Skip to content

Commit

Permalink
feat: add an option to skip builds for draft PR
Browse files Browse the repository at this point in the history
Signed-off-by: ankitm123 <[email protected]>
  • Loading branch information
ankitm123 committed Sep 24, 2022
1 parent c12ac7d commit a1ce98b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/plugins/trigger/generic-comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func handleGenericComment(c Client, trigger *plugins.Trigger, gc scmprovider.Gen
return err
}

if pr.Draft {
c.Logger.Infof("skipping build because PR is in draft mode")
return nil
}

// Skip untrusted users comments.
trusted, err := TrustedUser(c.SCMProviderClient, trigger, commentAuthor, org, repo)
if err != nil {
Expand All @@ -63,7 +68,7 @@ func handleGenericComment(c Client, trigger *plugins.Trigger, gc scmprovider.Gen
return err
}
if !trusted {
resp := fmt.Sprintf("Cannot trigger testing until a trusted user reviews the PR and leaves an `/ok-to-test` message.")
resp := "Cannot trigger testing until a trusted user reviews the PR and leaves an `/ok-to-test` message."
c.Logger.Infof("Commenting \"%s\".", resp)
return c.SCMProviderClient.CreateComment(org, repo, number, true, plugins.FormatResponseRaw(gc.Body, gc.Link, c.SCMProviderClient.QuoteAuthorForComment(gc.Author.Login), resp))
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/plugins/trigger/pull-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func handlePR(c Client, trigger *plugins.Trigger, pr scm.PullRequestHook) error

org, repo, a := orgRepoAuthor(pr.PullRequest)
author := string(a)
if pr.PullRequest.Draft {
c.Logger.Infof("skipping build because PR is in draft mode")
return nil
}
num := pr.PullRequest.Number
switch pr.Action {
case scm.ActionOpen:
Expand Down

0 comments on commit a1ce98b

Please sign in to comment.