From b416fdaac841e7c2404b365cf6aa7b9f1d450d93 Mon Sep 17 00:00:00 2001 From: Yann Malet Date: Sun, 4 Aug 2013 20:36:18 +0200 Subject: [PATCH] Adding Label struct that is in Issue --- github/issues.go | 3 ++- github/issues_labels.go | 21 +++++++++++++++++++++ github/issues_test.go | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 github/issues_labels.go diff --git a/github/issues.go b/github/issues.go index e4bb9cf..b61ab15 100644 --- a/github/issues.go +++ b/github/issues.go @@ -28,13 +28,14 @@ type Issue struct { Title string `json:"title,omitempty"` Body string `json:"body,omitempty"` User *User `json:"user,omitempty"` + Labels []Label `json:"labels,omitempty"` Assignee *User `json:"assignee,omitempty"` Comments int `json:"comments,omitempty"` ClosedAt *time.Time `json:"closed_at,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` - // TODO(willnorris): labels and milestone + // TODO(willnorris): milestone } // IssueListOptions specifies the optional parameters to the IssuesService.List diff --git a/github/issues_labels.go b/github/issues_labels.go new file mode 100644 index 0000000..5fc7871 --- /dev/null +++ b/github/issues_labels.go @@ -0,0 +1,21 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import + +// Label represents a GitHib label on an Issue +"fmt" + +type Label struct { + URL string `json:"url,omitempty"` + Name string `json:"name,omitempty"` + Color string `json:"color,omitempty"` +} + +func (label Label) String() string { + return fmt.Sprint(label.Name) +} diff --git a/github/issues_test.go b/github/issues_test.go index a9dff22..e4490d6 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -69,6 +69,26 @@ func TestIssuesService_List_owned(t *testing.T) { } } +func TestIssueService_List_label(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/user/issues", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"number":1, "labels": [{"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug", "name": "bug", "color": "f29513"}]}]`) + }) + + issues, _, err := client.Issues.List(false, nil) + if err != nil { + t.Errorf("Issues.List returned error: %v", err) + } + + want := []Issue{Issue{Number: 1, Labels: []Label{Label{URL: "https://api.github.com/repos/octocat/Hello-World/labels/bug", Name: "bug", Color: "f29513"}}}} + if !reflect.DeepEqual(issues, want) { + t.Errorf("Issues.List returned %+v, want %+v", issues, want) + } +} + func TestIssuesService_ListByOrg(t *testing.T) { setup() defer teardown()