Commit ca13d83a authored by Sander van Harmelen's avatar Sander van Harmelen

Merge pull request #48 from svanharmelen/b-fix-labels

Fix label marshalling
parents 38647abb b09c4d27
...@@ -76,13 +76,21 @@ func (i Issue) String() string { ...@@ -76,13 +76,21 @@ func (i Issue) String() string {
return Stringify(i) return Stringify(i)
} }
// Labels is a custom type with specific marshaling characteristics.
type Labels []string
// MarshalJSON implements the json.Marshaler interface.
func (l *Labels) MarshalJSON() ([]byte, error) {
return []byte(strings.Join(*l, ",")), nil
}
// ListIssuesOptions represents the available ListIssues() options. // ListIssuesOptions represents the available ListIssues() options.
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#list-issues // GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#list-issues
type ListIssuesOptions struct { type ListIssuesOptions struct {
ListOptions ListOptions
State string `url:"state,omitempty" json:"state,omitempty"` State string `url:"state,omitempty" json:"state,omitempty"`
Labels []string `url:"labels,omitempty" json:"labels,omitempty"` Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
OrderBy string `url:"order_by,omitempty" json:"order_by,omitempty"` OrderBy string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort string `url:"sort,omitempty" json:"sort,omitempty"` Sort string `url:"sort,omitempty" json:"sort,omitempty"`
} }
...@@ -113,7 +121,7 @@ type ListProjectIssuesOptions struct { ...@@ -113,7 +121,7 @@ type ListProjectIssuesOptions struct {
ListOptions ListOptions
IID int `url:"iid,omitempty" json:"iid,omitempty"` IID int `url:"iid,omitempty" json:"iid,omitempty"`
State string `url:"state,omitempty" json:"state,omitempty"` State string `url:"state,omitempty" json:"state,omitempty"`
Labels []string `url:"labels,omitempty" json:"labels,omitempty"` Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
Milestone string `url:"milestone,omitempty" json:"milestone,omitempty"` Milestone string `url:"milestone,omitempty" json:"milestone,omitempty"`
OrderBy string `url:"order_by,omitempty" json:"order_by,omitempty"` OrderBy string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort string `url:"sort,omitempty" json:"sort,omitempty"` Sort string `url:"sort,omitempty" json:"sort,omitempty"`
...@@ -178,7 +186,7 @@ type CreateIssueOptions struct { ...@@ -178,7 +186,7 @@ type CreateIssueOptions struct {
Description string `url:"description,omitempty" json:"description,omitempty"` Description string `url:"description,omitempty" json:"description,omitempty"`
AssigneeID int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` AssigneeID int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MilestoneID int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"` MilestoneID int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
Labels []string `url:"labels,omitempty" json:"labels,omitempty"` Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
} }
// CreateIssue creates a new project issue. // CreateIssue creates a new project issue.
...@@ -193,11 +201,6 @@ func (s *IssuesService) CreateIssue( ...@@ -193,11 +201,6 @@ func (s *IssuesService) CreateIssue(
} }
u := fmt.Sprintf("projects/%s/issues", url.QueryEscape(project)) u := fmt.Sprintf("projects/%s/issues", url.QueryEscape(project))
// This is needed to get a single, comma separated string
if len(opt.Labels) > 0 {
opt.Labels = []string{strings.Join(opt.Labels, ",")}
}
req, err := s.client.NewRequest("POST", u, opt) req, err := s.client.NewRequest("POST", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
...@@ -222,7 +225,7 @@ type UpdateIssueOptions struct { ...@@ -222,7 +225,7 @@ type UpdateIssueOptions struct {
Description string `url:"description,omitempty" json:"description,omitempty"` Description string `url:"description,omitempty" json:"description,omitempty"`
AssigneeID int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` AssigneeID int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MilestoneID int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"` MilestoneID int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
Labels []string `url:"labels,omitempty" json:"labels,omitempty"` Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
StateEvent string `url:"state_event,omitempty" json:"state_event,omitempty"` StateEvent string `url:"state_event,omitempty" json:"state_event,omitempty"`
} }
...@@ -240,9 +243,6 @@ func (s *IssuesService) UpdateIssue( ...@@ -240,9 +243,6 @@ func (s *IssuesService) UpdateIssue(
} }
u := fmt.Sprintf("projects/%s/issues/%d", url.QueryEscape(project), issue) u := fmt.Sprintf("projects/%s/issues/%d", url.QueryEscape(project), issue)
// This is needed to get a single, comma separated string
opt.Labels = []string{strings.Join(opt.Labels, ",")}
req, err := s.client.NewRequest("PUT", u, opt) req, err := s.client.NewRequest("PUT", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment