Skip to content

Commit

Permalink
Define specific behavior for each PR action including synchronize
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Orive <adrian.orive.oneca@gmail.com>
  • Loading branch information
Adirio committed Nov 13, 2020
1 parent f1629d0 commit 3b164d9
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
@@ -1,6 +1,6 @@
on:
pull_request_target:
types: [opened, edited, reopened]
types: [opened, edited, reopened, synchronize]

jobs:
verify:
Expand Down
26 changes: 6 additions & 20 deletions verify/cmd/runner.go
Expand Up @@ -18,8 +18,8 @@ package main

import (
"fmt"
"strings"
"regexp"
"strings"

"github.com/google/go-github/v32/github"

Expand All @@ -31,15 +31,17 @@ import (
type prErrs struct {
errs []string
}

func (e prErrs) Error() string {
return fmt.Sprintf("%d issues found with your PR description", len(e.errs))
}

func (e prErrs) Help() string {
res := make([]string, len(e.errs))
for _, err := range e.errs {
parts := strings.Split(err, "\n")
for i, part := range parts[1:] {
parts[i+1] = " "+part
parts[i+1] = " " + part
}
res = append(res, "- "+strings.Join(parts, "\n"))
}
Expand All @@ -49,23 +51,15 @@ func (e prErrs) Help() string {
func main() {
verify.ActionsEntrypoint(verify.RunPlugins(
verify.PRPlugin{
Name: "PR Type",
Name: "PR Type",
Title: "PR Type in Title",
ProcessPR: func(pr *github.PullRequest) (string, error) {
return notesver.VerifyPRTitle(pr.GetTitle())
},
ForAction: func(action string) bool {
switch action {
case "opened", "edited", "reopened":
return true
default:
return false
}
},
},

verify.PRPlugin{
Name: "PR Desc",
Name: "PR Desc",
Title: "Basic PR Descriptiveness Check",
ProcessPR: func(pr *github.PullRequest) (string, error) {
var errs []string
Expand All @@ -92,14 +86,6 @@ func main() {
}
return "", prErrs{errs: errs}
},
ForAction: func(action string) bool {
switch action {
case "opened", "edited", "reopened":
return true
default:
return false
}
},
},
))
}

0 comments on commit 3b164d9

Please sign in to comment.