From c85e2ad34298cdf581f8276e32b5fffea7fda98b Mon Sep 17 00:00:00 2001 From: aman Date: Sun, 10 Jan 2021 21:31:07 +0530 Subject: [PATCH 1/4] [CI-0]: updated issue --- scm/driver/github/issue.go | 19 ++- scm/driver/github/issue_test.go | 5 + scm/driver/github/testdata/issue.json.golden | 6 +- scm/driver/github/testdata/issues.json.golden | 6 +- .../testdata/webhooks/comment.json.golden | 147 +++++++++++------- scm/issue.go | 21 +-- 6 files changed, 129 insertions(+), 75 deletions(-) diff --git a/scm/driver/github/issue.go b/scm/driver/github/issue.go index b360d4a3b..15e7c5ed2 100644 --- a/scm/driver/github/issue.go +++ b/scm/driver/github/issue.go @@ -91,13 +91,14 @@ func (s *issueService) Unlock(ctx context.Context, repo string, number int) (*sc } type issue struct { - ID int `json:"id"` - HTMLURL string `json:"html_url"` - Number int `json:"number"` - State string `json:"state"` - Title string `json:"title"` - Body string `json:"body"` - User struct { + ID int `json:"id"` + HTMLURL string `json:"html_url"` + Number int `json:"number"` + State string `json:"state"` + Title string `json:"title"` + Body string `json:"body"` + PullRequest pr `json:"pull_request"` + User struct { Login string `json:"login"` AvatarURL string `json:"avatar_url"` } `json:"user"` @@ -150,6 +151,10 @@ func convertIssue(from *issue) *scm.Issue { Body: from.Body, Link: from.HTMLURL, Labels: convertLabels(from), + PullRequest: scm.PullRequest{ + Diff: from.PullRequest.DiffURL, + Link: from.PullRequest.HTMLURL, + }, Locked: from.Locked, Closed: from.State == "closed", Author: scm.User{ diff --git a/scm/driver/github/issue_test.go b/scm/driver/github/issue_test.go index d6ff16f2e..6f5465226 100644 --- a/scm/driver/github/issue_test.go +++ b/scm/driver/github/issue_test.go @@ -8,6 +8,7 @@ import ( "context" "encoding/json" "io/ioutil" + "os" "testing" "github.com/drone/go-scm/scm" @@ -104,6 +105,10 @@ func TestIssueList(t *testing.T) { if diff := cmp.Diff(got, want); diff != "" { t.Errorf("Unexpected Results") t.Log(diff) + + // debug only. remove once implemented + json.NewEncoder(os.Stdout).Encode(want) + json.NewEncoder(os.Stdout).Encode(got) } t.Run("Request", testRequest(res)) diff --git a/scm/driver/github/testdata/issue.json.golden b/scm/driver/github/testdata/issue.json.golden index 5d681b5d0..feabe4cf7 100644 --- a/scm/driver/github/testdata/issue.json.golden +++ b/scm/driver/github/testdata/issue.json.golden @@ -15,5 +15,9 @@ "Avatar": "https://github.com/images/error/octocat_happy.gif" }, "Created": "2011-04-22T13:33:48Z", - "Updated": "2011-04-22T13:33:48Z" + "Updated": "2011-04-22T13:33:48Z", + "PullRequest": { + "Link": "https://github.com/octocat/Hello-World/pull/1347", + "Diff": "https://github.com/octocat/Hello-World/pull/1347.diff" + } } \ No newline at end of file diff --git a/scm/driver/github/testdata/issues.json.golden b/scm/driver/github/testdata/issues.json.golden index 3c6b280a4..0d9d9e42f 100644 --- a/scm/driver/github/testdata/issues.json.golden +++ b/scm/driver/github/testdata/issues.json.golden @@ -16,6 +16,10 @@ "Avatar": "https://github.com/images/error/octocat_happy.gif" }, "Created": "2011-04-22T13:33:48Z", - "Updated": "2011-04-22T13:33:48Z" + "Updated": "2011-04-22T13:33:48Z", + "PullRequest": { + "Link": "https://github.com/octocat/Hello-World/pull/1347", + "Diff": "https://github.com/octocat/Hello-World/pull/1347.diff" + } } ] \ No newline at end of file diff --git a/scm/driver/github/testdata/webhooks/comment.json.golden b/scm/driver/github/testdata/webhooks/comment.json.golden index b5e56cef0..3a91fa1be 100644 --- a/scm/driver/github/testdata/webhooks/comment.json.golden +++ b/scm/driver/github/testdata/webhooks/comment.json.golden @@ -1,58 +1,93 @@ { - "Action": "created", - "Repo": { - "ID": "309651765", - "Namespace": "abc", - "Name": "def-ci-webhook-test", - "Perm": null, - "Branch": "master", - "Private": true, - "Visibility": 0, - "Clone": "https://github.com/abc/def-ci-webhook-test.git", - "CloneSSH": "git@github.com:abc/def-ci-webhook-test.git", - "Link": "https://github.com/abc/def-ci-webhook-test", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Issue": { - "Number": 2, - "Title": "Update README.md", - "Body": "", - "Link": "https://github.com/abc/def-ci-webhook-test/pull/2", - "Labels": null, - "Closed": false, - "Locked": false, - "Author": { - "Login": "lts-def", - "Name": "", - "Email": "", - "Avatar": "https://avatars0.githubusercontent.com/u/10278482?v=4", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Created": "2020-11-03T22:32:14Z", - "Updated": "2020-12-29T05:49:14Z" - }, - "Comment": { - "ID": 751955664, - "Body": "trigger abc", - "Author": { - "Login": "lts-def", - "Name": "", - "Email": "", - "Avatar": "https://avatars0.githubusercontent.com/u/10278482?v=4", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Created": "2020-12-29T05:49:14Z", - "Updated": "2020-12-29T05:49:14Z" - }, - "Sender": { - "Login": "lts-def", - "Name": "", - "Email": "", - "Avatar": "https://avatars0.githubusercontent.com/u/10278482?v=4", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - } + "Action":"created", + "Repo":{ + "ID":"309651765", + "Namespace":"abc", + "Name":"def-ci-webhook-test", + "Perm":null, + "Branch":"master", + "Private":true, + "Visibility":0, + "Clone":"https://github.com/abc/def-ci-webhook-test.git", + "CloneSSH":"git@github.com:abc/def-ci-webhook-test.git", + "Link":"https://github.com/abc/def-ci-webhook-test", + "Created":"0001-01-01T00:00:00Z", + "Updated":"0001-01-01T00:00:00Z" + }, + "Issue":{ + "Number":2, + "Title":"Update README.md", + "Body":"", + "Link":"https://github.com/abc/def-ci-webhook-test/pull/2", + "Labels":null, + "Closed":false, + "Locked":false, + "Author":{ + "Login":"lts-def", + "Name":"", + "Email":"", + "Avatar":"https://avatars0.githubusercontent.com/u/10278482?v=4", + "Created":"0001-01-01T00:00:00Z", + "Updated":"0001-01-01T00:00:00Z" + }, + "PullRequest":{ + "Number":0, + "Title":"", + "Body":"", + "Sha":"", + "Ref":"", + "Source":"", + "Target":"", + "Fork":"", + "Link":"https://github.com/abc/def-ci-webhook-test/pull/2", + "Diff":"https://github.com/abc/def-ci-webhook-test/pull/2.diff", + "Closed":false, + "Merged":false, + "Base":{ + "Name":"", + "Path":"", + "Sha":"" + }, + "Head":{ + "Name":"", + "Path":"", + "Sha":"" + }, + "Author":{ + "Login":"", + "Name":"", + "Email":"", + "Avatar":"", + "Created":"0001-01-01T00:00:00Z", + "Updated":"0001-01-01T00:00:00Z" + }, + "Created":"0001-01-01T00:00:00Z", + "Updated":"0001-01-01T00:00:00Z", + "Labels":null + }, + "Created":"2020-11-03T22:32:14Z", + "Updated":"2020-12-29T05:49:14Z" + }, + "Comment":{ + "ID":751955664, + "Body":"trigger abc", + "Author":{ + "Login":"lts-def", + "Name":"", + "Email":"", + "Avatar":"https://avatars0.githubusercontent.com/u/10278482?v=4", + "Created":"0001-01-01T00:00:00Z", + "Updated":"0001-01-01T00:00:00Z" + }, + "Created":"2020-12-29T05:49:14Z", + "Updated":"2020-12-29T05:49:14Z" + }, + "Sender":{ + "Login":"lts-def", + "Name":"", + "Email":"", + "Avatar":"https://avatars0.githubusercontent.com/u/10278482?v=4", + "Created":"0001-01-01T00:00:00Z", + "Updated":"0001-01-01T00:00:00Z" + } } \ No newline at end of file diff --git a/scm/issue.go b/scm/issue.go index cd734b004..61373fb48 100644 --- a/scm/issue.go +++ b/scm/issue.go @@ -12,16 +12,17 @@ import ( type ( // Issue represents an issue. Issue struct { - Number int - Title string - Body string - Link string - Labels []string - Closed bool - Locked bool - Author User - Created time.Time - Updated time.Time + Number int + Title string + Body string + Link string + Labels []string + Closed bool + Locked bool + Author User + PullRequest PullRequest + Created time.Time + Updated time.Time } // IssueInput provides the input fields required for From 5270deaaac15d8f7bbde009f2d1230afc3360d78 Mon Sep 17 00:00:00 2001 From: aman Date: Sun, 10 Jan 2021 21:55:40 +0530 Subject: [PATCH 2/4] [CI-0]: updated issue --- scm/driver/github/issue_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scm/driver/github/issue_test.go b/scm/driver/github/issue_test.go index 6f5465226..d6ff16f2e 100644 --- a/scm/driver/github/issue_test.go +++ b/scm/driver/github/issue_test.go @@ -8,7 +8,6 @@ import ( "context" "encoding/json" "io/ioutil" - "os" "testing" "github.com/drone/go-scm/scm" @@ -105,10 +104,6 @@ func TestIssueList(t *testing.T) { if diff := cmp.Diff(got, want); diff != "" { t.Errorf("Unexpected Results") t.Log(diff) - - // debug only. remove once implemented - json.NewEncoder(os.Stdout).Encode(want) - json.NewEncoder(os.Stdout).Encode(got) } t.Run("Request", testRequest(res)) From e4e65203516d25949fd61870e13d632867cc1803 Mon Sep 17 00:00:00 2001 From: aman Date: Sun, 10 Jan 2021 22:00:39 +0530 Subject: [PATCH 3/4] [CI-0]: updated issue --- .../testdata/webhooks/comment.json.golden | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/scm/driver/github/testdata/webhooks/comment.json.golden b/scm/driver/github/testdata/webhooks/comment.json.golden index 3a91fa1be..e8de7ccd3 100644 --- a/scm/driver/github/testdata/webhooks/comment.json.golden +++ b/scm/driver/github/testdata/webhooks/comment.json.golden @@ -31,39 +31,8 @@ "Updated":"0001-01-01T00:00:00Z" }, "PullRequest":{ - "Number":0, - "Title":"", - "Body":"", - "Sha":"", - "Ref":"", - "Source":"", - "Target":"", - "Fork":"", "Link":"https://github.com/abc/def-ci-webhook-test/pull/2", - "Diff":"https://github.com/abc/def-ci-webhook-test/pull/2.diff", - "Closed":false, - "Merged":false, - "Base":{ - "Name":"", - "Path":"", - "Sha":"" - }, - "Head":{ - "Name":"", - "Path":"", - "Sha":"" - }, - "Author":{ - "Login":"", - "Name":"", - "Email":"", - "Avatar":"", - "Created":"0001-01-01T00:00:00Z", - "Updated":"0001-01-01T00:00:00Z" - }, - "Created":"0001-01-01T00:00:00Z", - "Updated":"0001-01-01T00:00:00Z", - "Labels":null + "Diff":"https://github.com/abc/def-ci-webhook-test/pull/2.diff" }, "Created":"2020-11-03T22:32:14Z", "Updated":"2020-12-29T05:49:14Z" From 199eee1802898ef7462ad2280dc673ad828def20 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 11 Jan 2021 09:38:40 -0500 Subject: [PATCH 4/4] Update issue.json.golden --- scm/driver/github/testdata/issue.json.golden | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scm/driver/github/testdata/issue.json.golden b/scm/driver/github/testdata/issue.json.golden index feabe4cf7..438ea7f02 100644 --- a/scm/driver/github/testdata/issue.json.golden +++ b/scm/driver/github/testdata/issue.json.golden @@ -16,8 +16,8 @@ }, "Created": "2011-04-22T13:33:48Z", "Updated": "2011-04-22T13:33:48Z", - "PullRequest": { - "Link": "https://github.com/octocat/Hello-World/pull/1347", - "Diff": "https://github.com/octocat/Hello-World/pull/1347.diff" - } -} \ No newline at end of file + "PullRequest": { + "Link": "https://github.com/octocat/Hello-World/pull/1347", + "Diff": "https://github.com/octocat/Hello-World/pull/1347.diff" + } +}