forked from ldez/gha-mjolnir
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
44 lines (35 loc) · 987 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"log"
"github.com/google/go-github/v44/github"
"github.com/ldez/ghactions"
)
func main() {
displayVersion()
err := ghactions.NewAction(context.Background()).
OnPullRequest(func(client *github.Client, event *github.PullRequestEvent) error {
return action(client, event)
}).
OnPullRequestTarget(func(client *github.Client, event *github.PullRequestTargetEvent) error {
return action(client, event)
}).
Run()
if err != nil {
log.Fatal(err)
}
}
type pullRequestBasedEvent interface {
GetAction() string
GetPullRequest() *github.PullRequest
}
func action(client *github.Client, event pullRequestBasedEvent) error {
action := event.GetAction()
pr := event.GetPullRequest()
if action != "closed" || !pr.GetMerged() {
log.Printf("skip: %q merge %v", action, pr.GetMerged())
return nil
}
owner, repoName := ghactions.GetRepoInfo()
return closeRelatedIssues(context.Background(), client, owner, repoName, pr, false)
}