From 3c87bd7f86f2968bcb4ab18d822e82ea838555a0 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 12 Sep 2013 01:20:19 -0400 Subject: [PATCH] Switch ListByRepo() to addOptions(). --- github/issues.go | 39 ++++++++++++++------------------------- github/issues_test.go | 1 + 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/github/issues.go b/github/issues.go index 6fabf3e..2c8a148 100644 --- a/github/issues.go +++ b/github/issues.go @@ -128,36 +128,38 @@ type IssueListByRepoOptions struct { // Milestone limits issues for the specified milestone. Possible values are // a milestone number, "none" for issues with no milestone, "*" for issues // with any milestone. - Milestone string + Milestone string `url:"milestone,omitempty"` // State filters issues based on their state. Possible values are: open, // closed. Default is "open". - State string + State string `url:"state,omitempty"` // Assignee filters issues based on their assignee. Possible values are a // user name, "none" for issues that are not assigned, "*" for issues with // any assigned user. - Assignee string + Assignee string `url:"assignee,omitempty"` // Assignee filters issues based on their creator. - Creator string + Creator string `url:"creator,omitempty"` // Assignee filters issues to those mentioned a specific user. - Mentioned string + Mentioned string `url:"mentioned,omitempty"` // Labels filters issues based on their label. - Labels []string + Labels []string `url:"labels,omitempty,comma"` // Sort specifies how to sort issues. Possible values are: created, updated, // and comments. Default value is "assigned". - Sort string + Sort string `url:"sort,omitempty"` // Direction in which to sort issues. Possible values are: asc, desc. // Default is "asc". - Direction string + Direction string `url:"direction,omitempty"` // Since filters issues by time. - Since time.Time + Since time.Time `url:"since,omitempty"` + + ListOptions } // ListByRepo lists the issues for the specified repository. @@ -165,23 +167,10 @@ type IssueListByRepoOptions struct { // GitHub API docs: http://developer.github.com/v3/issues/#list-issues-for-a-repository func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRepoOptions) ([]Issue, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues", owner, repo) - if opt != nil { - params := url.Values{ - "milestone": {opt.Milestone}, - "state": {opt.State}, - "assignee": {opt.Assignee}, - "creator": {opt.Creator}, - "mentioned": {opt.Mentioned}, - "labels": {strings.Join(opt.Labels, ",")}, - "sort": {opt.Sort}, - "direction": {opt.Direction}, - } - if !opt.Since.IsZero() { - params.Add("since", opt.Since.Format(time.RFC3339)) - } - u += "?" + params.Encode() + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err } - req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/issues_test.go b/github/issues_test.go index 99d674b..08061ed 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -117,6 +117,7 @@ func TestIssuesService_ListByRepo(t *testing.T) { opt := &IssueListByRepoOptions{ "*", "closed", "a", "c", "m", []string{"a", "b"}, "updated", "asc", time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), + ListOptions{0, 0}, } issues, _, err := client.Issues.ListByRepo("o", "r", opt) if err != nil {