Skip to content

Commit

Permalink
options: Restore logic for publishing results
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <foo@auggie.dev>
  • Loading branch information
justaugustus committed May 26, 2022
1 parent fac7c3d commit 14eb9b8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
7 changes: 7 additions & 0 deletions entrypoint/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func New() (*cobra.Command, error) {
"path to output results to",
)

actionCmd.Flags().BoolVar(
&opts.PublishResults,
"publish",
opts.PublishResults,
"if set, results will be published (for public repositories only)",
)

// Adapt scorecard's PreRunE to support an output file
// TODO(scorecard): Move this into scorecard
var out, stdout *os.File
Expand Down
12 changes: 5 additions & 7 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ type Options struct {
IsForkStr string `env:"SCORECARD_IS_FORK"`
// TODO(options): This may be better as a bool
PrivateRepoStr string `env:"SCORECARD_PRIVATE_REPOSITORY"`
PublishResults bool

// Input parameters
InputResultsFile string `env:"INPUT_RESULTS_FILE"`
InputResultsFormat string `env:"INPUT_RESULTS_FORMAT"`
InputPublishResults string `env:"INPUT_PUBLISH_RESULTS"`
InputResultsFile string `env:"INPUT_RESULTS_FILE"`
InputResultsFormat string `env:"INPUT_RESULTS_FORMAT"`
}

const (
Expand Down Expand Up @@ -192,7 +192,7 @@ func (o *Options) Print() {
fmt.Printf("Repository: %s\n", o.ScorecardOpts.Repo)
fmt.Printf("Fork repository: %s\n", o.IsForkStr)
fmt.Printf("Private repository: %s\n", o.PrivateRepoStr)
fmt.Printf("Publication enabled: %+v\n", o.ScorecardOpts.PublishResults)
fmt.Printf("Publication enabled: %+v\n", o.PublishResults)
fmt.Printf("Format: %s\n", o.ScorecardOpts.Format)
fmt.Printf("Policy file: %s\n", o.ScorecardOpts.PolicyFile)
fmt.Printf("Default branch: %s\n", o.DefaultBranch)
Expand All @@ -211,9 +211,7 @@ func (o *Options) SetPublishResults() {
)
}

if privateRepo {
o.ScorecardOpts.PublishResults = false
}
o.PublishResults = o.PublishResults && !privateRepo
}

// SetRepoInfo gets the path to the GitHub event and sets the
Expand Down
40 changes: 40 additions & 0 deletions options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,43 @@ func TestPrint(t *testing.T) {
})
}
}

func TestSetPublishResults(t *testing.T) {
tests := []struct {
name string
privateRepo string
userInput bool
want bool
}{
{
name: "DefaultNoInput",
want: false,
},
{
name: "InputTruePrivateRepo",
privateRepo: "true",
userInput: true,
want: false,
},
{
name: "InvalidValueForPrivateRepo",
privateRepo: "invalid-value",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := &Options{
ScorecardOpts: options.New(),
}
opts.PrivateRepoStr = tt.privateRepo

opts.SetPublishResults()
got := opts.PublishResults

if !cmp.Equal(tt.want, got) {
t.Errorf("New(): -want, +got:\n%s", cmp.Diff(tt.want, got))
}
})
}
}

0 comments on commit 14eb9b8

Please sign in to comment.