Skip to content

Commit

Permalink
don't notify on draft PRs (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksnyder authored Sep 24, 2020
1 parent f784a0b commit 979df24
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/codenotify.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
on: [pull_request]
on:
pull_request:
types: [opened, synchronize, ready_for_review]

jobs:
codenotify:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down Expand Up @@ -112,6 +116,7 @@ type pullRequest struct {
User struct {
Login string `json:"login"`
} `json:"User"`
Draft bool `json:"draft"`
}

func githubActionOptions() (*options, error) {
Expand All @@ -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
Expand Down

0 comments on commit 979df24

Please sign in to comment.