Skip to content

Commit aa9d487

Browse files
authored
Merge branch 'dev' into enable-conan-support
2 parents 5aa9bbe + b70fc31 commit aa9d487

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

scanpullrequest/scanallpullrequests_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ func TestScanAllPullRequestsMultiRepo(t *testing.T) {
113113
firstRepoParams := utils.Params{
114114
JFrogPlatform: utils.JFrogPlatform{XrayVersion: xrayVersion, XscVersion: xscVersion},
115115
Scan: utils.Scan{
116-
FailOnSecurityIssues: &failOnSecurityIssues,
116+
AddPrCommentOnSuccess: true,
117+
FailOnSecurityIssues: &failOnSecurityIssues,
117118
Projects: []utils.Project{{
118119
InstallCommandName: "npm",
119120
InstallCommandArgs: []string{"i"},
@@ -127,8 +128,9 @@ func TestScanAllPullRequestsMultiRepo(t *testing.T) {
127128
Git: gitParams.Git,
128129
JFrogPlatform: utils.JFrogPlatform{XrayVersion: xrayVersion, XscVersion: xscVersion},
129130
Scan: utils.Scan{
130-
FailOnSecurityIssues: &failOnSecurityIssues,
131-
Projects: []utils.Project{{WorkingDirs: []string{utils.RootDir}, UseWrapper: &utils.TrueVal}}},
131+
AddPrCommentOnSuccess: true,
132+
FailOnSecurityIssues: &failOnSecurityIssues,
133+
Projects: []utils.Project{{WorkingDirs: []string{utils.RootDir}, UseWrapper: &utils.TrueVal}}},
132134
}
133135

134136
configAggregator := utils.RepoAggregator{
@@ -176,7 +178,8 @@ func TestScanAllPullRequests(t *testing.T) {
176178
params := utils.Params{
177179
JFrogPlatform: utils.JFrogPlatform{XrayVersion: xrayVersion, XscVersion: xscVersion},
178180
Scan: utils.Scan{
179-
FailOnSecurityIssues: &falseVal,
181+
AddPrCommentOnSuccess: true,
182+
FailOnSecurityIssues: &falseVal,
180183
Projects: []utils.Project{{
181184
InstallCommandName: "npm",
182185
InstallCommandArgs: []string{"i"},

utils/comment.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ func HandlePullRequestCommentsAfterScan(issues *IssuesCollection, repo *Reposito
4545
}
4646

4747
// Add summary (SCA, license) scan comment
48-
for _, comment := range generatePullRequestSummaryComment(issues, repo.OutputWriter) {
49-
if err = client.AddPullRequestComment(context.Background(), repo.RepoOwner, repo.RepoName, comment, pullRequestID); err != nil {
50-
err = errors.New("couldn't add pull request comment: " + err.Error())
51-
return
48+
if issues.IssuesExists() || repo.AddPrCommentOnSuccess {
49+
for _, comment := range generatePullRequestSummaryComment(issues, repo.OutputWriter) {
50+
if err = client.AddPullRequestComment(context.Background(), repo.RepoOwner, repo.RepoName, comment, pullRequestID); err != nil {
51+
err = errors.New("couldn't add pull request comment: " + err.Error())
52+
return
53+
}
5254
}
5355
}
5456

utils/consts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ const (
5353

5454
// Repository environment variables - Ignored if the frogbot-config.yml file is used
5555
InstallCommandEnv = "JF_INSTALL_DEPS_CMD"
56+
MaxPnpmTreeDepthEnv = "JF_PNPM_MAX_TREE_DEPTH"
5657
RequirementsFileEnv = "JF_REQUIREMENTS_FILE"
5758
WorkingDirectoryEnv = "JF_WORKING_DIR"
5859
PathExclusionsEnv = "JF_PATH_EXCLUSIONS"
5960
jfrogWatchesEnv = "JF_WATCHES"
6061
jfrogProjectEnv = "JF_PROJECT"
6162
IncludeAllVulnerabilitiesEnv = "JF_INCLUDE_ALL_VULNERABILITIES"
6263
AvoidPreviousPrCommentsDeletionEnv = "JF_AVOID_PREVIOUS_PR_COMMENTS_DELETION"
64+
AddPrCommentOnSuccessEnv = "JF_PR_ADD_SUCCESS_COMMENT"
6365
FailOnSecurityIssuesEnv = "JF_FAIL"
6466
UseWrapperEnv = "JF_USE_WRAPPER"
6567
DepsRepoEnv = "JF_DEPS_REPO"

utils/params.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type Project struct {
8989
WorkingDirs []string `yaml:"workingDirs,omitempty"`
9090
PathExclusions []string `yaml:"pathExclusions,omitempty"`
9191
UseWrapper *bool `yaml:"useWrapper,omitempty"`
92+
MaxPnpmTreeDepth string `yaml:"maxPnpmTreeDepth,omitempty"`
9293
DepsRepo string `yaml:"repository,omitempty"`
9394
InstallCommandName string
9495
InstallCommandArgs []string
@@ -131,6 +132,10 @@ func (p *Project) setDefaultsIfNeeded() error {
131132
if p.DepsRepo == "" {
132133
p.DepsRepo = getTrimmedEnv(DepsRepoEnv)
133134
}
135+
if p.MaxPnpmTreeDepth == "" {
136+
p.MaxPnpmTreeDepth = getTrimmedEnv(MaxPnpmTreeDepthEnv)
137+
}
138+
134139
return nil
135140
}
136141

@@ -157,6 +162,7 @@ type Scan struct {
157162
AvoidPreviousPrCommentsDeletion bool `yaml:"avoidPreviousPrCommentsDeletion,omitempty"`
158163
MinSeverity string `yaml:"minSeverity,omitempty"`
159164
DisableJas bool `yaml:"disableJas,omitempty"`
165+
AddPrCommentOnSuccess bool `yaml:"addPrCommentOnSuccess,omitempty"`
160166
AllowedLicenses []string `yaml:"allowedLicenses,omitempty"`
161167
Projects []Project `yaml:"projects,omitempty"`
162168
EmailDetails `yaml:",inline"`
@@ -222,6 +228,11 @@ func (s *Scan) setDefaultsIfNeeded() (err error) {
222228
return
223229
}
224230
}
231+
if !s.AddPrCommentOnSuccess {
232+
if s.AddPrCommentOnSuccess, err = getBoolEnv(AddPrCommentOnSuccessEnv, true); err != nil {
233+
return
234+
}
235+
}
225236
if !s.DetectionOnly {
226237
if s.DetectionOnly, err = getBoolEnv(DetectionOnlyEnv, false); err != nil {
227238
return

utils/params_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ func validateBuildRepoAggregator(t *testing.T, repo *Repository, gitParams *Git,
401401
assert.Equal(t, "Medium", repo.MinSeverity)
402402
assert.Equal(t, true, repo.FixableOnly)
403403
assert.Equal(t, true, repo.DisableJas)
404+
assert.Equal(t, true, repo.AddPrCommentOnSuccess)
404405
assert.Equal(t, true, repo.DetectionOnly)
405406
assert.ElementsMatch(t, []string{"MIT", "Apache-2.0"}, repo.AllowedLicenses)
406407
assert.Equal(t, gitParams.RepoOwner, repo.RepoOwner)

utils/scandetails.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (sc *ScanDetails) RunInstallAndAudit(workDirs ...string) (auditResults *res
180180
SetXscVersion(sc.XscVersion).
181181
SetPipRequirementsFile(sc.PipRequirementsFile).
182182
SetUseWrapper(*sc.UseWrapper).
183+
SetMaxTreeDepth(sc.MaxPnpmTreeDepth).
183184
SetDepsRepo(sc.DepsRepo).
184185
SetIgnoreConfigFile(true).
185186
SetServerDetails(sc.ServerDetails).

0 commit comments

Comments
 (0)