|
1 | 1 | package actions
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "context" |
4 | 5 | "fmt"
|
5 | 6 | "github.com/google/go-github/v28/github"
|
6 | 7 | "io/ioutil"
|
@@ -63,10 +64,41 @@ func CheckSuiteEvent() (*github.CheckSuiteEvent, error) {
|
63 | 64 | return evt.(*github.CheckSuiteEvent), nil
|
64 | 65 | }
|
65 | 66 |
|
| 67 | +func IssueEvent() (*github.IssueEvent, error) { |
| 68 | + evt, err := github.ParseWebHook("issue", Event()) |
| 69 | + if err != nil { |
| 70 | + return nil, err |
| 71 | + } |
| 72 | + return evt.(*github.IssueEvent), nil |
| 73 | +} |
| 74 | + |
66 | 75 | func PullRequest() (*github.PullRequest, string, string, error) {
|
67 | 76 | var pr *github.PullRequest
|
68 | 77 | var owner, repo string
|
69 | 78 | switch EventName() {
|
| 79 | + case "issue": |
| 80 | + issue, err := IssueEvent() |
| 81 | + if err != nil { |
| 82 | + return nil, "", "", err |
| 83 | + } |
| 84 | + |
| 85 | + client, err := CreateInstallationTokenClient(os.Getenv("GITHUB_TOKEN"), "", "") |
| 86 | + if err != nil { |
| 87 | + return nil, "", "", err |
| 88 | + } |
| 89 | + |
| 90 | + if issue.Issue.GetPullRequestLinks().GetURL() == "" { |
| 91 | + return nil, "", "", fmt.Errorf("issue %d is not a pull request", issue.Issue.GetNumber()) |
| 92 | + } |
| 93 | + |
| 94 | + // This can be a pull_request milestoned/demilestoned events emitted as issue event |
| 95 | + owner := issue.Issue.Repository.Owner.GetLogin() |
| 96 | + repo := issue.Issue.Repository.GetName() |
| 97 | + pull, _, err := client.PullRequests.Get(context.Background(), owner, repo, issue.Issue.GetNumber()) |
| 98 | + if err != nil { |
| 99 | + return nil, "", "", err |
| 100 | + } |
| 101 | + pr = pull |
70 | 102 | case "pull_request":
|
71 | 103 | pull, err := PullRequestEvent()
|
72 | 104 | if err != nil {
|
|
0 commit comments