Skip to content

Commit

Permalink
fix: check runs (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eun authored Jul 18, 2023
1 parent 9f691ae commit 74cacf0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 6 additions & 1 deletion pkg/merge-with-label/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func GetPullRequestDetails(
Nodes []struct {
Conclusion string `json:"conclusion"`
Name string `json:"name"`
Status string `json:"status"`
} `json:"nodes"`
} `json:"checkRuns" graphql:"checkRuns(last:100)"`
Conclusion string `json:"conclusion"`
Expand Down Expand Up @@ -566,7 +567,11 @@ func GetPullRequestDetails(
for _, node := range commit.CheckSuites.Nodes {
details.CheckStates[node.App.Name] = node.Conclusion
for _, run := range node.CheckRuns.Nodes {
details.CheckStates[node.App.Name+"/"+run.Name] = run.Conclusion
if run.Status == "COMPLETED" {
details.CheckStates[node.App.Name+"/"+run.Name] = run.Conclusion
} else {
details.CheckStates[node.App.Name+"/"+run.Name] = "PENDING"
}
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/merge-with-label/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if r.Method != http.MethodPost {
http.Redirect(w, r, "https://github.com/apps/merge-with-label", http.StatusTemporaryRedirect)
http.Redirect(w, r, "https://github.com/Eun/merge-with-label", http.StatusTemporaryRedirect)
return
}

Expand Down Expand Up @@ -83,9 +83,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (h *Handler) handleCheckRun(logger *zerolog.Logger, eventID string, body []byte, w http.ResponseWriter) {
var req struct {
BaseRequest
PullRequests []struct {
Number int64 `json:"number"`
} `json:"pull_requests"`
CheckRun struct {
PullRequests []struct {
Number int64 `json:"number"`
} `json:"pull_requests"`
} `json:"check_run"`
}
if err := json.Unmarshal(body, &req); err != nil {
logger.Error().Err(err).Msg("unable to decode request")
Expand All @@ -110,8 +112,8 @@ func (h *Handler) handleCheckRun(logger *zerolog.Logger, eventID string, body []
return
}

for i := range req.PullRequests {
if req.PullRequests[i].Number == 0 {
for i := range req.CheckRun.PullRequests {
if req.CheckRun.PullRequests[i].Number == 0 {
logger.Debug().Msgf("no pull_requests.%d.number present in request", i)
continue
}
Expand All @@ -127,7 +129,7 @@ func (h *Handler) handleCheckRun(logger *zerolog.Logger, eventID string, body []
OwnerName: req.Repository.Owner.Login,
},
&common.PullRequest{
Number: req.PullRequests[i].Number,
Number: req.CheckRun.PullRequests[i].Number,
})
if err != nil {
logger.Error().Err(err).Msg("unable to queue message")
Expand Down
7 changes: 5 additions & 2 deletions pkg/merge-with-label/worker/should_skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func (worker *Worker) buildAvailableChecksList(details *github.PullRequestDetail
if slices.Index(statesThatAreSuccess, state) == -1 {
passed = "❌"
}
if state == "" {
state = "\u200e" // empty char, do not delete
}
checks = append(checks, check{
name: name,
state: state,
Expand All @@ -182,8 +185,8 @@ func (worker *Worker) buildAvailableChecksList(details *github.PullRequestDetail

var sb strings.Builder
sb.WriteString("## Available Checks\n")
sb.WriteString("| Name | State | Passed? |\n")
sb.WriteString("| ---- | ----- | ------- |\n")
sb.WriteString("| Name | State | Good Enough For Merge? |\n")
sb.WriteString("| ---- | ----- | ---------------------- |\n")

for _, item := range checks {
fmt.Fprintf(&sb, "| `%s` | `%s` | %s |\n", item.name, item.state, item.passed)
Expand Down

0 comments on commit 74cacf0

Please sign in to comment.