Skip to content

Commit

Permalink
Merge pull request #13 from chrisgavin/handle-non-rerunnable-suites-b…
Browse files Browse the repository at this point in the history
…etter

Handle non-rerunnable and failed check suites slightly better.
  • Loading branch information
chrisgavin authored Jul 27, 2023
2 parents 3f5069c + 73fc139 commit c39c6db
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
59 changes: 30 additions & 29 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,39 @@ var rootCmd = &cobra.Command{
}

for _, checkSuite := range checkSuites.CheckSuites {
if checkSuite.Status != "completed" {
// A check suite is created for every installed GitHub App, but some don't run any checks so these remain permanently queued.
if checkSuite.LatestCheckRunsCount == 0 {
continue
}
if !checkSuite.IsCompleted() || !checkSuite.IsSuccessful() {
allSuitesGreen = false
}
}

for _, checkSuite := range checkSuites.CheckSuites {
if !checkSuite.RunsRerequestable && checkSuite.App.Slug != actions.ActionsAppSlug {
if checkSuite.IsCompleted() && !checkSuite.IsSuccessful() && !checkSuite.RunsRerequestable && checkSuite.App.Slug != actions.ActionsAppSlug {
fmt.Printf("Check suite is not rerunnable: %d\n", checkSuite.ID)
} else {
checkRuns, err := check_runs.GetCheckRuns(ghClient, repository, checkSuite.ID)
if err != nil {
return err
}
failedCheckRuns := check_runs.FilterFailedCheckRuns(checkRuns)
if len(failedCheckRuns) > 0 {
allSuitesGreen = false
}
for _, checkRun := range failedCheckRuns {
if checkSuite.App.Slug != actions.ActionsAppSlug {
err := check_runs.RerequestCheckRun(ghClient, repository, checkRun.ID)
if err != nil {
return err
}
} else {
actionsRunID, err := actions.ExtractActionsRunIDFromURL(checkRun.HTMLURL)
if err != nil {
return err
}
err = actions.RerunActionsWorkflow(ghClient, repository, actionsRunID)
if err != nil {
return err
}
continue
}
checkRuns, err := check_runs.GetCheckRuns(ghClient, repository, checkSuite.ID)
if err != nil {
return err
}
failedCheckRuns := check_runs.FilterFailedCheckRuns(checkRuns)
if len(failedCheckRuns) > 0 {
allSuitesGreen = false
}
for _, checkRun := range failedCheckRuns {
if checkSuite.App.Slug != actions.ActionsAppSlug {
err := check_runs.RerequestCheckRun(ghClient, repository, checkRun.ID)
if err != nil {
return err
}
} else {
actionsRunID, err := actions.ExtractActionsRunIDFromURL(checkRun.HTMLURL)
if err != nil {
return err
}
err = actions.RerunActionsWorkflow(ghClient, repository, actionsRunID)
if err != nil {
return err
}
}
}
Expand Down
25 changes: 12 additions & 13 deletions internal/check_suites/check_suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ import (
)

type CheckSuite struct {
ID int64 `json:"id"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
RunsRerequestable bool `json:"runs_rerequestable"`
App actions.App `json:"app"`
ID int64 `json:"id"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
RunsRerequestable bool `json:"runs_rerequestable"`
App actions.App `json:"app"`
LatestCheckRunsCount int `json:"latest_check_runs_count"`
}

type CheckSuites struct {
CheckSuites []CheckSuite `json:"check_suites"`
}

func FilterFailedCheckSuites(checkSuites *CheckSuites) []CheckSuite {
var failedCheckSuites []CheckSuite
for _, checkSuite := range checkSuites.CheckSuites {
if checkSuite.Status == "completed" && checkSuite.Conclusion != "success" && checkSuite.Conclusion != "skipped" && checkSuite.Conclusion != "neutral" {
failedCheckSuites = append(failedCheckSuites, checkSuite)
}
}
return failedCheckSuites
func (checkSuite *CheckSuite) IsCompleted() bool {
return checkSuite.Status == "completed"
}

func (checkSuite *CheckSuite) IsSuccessful() bool {
return checkSuite.Conclusion == "success" || checkSuite.Conclusion == "skipped" || checkSuite.Conclusion == "neutral"
}

func GetCheckSuites(client api.RESTClient, repository repository.Repository, ref string) (*CheckSuites, error) {
Expand Down

0 comments on commit c39c6db

Please sign in to comment.