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

Ignore Github draft PRs #977

Merged
merged 3 commits into from
Apr 21, 2020
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
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