diff --git a/scm/driver/gitea/pr.go b/scm/driver/gitea/pr.go index 9f0b3d799..fc82b8ae3 100644 --- a/scm/driver/gitea/pr.go +++ b/scm/driver/gitea/pr.go @@ -95,6 +95,10 @@ type pr struct { Merged bool `json:"merged"` Created time.Time `json:"created_at"` Updated time.Time `json:"updated_at"` + Labels []struct { + Name string `json:"name"` + Color string `json:"color"` + } `json:"labels"` } type reference struct { @@ -123,6 +127,13 @@ func convertPullRequests(src []*pr) []*scm.PullRequest { } func convertPullRequest(src *pr) *scm.PullRequest { + var labels []scm.Label + for _, label := range src.Labels { + labels = append(labels, scm.Label{ + Name: label.Name, + Color: label.Color, + }) + } return &scm.PullRequest{ Number: src.Number, Title: src.Title, @@ -138,6 +149,7 @@ func convertPullRequest(src *pr) *scm.PullRequest { Merged: src.Merged, Created: src.Created, Updated: src.Updated, + Labels: labels, } } diff --git a/scm/driver/github/pr.go b/scm/driver/github/pr.go index f039c2802..2b75a55cf 100644 --- a/scm/driver/github/pr.go +++ b/scm/driver/github/pr.go @@ -96,6 +96,10 @@ type pr struct { MergedAt null.String `json:"merged_at"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` + Labels []struct { + Name string `json:"name"` + Color string `json:"color"` + } `json:"labels"` } type prInput struct { @@ -123,6 +127,13 @@ func convertPullRequestList(from []*pr) []*scm.PullRequest { } func convertPullRequest(from *pr) *scm.PullRequest { + var labels []scm.Label + for _, label := range from.Labels { + labels = append(labels, scm.Label{ + Name: label.Name, + Color: label.Color, + }) + } return &scm.PullRequest{ Number: from.Number, Title: from.Title, @@ -151,6 +162,7 @@ func convertPullRequest(from *pr) *scm.PullRequest { }, Created: from.CreatedAt, Updated: from.UpdatedAt, + Labels: labels, } } diff --git a/scm/driver/github/testdata/webhooks/pr_labeled.json b/scm/driver/github/testdata/webhooks/pr_labeled.json index fb329771c..f648e3d95 100644 --- a/scm/driver/github/testdata/webhooks/pr_labeled.json +++ b/scm/driver/github/testdata/webhooks/pr_labeled.json @@ -55,6 +55,14 @@ "node_id": "MDU6TGFiZWw2MzA2MzQ4MA==", "url": "https://api.github.com/repos/bradrydzewski/drone-test-go/labels/bug", "name": "bug", + "color": "fc2927", + "default": true + }, + { + "id": 63063480, + "node_id": "MDU6TGFiZWw2MzA2MzQ4MA==", + "url": "https://api.github.com/repos/bradrydzewski/drone-test-go/labels/bug", + "name": "documentation", "color": "fc2929", "default": true } diff --git a/scm/driver/github/testdata/webhooks/pr_labeled.json.golden b/scm/driver/github/testdata/webhooks/pr_labeled.json.golden index ea04458e9..2198803f3 100644 --- a/scm/driver/github/testdata/webhooks/pr_labeled.json.golden +++ b/scm/driver/github/testdata/webhooks/pr_labeled.json.golden @@ -42,7 +42,17 @@ "Avatar": "https://avatars1.githubusercontent.com/u/817538?v=4" }, "Created": "2018-06-22T23:54:09Z", - "Updated": "2018-06-25T19:05:03Z" + "Updated": "2018-06-25T19:05:03Z", + "labels": [ + { + "name": "bug", + "color": "fc2927" + }, + { + "name": "documentation", + "color": "fc2929" + } + ] }, "Sender": { "Login": "bradrydzewski", diff --git a/scm/driver/gitlab/pr.go b/scm/driver/gitlab/pr.go index 98d5dfa65..9a6ca0d6e 100644 --- a/scm/driver/gitlab/pr.go +++ b/scm/driver/gitlab/pr.go @@ -109,6 +109,7 @@ type pr struct { Created time.Time `json:"created_at"` Updated time.Time `json:"updated_at"` Closed time.Time + Labels []string `json:"labels"` } type changes struct { @@ -132,6 +133,12 @@ func convertPullRequestList(from []*pr) []*scm.PullRequest { } func convertPullRequest(from *pr) *scm.PullRequest { + var labels []scm.Label + for _, label := range from.Labels { + labels = append(labels, scm.Label{ + Name: label, + }) + } return &scm.PullRequest{ Number: from.Number, Title: from.Title, @@ -150,6 +157,7 @@ func convertPullRequest(from *pr) *scm.PullRequest { }, Created: from.Created, Updated: from.Updated, + Labels: labels, } } diff --git a/scm/driver/gitlab/testdata/merge.json b/scm/driver/gitlab/testdata/merge.json index 7b0fca342..cb1c6e790 100644 --- a/scm/driver/gitlab/testdata/merge.json +++ b/scm/driver/gitlab/testdata/merge.json @@ -22,7 +22,7 @@ "assignee": null, "source_project_id": 32732, "target_project_id": 32732, - "labels": [], + "labels": ["bug", "documentation"], "work_in_progress": false, "milestone": null, "merge_when_pipeline_succeeds": false, diff --git a/scm/driver/gitlab/testdata/merge.json.golden b/scm/driver/gitlab/testdata/merge.json.golden index f22028c6a..4df0d2492 100644 --- a/scm/driver/gitlab/testdata/merge.json.golden +++ b/scm/driver/gitlab/testdata/merge.json.golden @@ -16,5 +16,13 @@ "Avatar": "https://secure.gravatar.com/avatar/b5bf44866b4eeafa2d8114bfe15da02f?s=80\u0026d=identicon" }, "Created": "2015-12-18T18:29:53.563Z", - "Updated": "2015-12-18T18:30:22.522Z" + "Updated": "2015-12-18T18:30:22.522Z", + "Labels": [ + { + "name": "bug" + }, + { + "name": "documentation" + } + ] } \ No newline at end of file diff --git a/scm/driver/gitlab/testdata/merges.json b/scm/driver/gitlab/testdata/merges.json index fa9e21b61..ef42c4df8 100644 --- a/scm/driver/gitlab/testdata/merges.json +++ b/scm/driver/gitlab/testdata/merges.json @@ -23,7 +23,7 @@ "assignee": null, "source_project_id": 32732, "target_project_id": 32732, - "labels": [], + "labels": ["bug", "documentation"], "work_in_progress": false, "milestone": null, "merge_when_pipeline_succeeds": false, diff --git a/scm/driver/gitlab/testdata/merges.json.golden b/scm/driver/gitlab/testdata/merges.json.golden index e48880af5..46cb6d7c4 100644 --- a/scm/driver/gitlab/testdata/merges.json.golden +++ b/scm/driver/gitlab/testdata/merges.json.golden @@ -17,6 +17,14 @@ "Avatar": "https://secure.gravatar.com/avatar/b5bf44866b4eeafa2d8114bfe15da02f?s=80\u0026d=identicon" }, "Created": "2015-12-18T18:29:53.563Z", - "Updated": "2015-12-18T18:30:22.522Z" + "Updated": "2015-12-18T18:30:22.522Z", + "Labels": [ + { + "name": "bug" + }, + { + "name": "documentation" + } + ] } ] \ No newline at end of file diff --git a/scm/pr.go b/scm/pr.go index 848de1eb2..ebf0b4363 100644 --- a/scm/pr.go +++ b/scm/pr.go @@ -28,6 +28,7 @@ type ( Author User Created time.Time Updated time.Time + Labels []Label } // PullRequestInput provides the input fields required for creating a pull request. @@ -55,6 +56,11 @@ type ( Deleted bool } + Label struct { + Name string + Color string + } + // PullRequestService provides access to pull request resources. PullRequestService interface { // Find returns the repository pull request by number.