Skip to content

Commit

Permalink
Add draft boolean for github and gitlab PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
karansaraswat19 committed Aug 2, 2024
1 parent 4c976e1 commit 845b0c5
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions scm/driver/github/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type pr struct {
State string `json:"state"`
Title string `json:"title"`
Body string `json:"body"`
Draft bool `json:"draft"`
DiffURL string `json:"diff_url"`
HTMLURL string `json:"html_url"`
User struct {
Expand Down Expand Up @@ -154,6 +155,7 @@ func convertPullRequest(from *pr) *scm.PullRequest {
Fork: from.Head.Repo.FullName,
Link: from.HTMLURL,
Diff: from.DiffURL,
Draft: from.Draft,
Closed: from.State != "open",
Merged: from.MergedAt.String != "",
Head: scm.Reference{
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"comments_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/comments",
"statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"number": 1347,
"draft": false,
"state": "open",
"title": "new-feature",
"body": "Please pull these awesome changes",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/pr.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"Fork": "octocat/Hello-World",
"Link": "https://github.com/octocat/Hello-World/pull/1347",
"Diff": "https://github.com/octocat/Hello-World/pull/1347.diff",
"Draft": false,
"Closed": false,
"Merged": true,
"Base": {
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/pulls.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"comments_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/comments",
"statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"number": 1347,
"draft": false,
"state": "open",
"title": "new-feature",
"body": "Please pull these awesome changes",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/pulls.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Fork": "octocat/Hello-World",
"Link": "https://github.com/octocat/Hello-World/pull/1347",
"Diff": "https://github.com/octocat/Hello-World/pull/1347.diff",
"Draft": false,
"Closed": false,
"Merged": true,
"Base": {
Expand Down
16 changes: 9 additions & 7 deletions scm/driver/gitlab/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ func (s *pullService) Close(ctx context.Context, repo string, number int) (*scm.
}

type pr struct {
Number int `json:"iid"`
Sha string `json:"sha"`
Title string `json:"title"`
Desc string `json:"description"`
State string `json:"state"`
Link string `json:"web_url"`
Author struct {
Number int `json:"iid"`
Sha string `json:"sha"`
Title string `json:"title"`
Desc string `json:"description"`
State string `json:"state"`
WorkInProgress bool `json:"work_in_progress"`
Link string `json:"web_url"`
Author struct {
Username string `json:"username"`
Email string `json:"email"`
Name string `json:"name"`
Expand Down Expand Up @@ -160,6 +161,7 @@ func convertPullRequest(from *pr) *scm.PullRequest {
Source: from.SourceBranch,
Target: from.TargetBranch,
Link: from.Link,
Draft: from.WorkInProgress,
Closed: from.State != "opened",
Merged: from.State == "merged",
Author: scm.User{
Expand Down
1 change: 1 addition & 0 deletions scm/driver/gitlab/testdata/merge.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Source": "fix",
"Target": "master",
"Link": "https://gitlab.com/gitlab-org/testme/merge_requests/1",
"Draft": false,
"Closed": true,
"Merged": false,
"Author": {
Expand Down
1 change: 1 addition & 0 deletions scm/driver/gitlab/testdata/merges.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Source": "fix",
"Target": "master",
"Link": "https://gitlab.com/gitlab-org/testme/merge_requests/1",
"Draft": false,
"Closed": true,
"Merged": false,
"Author": {
Expand Down
2 changes: 2 additions & 0 deletions scm/driver/gitlab/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func convertCommentHook(src *commentHook) (*scm.IssueCommentHook, error) {
Source: src.MergeRequest.SourceBranch,
Target: src.MergeRequest.TargetBranch,
Link: src.MergeRequest.URL,
Draft: src.MergeRequest.WorkInProgress,
Closed: src.MergeRequest.State != "opened",
Merged: src.MergeRequest.State == "merged",
Author: *convertUser(&src.User),
Expand Down Expand Up @@ -359,6 +360,7 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
Target: src.ObjectAttributes.TargetBranch,
Fork: fork,
Link: src.ObjectAttributes.URL,
Draft: src.ObjectAttributes.WorkInProgress,
Closed: src.ObjectAttributes.State != "opened",
Merged: src.ObjectAttributes.State == "merged",
// Created : src.ObjectAttributes.CreatedAt,
Expand Down
1 change: 1 addition & 0 deletions scm/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (
Fork string
Link string
Diff string
Draft bool
Closed bool
Merged bool
Merge string
Expand Down

0 comments on commit 845b0c5

Please sign in to comment.