Skip to content

Commit

Permalink
Duplicate the Check Run for the new commit instead of rebinding
Browse files Browse the repository at this point in the history
Related: google/go-github#1652
Signed-off-by: Adrian Orive <adrian.orive.oneca@gmail.com>
  • Loading branch information
Adirio committed Nov 18, 2020
1 parent 47b6d48 commit 19b23b3
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions verify/plugin.go
Expand Up @@ -226,6 +226,38 @@ 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
// TODO(Adirio): rebinding should be preferred but it is bugged, see: https://github.com/google/go-github/issues/1652
// When is is solved, remove the duplicateCheckRun function.
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 @@ -311,16 +343,26 @@ func (p PRPlugin) onSync(env *ActionsEnv) error {
}

// Rebind the check run
if err := p.rebindCheckRun(env.Client, env.Owner, env.Repo, checkRun.GetID(), after); err != nil {
return err
}
// TODO(Adirio): rebinding should be preferred but it is bugged, see: https://github.com/google/go-github/issues/1652
// When it is solved, uncomment the rebindCheckRun call and its error check.
//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
// TODO(Adirio): rebinding should be preferred but it is bugged, see: https://github.com/google/go-github/issues/1652
// When it is solved, remove the duplicateCheckRun call and its error check.
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

0 comments on commit 19b23b3

Please sign in to comment.