Skip to content

Commit

Permalink
cr comments
Browse files Browse the repository at this point in the history
Signed-off-by: Raghav Kaul <raghavkaul@google.com>
  • Loading branch information
raghavkaul committed Dec 8, 2022
1 parent 527abd2 commit 8719a2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion checks/evaluation/branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func codeownerBranchProtection(
case true:
info(dl, log, "codeowner review is required on branch '%s'", *branch.Name)
if len(codeownersFiles) == 0 {
warn(dl, log, "no codeowners files found")
warn(dl, log, "codeowners branch protection is being ignored - but no codeowners file found in repo")
} else {
score++
}
Expand Down
1 change: 0 additions & 1 deletion checks/raw/branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func BranchProtection(c clients.RepoClient) (checker.BranchProtectionsData, erro
if err := collectCodeownersFiles(c, &codeownersFiles); err != nil {
return checker.BranchProtectionsData{}, err
}
fmt.Printf("codeownersFiles: %v\n", codeownersFiles)

// No error, return the data.
return checker.BranchProtectionsData{
Expand Down
15 changes: 12 additions & 3 deletions pkg/json_raw_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ type jsonBranchProtection struct {
Name string `json:"name"`
}

type jsonBranchProtectionMetadata struct {
Branches []jsonBranchProtection `json:"branches"`
CodeownersFiles []string `json:"codeownersFiles"`
}

type jsonReview struct {
State string `json:"state"`
Reviewer jsonUser `json:"reviewer"`
Expand Down Expand Up @@ -265,7 +270,7 @@ type jsonRawResults struct {
// Note: we return one at most.
DependencyUpdateTools []jsonTool `json:"dependencyUpdateTools"`
// Branch protection settings for development and release branches.
BranchProtections []jsonBranchProtection `json:"branchProtections"`
BranchProtections jsonBranchProtectionMetadata `json:"branchProtections"`
// Contributors. Note: we could use the list of commits instead to store this data.
// However, it's harder to get statistics using commit list, so we have a dedicated
// structure for it.
Expand Down Expand Up @@ -711,7 +716,7 @@ func (r *jsonScorecardRawResult) addDependencyUpdateToolRawResults(dut *checker.

//nolint:unparam
func (r *jsonScorecardRawResult) addBranchProtectionRawResults(bp *checker.BranchProtectionsData) error {
r.Results.BranchProtections = []jsonBranchProtection{}
branches := []jsonBranchProtection{}
for _, v := range bp.Branches {
var bp *jsonBranchProtectionSettings
if v.Protected != nil && *v.Protected {
Expand All @@ -728,11 +733,15 @@ func (r *jsonScorecardRawResult) addBranchProtectionRawResults(bp *checker.Branc
StatusCheckContexts: v.BranchProtectionRule.CheckRules.Contexts,
}
}
r.Results.BranchProtections = append(r.Results.BranchProtections, jsonBranchProtection{
branches = append(branches, jsonBranchProtection{
Name: *v.Name,
Protection: bp,
})
}
r.Results.BranchProtections.Branches = branches

r.Results.BranchProtections.CodeownersFiles = bp.CodeownersFiles

return nil
}

Expand Down

0 comments on commit 8719a2b

Please sign in to comment.