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

Release locks when closing draft PRs #1038

Merged
merged 1 commit into from
May 19, 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
10 changes: 7 additions & 3 deletions server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,13 @@ func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (
}

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
// if the PR is in draft state we do not initiate actions proactively however,
// we must still clean up locks in the event of a user initiated plan
if pullEvent.GetAction() == "closed" {
pullEventType = models.ClosedPullEvent
} else {
pullEventType = models.OtherPullEvent
}
} else {
switch pullEvent.GetAction() {
case "opened":
Expand Down
77 changes: 43 additions & 34 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,74 +160,83 @@ 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
exp models.PullRequestEventType
action string
exp models.PullRequestEventType
draftExp models.PullRequestEventType
}{
{
action: "synchronize",
exp: models.UpdatedPullEvent,
action: "synchronize",
exp: models.UpdatedPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "unassigned",
exp: models.OtherPullEvent,
action: "unassigned",
exp: models.OtherPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "review_requested",
exp: models.OtherPullEvent,
action: "review_requested",
exp: models.OtherPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "review_request_removed",
exp: models.OtherPullEvent,
action: "review_request_removed",
exp: models.OtherPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "labeled",
exp: models.OtherPullEvent,
action: "labeled",
exp: models.OtherPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "unlabeled",
exp: models.OtherPullEvent,
action: "unlabeled",
exp: models.OtherPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "opened",
exp: models.OpenedPullEvent,
action: "opened",
exp: models.OpenedPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "edited",
exp: models.OtherPullEvent,
action: "edited",
exp: models.OtherPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "closed",
exp: models.ClosedPullEvent,
action: "closed",
exp: models.ClosedPullEvent,
draftExp: models.ClosedPullEvent,
},
{
action: "reopened",
exp: models.OtherPullEvent,
action: "reopened",
exp: models.OtherPullEvent,
draftExp: models.OtherPullEvent,
},
{
action: "ready_for_review",
exp: models.OpenedPullEvent,
action: "ready_for_review",
exp: models.OpenedPullEvent,
draftExp: models.OtherPullEvent,
},
}

for _, c := range cases {
t.Run(c.action, func(t *testing.T) {
// Test normal parsing
event := deepcopy.Copy(PullEvent).(github.PullRequestEvent)
event.Action = &c.action
_, actType, _, _, _, err := parser.ParseGithubPullEvent(&event)
Ok(t, err)
Equals(t, c.exp, actType)
// Test draft parsing
draftPR := true
event.PullRequest.Draft = &draftPR
_, draftEvType, _, _, _, err := parser.ParseGithubPullEvent(&event)
Ok(t, err)
Equals(t, c.draftExp, draftEvType)
})
}
}
Expand Down