Skip to content

Commit

Permalink
added all code from existing pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalk007 committed Dec 29, 2024
1 parent 802ca5b commit 47e8c63
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion scanpullrequest/scanallpullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func TestScanAllPullRequestsMultiRepo(t *testing.T) {
firstRepoParams := utils.Params{
JFrogPlatform: utils.JFrogPlatform{XrayVersion: xrayVersion, XscVersion: xscVersion},
Scan: utils.Scan{
FailOnSecurityIssues: &failOnSecurityIssues,
AddPrCommentOnSuccess: true,
FailOnSecurityIssues: &failOnSecurityIssues,
Projects: []utils.Project{{
InstallCommandName: "npm",
InstallCommandArgs: []string{"i"},
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 @@ -60,6 +60,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 @@ -157,6 +157,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 @@ -222,6 +223,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 @@ -401,6 +401,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

0 comments on commit 47e8c63

Please sign in to comment.