From 386ef0ee907f60646790771b00e60ed25984424d Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Wed, 8 Jul 2020 11:29:30 +0900 Subject: [PATCH] Workaround to fail to parse json in pull request sync path --- json.go | 7 ++----- main.go | 14 +++++++++----- operation.go | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/json.go b/json.go index bf4921b..391b11b 100644 --- a/json.go +++ b/json.go @@ -6,8 +6,6 @@ import ( "os" "encoding/json" - - "github.com/google/go-github/v32/github" ) // PushEventData is workaround to use *github.PushEvent. @@ -55,9 +53,8 @@ func loadJSONFileForPushEventData(path string) *PushEventData { // If we available, we should use *github.PushEvent. // But we cannot use it by parsing error. See https://github.com/cats-oss/github-action-detect-unmergeable/issues/71 type PullRequestEventData struct { - Action *string `json:"action,omitempty"` - Number *int `json:"number,omitempty"` - PullRequest *github.PullRequest `json:"pull_request,omitempty"` + Action *string `json:"action,omitempty"` + Number *int `json:"number,omitempty"` } func (p *PullRequestEventData) GetAction() string { diff --git a/main.go b/main.go index 3f07c21..ee585cf 100644 --- a/main.go +++ b/main.go @@ -151,15 +151,19 @@ func onPullRequestEvent(githubClient *github.Client, githubEventPath string, rep return } - pr := eventData.PullRequest - prNumber := pr.GetNumber() + prNumber := eventData.GetNumber() if prNumber == 0 { - log.Fatalln("we cannot get the PR number for this pull request") + log.Println("we cannot get the PR number for this pull request") return } - if _, isUnmergeable := checkWhetherThisPullRequestNeedRebase(pr, needRebaseLabel); isUnmergeable { - log.Printf("#%v is not mergeable", prNumber) + _, isUnmergeable, err := shouldMarkPullRequestNeedRebase(githubClient, repoOwner, repoName, prNumber, needRebaseLabel) + if err != nil { + return + } + + if isUnmergeable { + log.Printf("#%v is not mergeable. We don't do anything", prNumber) return } diff --git a/operation.go b/operation.go index ea9b5cf..dfcac48 100644 --- a/operation.go +++ b/operation.go @@ -158,6 +158,7 @@ func shouldMarkPullRequestNeedRebase(client *github.Client, owner, repo string, ctx := context.Background() newPRInfoResponse, _, err := client.PullRequests.Get(ctx, owner, repo, number) if err != nil { + log.Printf("Getting info about #%v was failed.", number) return }