Feature - Include metadata in the results

Included metadata that can be passed an argument to the command line.
The same metadata will returned the `json` results.
This commit is contained in:
naveen 2021-02-22 15:32:39 -05:00 committed by Naveen
parent 9510d3e0d7
commit 7726ca7987
4 changed files with 23 additions and 13 deletions

View File

@ -61,10 +61,10 @@ ci-e2e: ## Runs ci e2e tests
ci-e2e: build check-env
$(call ndef, GITHUB_AUTH_TOKEN)
mkdir -p bin
./scorecard --repo=https://github.com/ossf/scorecard --show-details --format json > ./bin/results.json
./scorecard --repo=https://github.com/ossf/scorecard --format json --metadata=openssf > ./bin/results.json
ginkgo -p -v -cover ./...
mkdir -p cache
USE_DISK_CACHE=1 DISK_CACHE_PATH="./cache" ./scorecard --repo=https://github.com/ossf/scorecard --show-details --format json > ./bin/results.json
USE_DISK_CACHE=1 DISK_CACHE_PATH="./cache" ./scorecard --repo=https://github.com/ossf/scorecard --show-details --metadata=openssf --format json > ./bin/results.json
ginkgo -p -v -cover ./...

View File

@ -39,7 +39,8 @@ import (
var (
repo pkg.RepoURL
checksToRun []string
// This one has to use goflag instead of pflag because it's defined by zap
metaData []string
// This one has to use goflag instead of pflag because it's defined by zap.
logLevel = zap.LevelFlag("verbosity", zap.InfoLevel, "override the default log level")
format string
npm string
@ -149,16 +150,18 @@ type npmSearchResults struct {
}
type record struct {
Repo string
Date string
Checks []checkResult
Repo string
Date string
Checks []checkResult
MetaData []string
}
func outputJSON(results []pkg.Result) {
d := time.Now()
or := record{
Repo: repo.String(),
Date: d.Format("2006-01-02"),
Repo: repo.String(),
Date: d.Format("2006-01-02"),
MetaData: metaData,
}
for _, r := range results {
@ -255,6 +258,8 @@ func init() {
rootCmd.Flags().Var(&repo, "repo", "repository to check")
rootCmd.Flags().StringVar(&npm, "npm", "", "npm package to check. If the npm package has a GitHub repository")
rootCmd.Flags().StringVar(&format, "format", formatDefault, "output format. allowed values are [default, csv, json]")
rootCmd.Flags().StringSliceVar(
&metaData, "metadata", []string{}, "metadata for the project.It can be multiple separated by commas")
rootCmd.Flags().BoolVar(&showDetails, "show-details", false, "show extra details about each check")
checkNames := []string{}

View File

@ -17,19 +17,23 @@ type scorecard struct {
Confidence int `json:"Confidence"`
Details []string `json:"Details"`
} `json:"Checks"`
MetaData []string `json:"MetaData"`
}
var _ = Describe("E2E TEST:executable", func() {
Context("E2E TEST:Validating executable test", func() {
It("Should return valid test results for scorecard", func() {
file, _ := ioutil.ReadFile("../bin/results.json")
file, err := ioutil.ReadFile("../bin/results.json")
Expect(err).Should(BeNil())
data := scorecard{}
err := json.Unmarshal([]byte(file), &data)
err = json.Unmarshal(file, &data)
Expect(err).Should(BeNil())
Expect(len(data.MetaData)).ShouldNot(BeZero())
Expect(data.MetaData[0]).Should(BeEquivalentTo("openssf"))
for _, c := range data.Checks {
switch c.CheckName {

View File

@ -31,8 +31,9 @@ import (
)
type Result struct {
Cr checker.CheckResult
Name string
Cr checker.CheckResult
Name string
MetaData []string
}
type RepoURL struct {