Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f309d3f

Browse files
committedDec 2, 2020
Show new compliance level settings in report
Previously, the report was only displaying the permissive check mode setting.
1 parent 41fc8f9 commit f309d3f

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed
 

‎configuration/checkmode/checkmode.go

+10
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,13 @@ func Modes(defaultCheckModes map[projecttype.Type]map[Type]bool, customCheckMode
8686

8787
return checkModes
8888
}
89+
90+
func Compliance(checkModes map[Type]bool) string {
91+
for key, value := range checkModes {
92+
if value && (key == Strict || key == Specification || key == Permissive) {
93+
return key.String()
94+
}
95+
}
96+
97+
panic(fmt.Errorf("Unrecognized compliance configuration"))
98+
}

‎configuration/checkmode/checkmode_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ func TestMode(t *testing.T) {
5252
mergedCheckModes = Modes(defaultCheckModes, customCheckModes, testProjectType)
5353
assert.Equal(t, customCheckModes[testCheckMode], mergedCheckModes[testCheckMode], "Should be set to custom value")
5454
}
55+
56+
func TestCompliance(t *testing.T) {
57+
checkModes := map[Type]bool{
58+
Strict: false,
59+
Specification: false,
60+
Permissive: false,
61+
}
62+
63+
assert.Panics(t, func() { Compliance(checkModes) })
64+
checkModes[Strict] = true
65+
assert.Equal(t, Strict.String(), Compliance(checkModes))
66+
checkModes[Strict] = false
67+
checkModes[Specification] = true
68+
assert.Equal(t, Specification.String(), Compliance(checkModes))
69+
checkModes[Specification] = false
70+
checkModes[Permissive] = true
71+
assert.Equal(t, Permissive.String(), Compliance(checkModes))
72+
}

‎configuration/configuration.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
113113
}
114114

115115
logrus.WithFields(logrus.Fields{
116-
"compliance strict mode": customCheckModes[checkmode.Strict],
117-
"compliance specification mode": customCheckModes[checkmode.Specification],
118-
"compliance permissive mode": customCheckModes[checkmode.Permissive],
116+
"compliance": checkmode.Compliance(customCheckModes),
119117
"output format": OutputFormat(),
120118
"Library Manager submission mode": customCheckModes[checkmode.LibraryManagerSubmission],
121119
"Library Manager update mode": customCheckModes[checkmode.LibraryManagerIndexed],

‎result/result.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ type projectReportType struct {
5858
}
5959

6060
type projectConfigurationReportType struct {
61-
Permissive bool `json:"permissive"`
62-
LibraryManagerSubmit bool `json:"libraryManagerSubmit"`
63-
LibraryManagerUpdate bool `json:"libraryManagerUpdate"`
64-
Official bool `json:"official"`
61+
Compliance string `json:"compliance"`
62+
LibraryManagerSubmit bool `json:"libraryManagerSubmit"`
63+
LibraryManagerUpdate bool `json:"libraryManagerUpdate"`
64+
Official bool `json:"official"`
6565
}
6666

6767
type checkReportType struct {
@@ -129,8 +129,8 @@ func (results *Type) Record(checkedProject project.Type, checkConfiguration chec
129129
Path: checkedProject.Path,
130130
ProjectType: checkedProject.ProjectType.String(),
131131
Configuration: projectConfigurationReportType{
132-
Permissive: configuration.CheckModes(checkedProject.ProjectType)[checkmode.Permissive],
133-
LibraryManagerSubmit: configuration.CheckModes(checkedProject.ProjectType)[checkmode.Permissive],
132+
Compliance: checkmode.Compliance(configuration.CheckModes(checkedProject.ProjectType)),
133+
LibraryManagerSubmit: configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerSubmission],
134134
LibraryManagerUpdate: configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerIndexed],
135135
Official: configuration.CheckModes(checkedProject.ProjectType)[checkmode.Official],
136136
},

0 commit comments

Comments
 (0)
Please sign in to comment.