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

Commit

Permalink
Make Github Status namespace checks by APP ID
Browse files Browse the repository at this point in the history
The Github Status function was not namespacing the check-runs. It was
using the same ting for each installed app. This has been changed to
namespace by app_id. This means that 2 + installations on the same
repository can now correctly create & report github check runs.

This has been tested by installing 2x OCF installations, then running a
pipeline. This failed of half of the functions as they didn't get the
correct check for that app.

Then I added the new function to each OFC installation, and re-ran a
pipeline. Every check run was created and reported back correctly.

Signed-off-by: Alistair Hey <alistair@heyal.co.uk>
  • Loading branch information
Waterdrips authored and alexellis committed May 21, 2020
1 parent edf87c1 commit 0d2ec50
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions github-status/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,23 @@ func getLogs(status *sdk.CommitStatus, event *sdk.Event) (string, error) {
}

func reportToGithub(commitStatus *sdk.CommitStatus, event *sdk.Event) error {
appID := os.Getenv("github_app_id")
if os.Getenv("use_checks") == "false" {
return reportStatus(commitStatus.Status, commitStatus.Description, commitStatus.Context, event)
return reportStatus(commitStatus.Status, commitStatus.Description, appID, event)
}
return reportCheck(commitStatus, event)
}

func reportStatus(status string, desc string, statusContext string, event *sdk.Event) error {
appID := os.Getenv("github_app_id")

ctx := context.Background()

url := buildPublicStatusURL(status, statusContext, event)

repoStatus := buildStatus(status, desc, statusContext, url)

log.Printf("Status: %s, Context: %s, GitHub AppID: %d, Repo: %s, Owner: %s", status, statusContext, event.InstallationID, event.Repository, event.Owner)
log.Printf("Status: %s, Context: %s, GitHub AppID: %s, Repo: %s, Owner: %s", status, statusContext, appID, event.Repository, event.Owner)

client := factory.MakeClient(ctx, token)

Expand All @@ -147,11 +149,11 @@ func reportStatus(status string, desc string, statusContext string, event *sdk.E

func reportCheck(commitStatus *sdk.CommitStatus, event *sdk.Event) error {
ctx := context.Background()

appID := os.Getenv("github_app_id")
status := commitStatus.Status
url := buildPublicStatusURL(commitStatus.Status, commitStatus.Context, event)

log.Printf("Check: %s, Context: %s, GitHub AppID: %d, Repo: %s, Owner: %s", status, commitStatus.Context, event.InstallationID, event.Repository, event.Owner)
log.Printf("Check: %s, Context: %s, GitHub AppID: %s, Repo: %s, Owner: %s", status, commitStatus.Context, appID, event.Repository, event.Owner)

client := factory.MakeClient(ctx, token)

Expand All @@ -169,7 +171,7 @@ func reportCheck(commitStatus *sdk.CommitStatus, event *sdk.Event) error {
logValue = formatLog(logs, maxCheckMessageLength)
}

checks, _, _ := client.Checks.ListCheckRunsForRef(ctx, event.Owner, event.Repository, event.SHA, &github.ListCheckRunsOptions{CheckName: &commitStatus.Context})
checks, _, _ := client.Checks.ListCheckRunsForRef(ctx, event.Owner, event.Repository, event.SHA, &github.ListCheckRunsOptions{CheckName: &appID})

checkRunStatus := getCheckRunStatus(&status)
conclusion := getCheckRunConclusion(&status)
Expand Down Expand Up @@ -214,7 +216,7 @@ func reportCheck(commitStatus *sdk.CommitStatus, event *sdk.Event) error {
log.Printf("Creating check run %s", check.Name)
}
if apiErr != nil {
return fmt.Errorf("Failed to report status %s, error: %s", status, apiErr.Error())
return fmt.Errorf("failed to report status %s, error: %s", status, apiErr.Error())
}
return nil
}
Expand Down

0 comments on commit 0d2ec50

Please sign in to comment.