Skip to content

Commit

Permalink
Ignore Github draft PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
cket committed Apr 10, 2020
1 parent df357bd commit d41d0f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
23 changes: 15 additions & 8 deletions server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,22 @@ 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 "synchronize":
pullEventType = models.UpdatedPullEvent
case "closed":
pullEventType = models.ClosedPullEvent
default:
pullEventType = models.OtherPullEvent
}
}
user = models.User{Username: senderUsername}
return
Expand Down
8 changes: 8 additions & 0 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ func TestParseGithubPullEvent(t *testing.T) {
_, _, _, _, _, err = parser.ParseGithubPullEvent(&testEvent)
ErrEquals(t, "sender.login is null", err)

// 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)

actPull, evType, actBaseRepo, actHeadRepo, actUser, err := parser.ParseGithubPullEvent(&PullEvent)
Ok(t, err)
expBaseRepo := models.Repo{
Expand Down

0 comments on commit d41d0f4

Please sign in to comment.