@@ -54,26 +54,24 @@ func (cfp *CreateFixPullRequestsCmd) scanAndFixRepository(repository *utils.Frog
5454 if err != nil {
5555 return err
5656 }
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 )
7068 for _ , fullPathWd := range projectFullPathWorkingDirs {
7169 scanResults , isMultipleRoots , err := cfp .scan (cfp .details , fullPathWd )
7270 if err != nil {
7371 return err
7472 }
7573
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 )
7775 if err != nil {
7876 log .Warn (err )
7977 }
@@ -151,16 +149,15 @@ func (cfp *CreateFixPullRequestsCmd) fixIssuesSeparatePRs(fixVersionsMap map[str
151149 log .Warn (err )
152150 }
153151 // 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 {
156154 return
157155 }
158156 }
159157 return
160158}
161159
162160func (cfp * CreateFixPullRequestsCmd ) fixIssuesSinglePR (fixVersionsMap map [string ]* utils.FixVersionInfo ) (err error ) {
163- successfullyFixedPackages := make (map [string ]* utils.FixVersionInfo )
164161 log .Info ("-----------------------------------------------------------------" )
165162 log .Info ("Start aggregated packages fix" )
166163 aggregatedFixBranchName , err := cfp .gitManager .GenerateAggregatedFixBranchName (fixVersionsMap )
@@ -174,13 +171,10 @@ func (cfp *CreateFixPullRequestsCmd) fixIssuesSinglePR(fixVersionsMap map[string
174171 for impactedPackage , fixVersionInfo := range fixVersionsMap {
175172 if err = cfp .updatePackageToFixedVersion (impactedPackage , fixVersionInfo ); err != nil {
176173 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
180174 }
181175 }
182176
183- if err = cfp .openAggregatedPullRequest (aggregatedFixBranchName , successfullyFixedPackages ); err != nil {
177+ if err = cfp .openAggregatedPullRequest (aggregatedFixBranchName ); err != nil {
184178 return fmt .Errorf ("failed while creating aggreagted pull request. Error: \n %s" , err .Error ())
185179 }
186180 return
@@ -189,7 +183,7 @@ func (cfp *CreateFixPullRequestsCmd) fixIssuesSinglePR(fixVersionsMap map[string
189183func (cfp * CreateFixPullRequestsCmd ) fixSinglePackageAndCreatePR (impactedPackage string , fixVersionInfo * utils.FixVersionInfo ) (err error ) {
190184 log .Info ("-----------------------------------------------------------------" )
191185 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 )
193187 if err != nil {
194188 return
195189 }
@@ -231,14 +225,14 @@ func (cfp *CreateFixPullRequestsCmd) openFixingPullRequest(impactedPackage, fixB
231225 }
232226
233227 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 () )
235229 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 )
237231}
238232
239233// When aggregate mode is active, there can be only one updated pull request to contain all the available fixes.
240234// 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 ) {
242236 log .Info ("Checking if there are changes to commit" )
243237 isClean , err := cfp .gitManager .IsClean ()
244238 if err != nil {
@@ -263,7 +257,7 @@ func (cfp *CreateFixPullRequestsCmd) openAggregatedPullRequest(fixBranchName str
263257 if ! exists {
264258 log .Info ("Creating Pull Request form:" , fixBranchName , " to:" , cfp .details .Branch )
265259 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 )
267261 }
268262 log .Info ("Pull Request branch:" , fixBranchName , "has been updated" )
269263 return
@@ -290,8 +284,7 @@ func (cfp *CreateFixPullRequestsCmd) cloneRepository() (tempWd string, restoreDi
290284 log .Debug ("Created temp working directory:" , tempWd )
291285
292286 // 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 {
295288 return
296289 }
297290
0 commit comments