Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip comment generation on PR success if needed #778

Closed
wants to merge 9 commits into from
1 change: 1 addition & 0 deletions scanpullrequest/scanallpullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestScanAllPullRequestsMultiRepo(t *testing.T) {
Git: gitParams.Git,
JFrogPlatform: utils.JFrogPlatform{XrayVersion: xrayVersion, XscVersion: xscVersion},
Scan: utils.Scan{
AddPrCommentOnSuccess: true,
FailOnSecurityIssues: &failOnSecurityIssues,
Projects: []utils.Project{{WorkingDirs: []string{utils.RootDir}, UseWrapper: &utils.TrueVal}}},
}
Expand Down
10 changes: 6 additions & 4 deletions utils/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,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 issues.IssuesExists() || 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 @@ -59,6 +59,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 @@ -158,6 +158,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 @@ -223,6 +224,11 @@ func (s *Scan) setDefaultsIfNeeded() (err error) {
return
}
}
if !s.AddPrCommentOnSuccess {
if s.AddPrCommentOnSuccess, err = getBoolEnv(AddPrCommentOnSuccessEnv, true); err != nil {
return
}
}
if !s.DetectionOnly {
if s.DetectionOnly, err = getBoolEnv(DetectionOnlyEnv, false); err != nil {
return
Expand Down
1 change: 1 addition & 0 deletions utils/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,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, true, 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
Loading