Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion clients/githubrepo/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,18 @@
"name": githubv4.String(handler.repourl.repo),
"branchRefName": githubv4.String(refPrefix + branchName),
}
// Attempt to fetch branch protection rules, which require admin permission.
// Ignore permissions errors if we know the repository is using rulesets, so non-admins can still get a score.
queryData := new(branchData)
if err := handler.graphClient.Query(handler.ctx, queryData, vars); err != nil {
return nil, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("githubv4.Query: %v", err))
// always report errors which aren't token permission related
if !isPermissionsError(err) {
return nil, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("githubv4.Query: %v", err))

Check warning on line 316 in clients/githubrepo/branches.go

View check run for this annotation

Codecov / codecov/patch

clients/githubrepo/branches.go#L315-L316

Added lines #L315 - L316 were not covered by tests
}
// only report permission errors if no ruleset data
if len(handler.ruleSets) == 0 {
return nil, sce.WithMessage(sce.ErrScorecardInternal, classicBranchErrMsg)

Check warning on line 320 in clients/githubrepo/branches.go

View check run for this annotation

Codecov / codecov/patch

clients/githubrepo/branches.go#L319-L320

Added lines #L319 - L320 were not covered by tests
}
}
rules, err := rulesMatchingBranch(handler.ruleSets, branchName, branchName == handler.defaultBranchName)
if err != nil {
Expand Down
Loading