Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [CODE-2180]: Add draft boolean for github, azure and gitlab PRs #318

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scm/driver/azure/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type pr struct {
SourceRefName string `json:"sourceRefName"`
TargetRefName string `json:"targetRefName"`
MergeStatus string `json:"mergeStatus"`
IsDraft bool `json:"isDraft"`
abhinav-harness marked this conversation as resolved.
Show resolved Hide resolved
MergeID string `json:"mergeId"`
LastMergeSourceCommit struct {
CommitID string `json:"commitId"`
Expand Down Expand Up @@ -168,6 +169,7 @@ func convertPullRequest(from *pr) *scm.PullRequest {
Source: scm.TrimRef(from.SourceRefName),
Target: scm.TrimRef(from.TargetRefName),
Link: from.URL,
Draft: from.IsDraft,
Closed: from.ClosedDate.Valid,
Merged: from.Status == "completed",
Ref: fmt.Sprintf("refs/pull/%d/merge", from.PullRequestID),
Expand Down
1 change: 1 addition & 0 deletions scm/driver/azure/testdata/pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"sourceRefName": "refs/heads/pr_branch",
"targetRefName": "refs/heads/main",
"mergeStatus": "queued",
"isDraft": false,
"mergeId": "36c88bf7-3d14-437f-82aa-e38cce733261",
"lastMergeSourceCommit": {
"commitId": "01768d964c03e97260af0bd8cd9e5cd1f9ac6356",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/azure/testdata/pr.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Fork": "",
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/pullRequests/19",
"Diff": "",
"Draft": false,
"Closed": true,
"Merged": true,
"Base": {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"Target": "main",
"Fork": "Meet Rathod/meet",
"Link": "https://gitlab.com/rathod.meetsatish/meet/-/merge_requests/3",
"Draft": true,
"Closed": false,
"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