Skip to content

Commit

Permalink
Ignore Github draft PRs (#977)
Browse files Browse the repository at this point in the history
* Ignore Github draft PRs
  • Loading branch information
cket authored Apr 21, 2020
1 parent 8c68621 commit 9ce981f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
27 changes: 19 additions & 8 deletions server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,26 @@ func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (
err = errors.New("sender.login is null")
return
}
switch pullEvent.GetAction() {
case "opened":
pullEventType = models.OpenedPullEvent
case "synchronize":
pullEventType = models.UpdatedPullEvent
case "closed":
pullEventType = models.ClosedPullEvent
default:

if pullEvent.GetPullRequest().GetDraft() {
// if the PR is in draft state we don't care about the action type
// we can set the type to Other and ignore the PR
pullEventType = models.OtherPullEvent
} else {
switch pullEvent.GetAction() {
case "opened":
pullEventType = models.OpenedPullEvent
case "ready_for_review":
// when an author takes a PR out of 'draft' state a 'ready_for_review'
// event is triggered. We want atlantis to treat this as a freshly opened PR
pullEventType = models.OpenedPullEvent
case "synchronize":
pullEventType = models.UpdatedPullEvent
case "closed":
pullEventType = models.ClosedPullEvent
default:
pullEventType = models.OtherPullEvent
}
}
user = models.User{Username: senderUsername}
return
Expand Down
14 changes: 14 additions & 0 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ func TestParseGithubPullEvent(t *testing.T) {
Equals(t, models.User{Username: "user"}, actUser)
}

func TestParseGithubPullEventFromDraft(t *testing.T) {
// verify that draft PRs are treated as 'other' events
testEvent := deepcopy.Copy(PullEvent).(github.PullRequestEvent)
draftPR := true
testEvent.PullRequest.Draft = &draftPR
_, evType, _, _, _, err := parser.ParseGithubPullEvent(&testEvent)
Ok(t, err)
Equals(t, models.OtherPullEvent, evType)
}

func TestParseGithubPullEvent_EventType(t *testing.T) {
cases := []struct {
action string
Expand Down Expand Up @@ -205,6 +215,10 @@ func TestParseGithubPullEvent_EventType(t *testing.T) {
action: "reopened",
exp: models.OtherPullEvent,
},
{
action: "ready_for_review",
exp: models.OpenedPullEvent,
},
}

for _, c := range cases {
Expand Down

0 comments on commit 9ce981f

Please sign in to comment.