@@ -54,26 +54,24 @@ func (cfp *CreateFixPullRequestsCmd) scanAndFixRepository(repository *utils.Frog
54
54
if err != nil {
55
55
return err
56
56
}
57
- cfp .details = & utils.ScanDetails {
58
- XrayGraphScanParams : createXrayScanParams (repository .Watches , repository .JFrogProjectKey ),
59
- ServerDetails : & repository .Server ,
60
- Git : & repository .Git ,
61
- Client : client ,
62
- FailOnInstallationErrors : * repository .FailOnSecurityIssues ,
63
- Branch : branch ,
64
- ReleasesRepo : repository .JfrogReleasesRepo ,
65
- }
66
- for _ , project := range repository .Projects {
67
- cfp .details .Project = project
68
- cfp .aggregateFixes = repository .Git .AggregateFixes
69
- projectFullPathWorkingDirs := getFullPathWorkingDirs (project .WorkingDirs , baseWd )
57
+ cfp .details = utils .NewScanDetails (client , & repository .Server , & repository .Git ).
58
+ SetXrayGraphScanParams (repository .Watches , repository .JFrogProjectKey ).
59
+ SetFailOnInstallationErrors (* repository .FailOnSecurityIssues ).
60
+ SetBranch (branch ).
61
+ SetReleasesRepo (repository .JfrogReleasesRepo ).
62
+ SetFixableOnly (repository .FixableOnly ).
63
+ SetMinSeverity (repository .MinSeverity )
64
+ cfp .aggregateFixes = repository .Git .AggregateFixes
65
+ for i := range repository .Projects {
66
+ cfp .details .Project = & repository .Projects [i ]
67
+ projectFullPathWorkingDirs := getFullPathWorkingDirs (cfp .details .Project .WorkingDirs , baseWd )
70
68
for _ , fullPathWd := range projectFullPathWorkingDirs {
71
69
scanResults , isMultipleRoots , err := cfp .scan (cfp .details , fullPathWd )
72
70
if err != nil {
73
71
return err
74
72
}
75
73
76
- err = utils .UploadScanToGitProvider (scanResults , repository , cfp .details .Branch , cfp .details .Client , isMultipleRoots )
74
+ err = utils .UploadScanToGitProvider (scanResults , repository , cfp .details .Branch () , cfp .details .Client () , isMultipleRoots )
77
75
if err != nil {
78
76
log .Warn (err )
79
77
}
@@ -151,16 +149,15 @@ func (cfp *CreateFixPullRequestsCmd) fixIssuesSeparatePRs(fixVersionsMap map[str
151
149
log .Warn (err )
152
150
}
153
151
// After finishing to work on the current vulnerability, we go back to the base branch to start the next vulnerability fix
154
- log .Info ("Running git checkout to base branch:" , cfp .details .Branch )
155
- if err = cfp .gitManager .Checkout (cfp .details .Branch ); err != nil {
152
+ log .Info ("Running git checkout to base branch:" , cfp .details .Branch () )
153
+ if err = cfp .gitManager .Checkout (cfp .details .Branch () ); err != nil {
156
154
return
157
155
}
158
156
}
159
157
return
160
158
}
161
159
162
160
func (cfp * CreateFixPullRequestsCmd ) fixIssuesSinglePR (fixVersionsMap map [string ]* utils.FixVersionInfo ) (err error ) {
163
- successfullyFixedPackages := make (map [string ]* utils.FixVersionInfo )
164
161
log .Info ("-----------------------------------------------------------------" )
165
162
log .Info ("Start aggregated packages fix" )
166
163
aggregatedFixBranchName , err := cfp .gitManager .GenerateAggregatedFixBranchName (fixVersionsMap )
@@ -174,13 +171,10 @@ func (cfp *CreateFixPullRequestsCmd) fixIssuesSinglePR(fixVersionsMap map[string
174
171
for impactedPackage , fixVersionInfo := range fixVersionsMap {
175
172
if err = cfp .updatePackageToFixedVersion (impactedPackage , fixVersionInfo ); err != nil {
176
173
log .Error ("Could not fix impacted package" , impactedPackage , "as part of the PR. Skipping it. Cause:" , err .Error ())
177
- } else {
178
- log .Info ("Successfully fixed" , impactedPackage )
179
- successfullyFixedPackages [impactedPackage ] = fixVersionInfo
180
174
}
181
175
}
182
176
183
- if err = cfp .openAggregatedPullRequest (aggregatedFixBranchName , successfullyFixedPackages ); err != nil {
177
+ if err = cfp .openAggregatedPullRequest (aggregatedFixBranchName ); err != nil {
184
178
return fmt .Errorf ("failed while creating aggreagted pull request. Error: \n %s" , err .Error ())
185
179
}
186
180
return
@@ -189,7 +183,7 @@ func (cfp *CreateFixPullRequestsCmd) fixIssuesSinglePR(fixVersionsMap map[string
189
183
func (cfp * CreateFixPullRequestsCmd ) fixSinglePackageAndCreatePR (impactedPackage string , fixVersionInfo * utils.FixVersionInfo ) (err error ) {
190
184
log .Info ("-----------------------------------------------------------------" )
191
185
log .Info ("Start fixing" , impactedPackage , "with" , fixVersionInfo .FixVersion )
192
- fixBranchName , err := cfp .gitManager .GenerateFixBranchName (cfp .details .Branch , impactedPackage , fixVersionInfo .FixVersion )
186
+ fixBranchName , err := cfp .gitManager .GenerateFixBranchName (cfp .details .Branch () , impactedPackage , fixVersionInfo .FixVersion )
193
187
if err != nil {
194
188
return
195
189
}
@@ -231,14 +225,14 @@ func (cfp *CreateFixPullRequestsCmd) openFixingPullRequest(impactedPackage, fixB
231
225
}
232
226
233
227
pullRequestTitle := cfp .gitManager .GeneratePullRequestTitle (impactedPackage , fixVersionInfo .FixVersion )
234
- log .Info ("Creating Pull Request form:" , fixBranchName , " to:" , cfp .details .Branch )
228
+ log .Info ("Creating Pull Request form:" , fixBranchName , " to:" , cfp .details .Branch () )
235
229
prBody := commitMessage + "\n \n " + utils .WhatIsFrogbotMd
236
- return cfp .details .Client .CreatePullRequest (context .Background (), cfp .details .RepoOwner , cfp .details .RepoName , fixBranchName , cfp .details .Branch , pullRequestTitle , prBody )
230
+ return cfp .details .Client () .CreatePullRequest (context .Background (), cfp .details .RepoOwner , cfp .details .RepoName , fixBranchName , cfp .details .Branch () , pullRequestTitle , prBody )
237
231
}
238
232
239
233
// When aggregate mode is active, there can be only one updated pull request to contain all the available fixes.
240
234
// In case of an already opened pull request, Frogbot will only update the branch.
241
- func (cfp * CreateFixPullRequestsCmd ) openAggregatedPullRequest (fixBranchName string , versionsMap map [ string ] * utils. FixVersionInfo ) (err error ) {
235
+ func (cfp * CreateFixPullRequestsCmd ) openAggregatedPullRequest (fixBranchName string ) (err error ) {
242
236
log .Info ("Checking if there are changes to commit" )
243
237
isClean , err := cfp .gitManager .IsClean ()
244
238
if err != nil {
@@ -263,7 +257,7 @@ func (cfp *CreateFixPullRequestsCmd) openAggregatedPullRequest(fixBranchName str
263
257
if ! exists {
264
258
log .Info ("Creating Pull Request form:" , fixBranchName , " to:" , cfp .details .Branch )
265
259
prBody := commitMessage + "\n \n " + utils .WhatIsFrogbotMd
266
- return cfp .details .Client .CreatePullRequest (context .Background (), cfp .details .RepoOwner , cfp .details .RepoName , fixBranchName , cfp .details .Branch , utils .AggregatedPullRequestTitleTemplate , prBody )
260
+ return cfp .details .Client () .CreatePullRequest (context .Background (), cfp .details .RepoOwner , cfp .details .RepoName , fixBranchName , cfp .details .Branch () , utils .AggregatedPullRequestTitleTemplate , prBody )
267
261
}
268
262
log .Info ("Pull Request branch:" , fixBranchName , "has been updated" )
269
263
return
@@ -290,8 +284,7 @@ func (cfp *CreateFixPullRequestsCmd) cloneRepository() (tempWd string, restoreDi
290
284
log .Debug ("Created temp working directory:" , tempWd )
291
285
292
286
// Clone the content of the repo to the new working directory
293
- err = cfp .gitManager .Clone (tempWd , cfp .details .Branch )
294
- if err != nil {
287
+ if err = cfp .gitManager .Clone (tempWd , cfp .details .Branch ()); err != nil {
295
288
return
296
289
}
297
290
0 commit comments