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

Commit 0d2ec50

Browse files
Waterdripsalexellis
authored andcommitted
Make Github Status namespace checks by APP ID
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>
1 parent edf87c1 commit 0d2ec50

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

github-status/handler.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,23 @@ func getLogs(status *sdk.CommitStatus, event *sdk.Event) (string, error) {
119119
}
120120

121121
func reportToGithub(commitStatus *sdk.CommitStatus, event *sdk.Event) error {
122+
appID := os.Getenv("github_app_id")
122123
if os.Getenv("use_checks") == "false" {
123-
return reportStatus(commitStatus.Status, commitStatus.Description, commitStatus.Context, event)
124+
return reportStatus(commitStatus.Status, commitStatus.Description, appID, event)
124125
}
125126
return reportCheck(commitStatus, event)
126127
}
127128

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

130132
ctx := context.Background()
131133

132134
url := buildPublicStatusURL(status, statusContext, event)
133135

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

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

138140
client := factory.MakeClient(ctx, token)
139141

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

148150
func reportCheck(commitStatus *sdk.CommitStatus, event *sdk.Event) error {
149151
ctx := context.Background()
150-
152+
appID := os.Getenv("github_app_id")
151153
status := commitStatus.Status
152154
url := buildPublicStatusURL(commitStatus.Status, commitStatus.Context, event)
153155

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

156158
client := factory.MakeClient(ctx, token)
157159

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

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

174176
checkRunStatus := getCheckRunStatus(&status)
175177
conclusion := getCheckRunConclusion(&status)
@@ -214,7 +216,7 @@ func reportCheck(commitStatus *sdk.CommitStatus, event *sdk.Event) error {
214216
log.Printf("Creating check run %s", check.Name)
215217
}
216218
if apiErr != nil {
217-
return fmt.Errorf("Failed to report status %s, error: %s", status, apiErr.Error())
219+
return fmt.Errorf("failed to report status %s, error: %s", status, apiErr.Error())
218220
}
219221
return nil
220222
}

0 commit comments

Comments
 (0)