Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions utils/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ func HandlePullRequestCommentsAfterScan(issues *IssuesCollection, repo *Reposito
}

// Add summary (SCA, license) scan comment
for _, comment := range generatePullRequestSummaryComment(issues, repo.OutputWriter) {
if err = client.AddPullRequestComment(context.Background(), repo.RepoOwner, repo.RepoName, comment, pullRequestID); err != nil {
err = errors.New("couldn't add pull request comment: " + err.Error())
return
if repo.AddPrCommentOnSuccess {
for _, comment := range generatePullRequestSummaryComment(issues, repo.OutputWriter) {
if err = client.AddPullRequestComment(context.Background(), repo.RepoOwner, repo.RepoName, comment, pullRequestID); err != nil {
err = errors.New("couldn't add pull request comment: " + err.Error())
return
}
}
}

Expand Down
1 change: 1 addition & 0 deletions utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
jfrogProjectEnv = "JF_PROJECT"
IncludeAllVulnerabilitiesEnv = "JF_INCLUDE_ALL_VULNERABILITIES"
AvoidPreviousPrCommentsDeletionEnv = "JF_AVOID_PREVIOUS_PR_COMMENTS_DELETION"
AddPrCommentOnSuccessEnv = "JF_PR_ADD_SUCCESS_COMMENT"
FailOnSecurityIssuesEnv = "JF_FAIL"
UseWrapperEnv = "JF_USE_WRAPPER"
DepsRepoEnv = "JF_DEPS_REPO"
Expand Down
6 changes: 6 additions & 0 deletions utils/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type Scan struct {
AvoidPreviousPrCommentsDeletion bool `yaml:"avoidPreviousPrCommentsDeletion,omitempty"`
MinSeverity string `yaml:"minSeverity,omitempty"`
DisableJas bool `yaml:"disableJas,omitempty"`
AddPrCommentOnSuccess bool `yaml:"addPrCommentOnSuccess,omitempty"`
AllowedLicenses []string `yaml:"allowedLicenses,omitempty"`
Projects []Project `yaml:"projects,omitempty"`
EmailDetails `yaml:",inline"`
Expand Down Expand Up @@ -220,6 +221,11 @@ func (s *Scan) setDefaultsIfNeeded() (err error) {
return
}
}
if !s.AddPrCommentOnSuccess {
if s.AddPrCommentOnSuccess, err = getBoolEnv(AddPrCommentOnSuccessEnv, false); err != nil {
return
}
}
if !s.DetectionOnly {
if s.DetectionOnly, err = getBoolEnv(DetectionOnlyEnv, false); err != nil {
return
Expand Down
3 changes: 3 additions & 0 deletions utils/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func TestExtractAndAssertRepoParams(t *testing.T) {
assert.Equal(t, "High", repo.MinSeverity)
assert.True(t, repo.FixableOnly)
assert.True(t, repo.DisableJas)
assert.True(t, repo.AddPrCommentOnSuccess)
assert.True(t, repo.DetectionOnly)
assert.Equal(t, true, repo.AggregateFixes)
assert.Equal(t, "[email protected]", repo.EmailAuthor)
Expand Down Expand Up @@ -350,6 +351,7 @@ func TestGenerateConfigAggregatorFromEnv(t *testing.T) {
IncludeAllVulnerabilitiesEnv: "true",
AvoidPreviousPrCommentsDeletionEnv: "true",
FailOnSecurityIssuesEnv: "false",
AddPrCommentOnSuccessEnv: "false",
MinSeverityEnv: "medium",
FixableOnlyEnv: "true",
DisableJasEnv: "true",
Expand Down Expand Up @@ -397,6 +399,7 @@ func validateBuildRepoAggregator(t *testing.T, repo *Repository, gitParams *Git,
assert.Equal(t, "Medium", repo.MinSeverity)
assert.Equal(t, true, repo.FixableOnly)
assert.Equal(t, true, repo.DisableJas)
assert.Equal(t, false, repo.AddPrCommentOnSuccess)
assert.Equal(t, true, repo.DetectionOnly)
assert.ElementsMatch(t, []string{"MIT", "Apache-2.0"}, repo.AllowedLicenses)
assert.Equal(t, gitParams.RepoOwner, repo.RepoOwner)
Expand Down