Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #100 from tetsuharuohzeki/fix2
Browse files Browse the repository at this point in the history
Workaround to fail to parse json in pull request sync path
  • Loading branch information
tetsuharuohzeki authored Jul 8, 2020
2 parents 9356be5 + 386ef0e commit b09061e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
7 changes: 2 additions & 5 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os"

"encoding/json"

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

// PushEventData is workaround to use *github.PushEvent.
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 9 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit b09061e

Please sign in to comment.