Skip to content

Commit 4e140f9

Browse files
committed
Fallback to ruleset for non-default branches too
Signed-off-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 80ee3ec commit 4e140f9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

clients/githubrepo/branches.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,18 @@ func (handler *branchesHandler) query(branchName string) (*clients.BranchRef, er
307307
"name": githubv4.String(handler.repourl.repo),
308308
"branchRefName": githubv4.String(refPrefix + branchName),
309309
}
310+
// Attempt to fetch branch protection rules, which require admin permission.
311+
// Ignore permissions errors if we know the repository is using rulesets, so non-admins can still get a score.
310312
queryData := new(branchData)
311313
if err := handler.graphClient.Query(handler.ctx, queryData, vars); err != nil {
312-
return nil, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("githubv4.Query: %v", err))
314+
// always report errors which aren't token permission related
315+
if !isPermissionsError(err) {
316+
return nil, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("githubv4.Query: %v", err))
317+
}
318+
// only report permission errors if no ruleset data
319+
if len(handler.ruleSets) == 0 {
320+
return nil, sce.WithMessage(sce.ErrScorecardInternal, classicBranchErrMsg)
321+
}
313322
}
314323
rules, err := rulesMatchingBranch(handler.ruleSets, branchName, branchName == handler.defaultBranchName)
315324
if err != nil {

0 commit comments

Comments
 (0)