From 979df24c97b0c4fa2f5a3127c487fc267626b92d Mon Sep 17 00:00:00 2001 From: Nick Snyder Date: Wed, 23 Sep 2020 22:50:12 -0700 Subject: [PATCH] don't notify on draft PRs (#6) --- .github/workflows/codenotify.yml | 4 +++- README.md | 4 +++- main.go | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codenotify.yml b/.github/workflows/codenotify.yml index bb1487d..87ad2ba 100644 --- a/.github/workflows/codenotify.yml +++ b/.github/workflows/codenotify.yml @@ -1,4 +1,6 @@ -on: [pull_request] +on: + pull_request: + types: [opened, synchronize, ready_for_review] jobs: codenotify: diff --git a/README.md b/README.md index a0b663d..fdf6249 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,9 @@ a1b2c3...HEAD Add `.github/workflows/codenotify.yml` to your repository. ```yaml -on: [pull_request] +on: + pull_request: + types: [opened, synchronize, ready_for_review] jobs: codenotify: diff --git a/main.go b/main.go index 25e2bc9..9c378aa 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,10 @@ func testableMain(stdout io.Writer, args []string) error { return err } + if opts == nil { + return nil + } + commits := opts.baseRef + "..." + opts.headRef diff, err := run("git", "-C", opts.cwd, "diff", "--name-only", commits) if err != nil { @@ -51,7 +55,7 @@ func testableMain(stdout io.Writer, args []string) error { } if opts.author != "" { - fmt.Fprintf(verbose, "Not notifying pull request author %s\n", opts.author) + fmt.Fprintf(verbose, "not notifying pull request author %s\n", opts.author) delete(notifs, opts.author) } @@ -112,6 +116,7 @@ type pullRequest struct { User struct { Login string `json:"login"` } `json:"User"` + Draft bool `json:"draft"` } func githubActionOptions() (*options, error) { @@ -133,6 +138,11 @@ func githubActionOptions() (*options, error) { return nil, fmt.Errorf("unable to decode GitHub event: %s\n%s", err, string(data)) } + if event.PullRequest.Draft { + fmt.Fprintln(verbose, "Not sending notifications for draft pull request.") + return nil, nil + } + commitCount, err := commitCount(event.PullRequest.NodeID) if err != nil { return nil, err