Skip to content

Commit 73f5e9b

Browse files
committed
Add check of invalid label in rescue
1 parent 72be62a commit 73f5e9b

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

pkg/gh/label.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package gh
2+
3+
import "strings"
4+
5+
// IsRequestedMyshoesLabel checks if the job has appropriate labels for myshoes
6+
func IsRequestedMyshoesLabel(labels []string) bool {
7+
// Accept dependabot runner in GHES
8+
if len(labels) == 1 && strings.EqualFold(labels[0], "dependabot") {
9+
return true
10+
}
11+
12+
for _, label := range labels {
13+
if strings.EqualFold(label, "myshoes") || strings.EqualFold(label, "self-hosted") {
14+
return true
15+
}
16+
}
17+
return false
18+
}

pkg/starter/scripts.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (s *Starter) getSetupScript(ctx context.Context, targetScope, runnerName st
4646

4747
func (s *Starter) getSetupRawScript(ctx context.Context, targetScope, runnerName string) (string, error) {
4848
runnerUser := config.Config.RunnerUser
49-
githubURL := config.Config.GitHubURL
5049

5150
targetRunnerVersion := s.runnerVersion
5251
if strings.EqualFold(s.runnerVersion, "latest") {
@@ -77,9 +76,7 @@ func (s *Starter) getSetupRawScript(ctx context.Context, targetScope, runnerName
7776
}
7877

7978
var labels []string
80-
if githubURL != "" && githubURL != "https://github.com" {
81-
labels = append(labels, "dependabot")
82-
}
79+
labels = append(labels, "dependabot")
8380

8481
v := templateCreateLatestRunnerOnceValue{
8582
Scope: targetScope,

pkg/starter/starter.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ func enqueueRescueRun(ctx context.Context, pendingRun datastore.PendingWorkflowR
483483
continue
484484
}
485485

486+
// Check if the job has appropriate labels for myshoes
487+
if !gh.IsRequestedMyshoesLabel(job.Labels) {
488+
logger.Logf(true, "skip rescue job because it doesn't have myshoes labels: (repo: %s, gh_run_id: %d, gh_job_id: %d, labels: %v)",
489+
fullName, pendingRun.WorkflowRun.GetID(), job.GetID(), job.Labels)
490+
continue
491+
}
492+
486493
// Get installation ID from target scope
487494
installationID, err := gh.IsInstalledGitHubApp(ctx, target.Scope)
488495
if err != nil {

pkg/web/webhook.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func receiveWorkflowJobWebhook(ctx context.Context, event *github.WorkflowJobEve
194194
repoURL := repo.GetHTMLURL()
195195

196196
labels := event.GetWorkflowJob().Labels
197-
if !isRequestedMyshoesLabel(labels) {
197+
if !gh.IsRequestedMyshoesLabel(labels) {
198198
// is not request myshoes, So will be ignored
199199
logger.Logf(true, "label \"myshoes\" is not found in labels, so ignore (labels: %s)", labels)
200200
return nil
@@ -221,16 +221,3 @@ func receiveWorkflowJobWebhook(ctx context.Context, event *github.WorkflowJobEve
221221
return nil
222222
}
223223

224-
func isRequestedMyshoesLabel(labels []string) bool {
225-
// Accept dependabot runner in GHES
226-
if len(labels) == 1 && strings.EqualFold(labels[0], "dependabot") {
227-
return true
228-
}
229-
230-
for _, label := range labels {
231-
if strings.EqualFold(label, "myshoes") || strings.EqualFold(label, "self-hosted") {
232-
return true
233-
}
234-
}
235-
return false
236-
}

0 commit comments

Comments
 (0)