Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Duplicate the Check Run for the new commit instead of rebinding #18

Merged
merged 1 commit into from Nov 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 36 additions & 30 deletions verify/plugin.go
Expand Up @@ -176,31 +176,6 @@ func (p PRPlugin) resetCheckRun(client *github.Client, owner, repo string, headS
return checkRun, nil
}

// rebindCheckRun modifies the bound commit to the Check-Run with id checkRunID to headSHA.
// It returns an error in case it couldn't be rebound.
func (p PRPlugin) rebindCheckRun(client *github.Client, owner, repo string, checkRunID int64, headSHA string) error {
p.debugf("updating check run %q on %s/%s...", p.Name, owner, repo)

checkRun, updateResp, err := client.Checks.UpdateCheckRun(
context.TODO(),
owner,
repo,
checkRunID,
github.UpdateCheckRunOptions{
Name: p.Name,
HeadSHA: github.String(headSHA),
},
)
if err != nil {
return fmt.Errorf("unable to update check result: %w", err)
}

p.debugf("update check API response: %+v", updateResp)
p.debugf("updated run: %+v", checkRun)

return nil
}

// finishCheckRun updates the Check-Run with id checkRunID setting its output.
// It returns an error in case it couldn't be updated.
func (p PRPlugin) finishCheckRun(client *github.Client, owner, repo string, checkRunID int64, conclusion, summary, text string) error {
Expand All @@ -226,6 +201,36 @@ func (p PRPlugin) finishCheckRun(client *github.Client, owner, repo string, chec
return nil
}

// duplicateCheckRun creates a new Check-Run with the same info as the provided one but for a new headSHA
func (p PRPlugin) duplicateCheckRun(client *github.Client, owner, repo, headSHA string, checkRun *github.CheckRun) (*github.CheckRun, error) {
p.debugf("creating check run %q on %s/%s @ %s...", p.Name, owner, repo, headSHA)

checkRun, res, err := client.Checks.CreateCheckRun(
context.TODO(),
owner,
repo,
github.CreateCheckRunOptions{
Name: p.Name,
HeadSHA: headSHA,
DetailsURL: checkRun.DetailsURL,
ExternalID: checkRun.ExternalID,
Status: checkRun.Status,
Conclusion: checkRun.Conclusion,
StartedAt: checkRun.StartedAt,
CompletedAt: checkRun.CompletedAt,
Output: checkRun.Output,
},
)
if err != nil {
return nil, fmt.Errorf("unable to submit check result: %w", err)
}

p.debugf("create check API response: %+v", res)
p.debugf("created run: %+v", checkRun)

return checkRun, nil
}

////////////////////////////////////////////////////////////////////////////////
// Entrypoint //
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -310,17 +315,18 @@ func (p PRPlugin) onSync(env *ActionsEnv) error {
return err
}

// Rebind the check run
if err := p.rebindCheckRun(env.Client, env.Owner, env.Repo, checkRun.GetID(), after); err != nil {
return err
}

// Rerun the tests if they weren't finished
if !Finished.Equal(checkRun.GetStatus()) {
// Process the PR and submit the results
return p.processAndSubmit(env, checkRun)
}

// Create a duplicate for the new commit
checkRun, err = p.duplicateCheckRun(env.Client, env.Owner, env.Repo, after, checkRun)
if err != nil {
return err
}

// Return failure here too so that the whole suite fails (since the actions
// suite seems to ignore failing check runs when calculating general failure)
if *checkRun.Conclusion == "failure" {
Expand Down