diff --git a/server/events/event_parser.go b/server/events/event_parser.go index 6a64110ff0..8e6e5b240f 100644 --- a/server/events/event_parser.go +++ b/server/events/event_parser.go @@ -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 diff --git a/server/events/event_parser_test.go b/server/events/event_parser_test.go index 851f444cba..5c2817e7b9 100644 --- a/server/events/event_parser_test.go +++ b/server/events/event_parser_test.go @@ -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{