Skip to content

Commit

Permalink
Return DefaultBranch as part of ListBranches (#960)
Browse files Browse the repository at this point in the history
Co-authored-by: Azeem Shaikh <[email protected]>
  • Loading branch information
azeemshaikh38 and azeemsgoogle authored Sep 3, 2021
1 parent 830c4f5 commit 7b912e8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions clients/githubrepo/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func (handler *branchesHandler) setup() error {
handler.errSetup = sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("githubv4.Query: %v", err))
}
handler.defaultBranchRef = getBranchRefFrom(handler.data.Repository.DefaultBranchRef)
handler.branches = getBranchRefsFrom(handler.data.Repository.Refs.Nodes)
// Maybe add defaultBranchRef to branches.
handler.branches = getBranchRefsFrom(handler.data.Repository.Refs.Nodes, handler.defaultBranchRef)
})
return handler.errSetup
}
Expand Down Expand Up @@ -194,10 +193,18 @@ func getBranchRefFrom(data branch) *clients.BranchRef {
return branchRef
}

func getBranchRefsFrom(data []branch) []*clients.BranchRef {
func getBranchRefsFrom(data []branch, defaultBranch *clients.BranchRef) []*clients.BranchRef {
branchRefs := make([]*clients.BranchRef, len(data))
var defaultFound bool
for i, b := range data {
branchRefs[i] = getBranchRefFrom(b)
if defaultBranch != nil && branchRefs[i].Name == defaultBranch.Name {
defaultFound = true
}
}
if !defaultFound {
// nolint: makezero
branchRefs = append(branchRefs, defaultBranch)
}
return branchRefs
}

0 comments on commit 7b912e8

Please sign in to comment.