Skip to content

Commit efeceb7

Browse files
🐛 also check releases/v2 branch for github/codeql-action (#518)
* check v2 branch too Signed-off-by: Spencer Schrock <[email protected]> --------- Signed-off-by: Spencer Schrock <[email protected]>
1 parent 18ba55b commit efeceb7

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

app/server/verify_workflow.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,16 @@ func (g *githubVerifier) contains(owner, repo, hash string) (bool, error) {
263263
if contains {
264264
return true, nil
265265
}
266-
// github/codeql-action has commits from their v1 release branch that don't show up in the default branch
266+
// github/codeql-action has commits from their v1 and v2 release branch that don't show up in the default branch
267267
// this isn't the best approach for now, but theres no universal "does this commit belong to this repo" call
268268
if owner == "github" && repo == "codeql-action" {
269-
contains, err = g.branchContains("releases/v1", owner, repo, hash)
269+
contains, err = g.branchContains("releases/v2", owner, repo, hash)
270+
if err != nil {
271+
return false, err
272+
}
273+
if !contains {
274+
contains, err = g.branchContains("releases/v1", owner, repo, hash)
275+
}
270276
}
271277
return contains, err
272278
}

app/server/verify_workflow_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ func (s suffixStubTripper) RoundTrip(r *http.Request) (*http.Response, error) {
115115
}, nil
116116
}
117117

118-
func Test_githubVerifier_contains(t *testing.T) {
118+
func Test_githubVerifier_contains_codeql_v1(t *testing.T) {
119119
t.Parallel()
120120
httpClient := http.Client{
121121
Transport: suffixStubTripper{
122122
responsePaths: map[string]string{
123123
"codeql-action": "./testdata/api/github/repository.json", // api call which finds the default branch
124124
"main...somehash": "./testdata/api/github/divergent.json", // doesnt belong to default branch
125+
"v2...somehash": "./testdata/api/github/divergent.json", // doesnt belong to releases/v2 branch
125126
"v1...somehash": "./testdata/api/github/containsCommit.json", // belongs to releases/v1 branch
126127
},
127128
},
@@ -140,6 +141,31 @@ func Test_githubVerifier_contains(t *testing.T) {
140141
}
141142
}
142143

144+
func Test_githubVerifier_contains_codeql_v2(t *testing.T) {
145+
t.Parallel()
146+
httpClient := http.Client{
147+
Transport: suffixStubTripper{
148+
responsePaths: map[string]string{
149+
"codeql-action": "./testdata/api/github/repository.json", // api call which finds the default branch
150+
"main...somehash": "./testdata/api/github/divergent.json", // doesnt belong to default branch
151+
"v2...somehash": "./testdata/api/github/containsCommit.json", // belongs to releases/v2 branch
152+
},
153+
},
154+
}
155+
client := github.NewClient(&httpClient)
156+
gv := githubVerifier{
157+
ctx: context.Background(),
158+
client: client,
159+
}
160+
got, err := gv.contains("github", "codeql-action", "somehash")
161+
if err != nil {
162+
t.Fatalf("unexpected error: %v", err)
163+
}
164+
if got != true {
165+
t.Errorf("expected to contain hash, but it didnt")
166+
}
167+
}
168+
143169
func FuzzVerifyWorkflow(f *testing.F) {
144170
testfiles := []string{
145171
"testdata/workflow-valid.yml",

0 commit comments

Comments
 (0)