Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion scm/driver/github/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type pr struct {
AvatarURL string `json:"avatar_url"`
}
} `json:"base"`
Merged bool `json:"merged"`
MergedAt null.String `json:"merged_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Expand Down Expand Up @@ -154,7 +155,7 @@ func convertPullRequest(from *pr) *scm.PullRequest {
Link: from.HTMLURL,
Diff: from.DiffURL,
Closed: from.State != "open",
Merged: from.MergedAt.String != "",
Merged: from.Merged,
Head: scm.Reference{
Name: from.Head.Ref,
Path: scm.ExpandRef(from.Head.Ref, "refs/heads"),
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/github/testdata/pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
"site_admin": false
},
"merge_commit_sha": "e5bd3914e2e596debea16f433f57875b5b90bcd6",
"merged": false,
"merged": true,
Copy link
Contributor

@bradrydzewski bradrydzewski Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the json payload in pr.json is for an open pull request; therefore it should not be set to merged: true. I would instead suggest adding a new, real world json file and creating a new test case. I think you will find our existing merged_at logic works as expected if you provide it with a real world payload for a merged action.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on my own repo, the merged and merge_at are always marked or filled in the case of merged-pr. And both not marked or filled in the case of closed-pr and opening-pr.

Copy link
Contributor

@bradrydzewski bradrydzewski Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may be a misunderstanding. The pr.json file is for an open pull request (the state field is set to open) which means it cannot have merged set to true. If you want to create a test case for a merged pull request, you should add a new file, for example pr_merged.json; this should be a real json payload captured from github, not something modified by hand.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, it the pr.json is for a opening-pr, then its merge_at must be null. If it is not merged (opening), how can it have a merge time... So I think something in the pr.json must be wrong.

But having another test json (maybe pr_merged.json) make sense.

"mergeable": true,
"merged_by": {
"login": "octocat",
Expand All @@ -398,4 +398,4 @@
"deletions": 3,
"changed_files": 5,
"maintainer_can_modify": true
}
}
5 changes: 3 additions & 2 deletions scm/driver/github/testdata/pulls.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
}
},
"merged": true
}
]
]
12 changes: 5 additions & 7 deletions scm/driver/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error)
case "edited":
dst.Action = scm.ActionUpdate
case "closed":
// TODO(bradrydzewski) github does not provide a merged action,
// but this is provided by gitlab and bitbucket. Is it possible
// to emulate the merge action?

// if merged == true
// dst.Action = scm.ActionMerge
dst.Action = scm.ActionClose
if dst.PullRequest.Merged {
dst.Action = scm.ActionMerge
} else {
dst.Action = scm.ActionClose
}
case "reopened":
dst.Action = scm.ActionReopen
case "synchronize":
Expand Down