Skip to content

Commit

Permalink
PR Scanning - Prevent Frogbot from failing when comment removal fails (
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi authored Oct 19, 2023
1 parent 699aea0 commit 75b2f6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions scanpullrequest/scanpullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func auditPullRequestInProject(repoConfig *utils.Repository, scanDetails *utils.
// Audit source branch
var sourceResults *audit.Results
workingDirs := utils.GetFullPathWorkingDirs(scanDetails.Project.WorkingDirs, sourceBranchWd)
log.Info("Scanning source branch...")
sourceResults, err = scanDetails.RunInstallAndAudit(workingDirs...)
if err != nil {
return
Expand Down Expand Up @@ -199,6 +200,7 @@ func auditTargetBranch(repoConfig *utils.Repository, scanDetails *utils.ScanDeta
// Set target branch scan details
var targetResults *audit.Results
workingDirs := utils.GetFullPathWorkingDirs(scanDetails.Project.WorkingDirs, targetBranchWd)
log.Info("Scanning target branch...")
targetResults, err = scanDetails.RunInstallAndAudit(workingDirs...)
if err != nil {
return
Expand Down
15 changes: 11 additions & 4 deletions utils/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ const (
IacComment ReviewCommentType = "Iac"
SastComment ReviewCommentType = "Sast"

RescanRequestComment = "rescan"
RescanRequestComment = "rescan"
commentRemovalErrorMsg = "An error occurred while attempting to remove older Frogbot pull request comments:"
)

func HandlePullRequestCommentsAfterScan(issues *IssuesCollection, repo *Repository, client vcsclient.VcsClient, pullRequestID int) (err error) {
if !repo.Params.AvoidPreviousPrCommentsDeletion {
// The removal of comments may fail for various reasons,
// such as concurrent scanning of pull requests and attempts
// to delete comments that have already been removed in a different process.
// Since this task is not mandatory for a Frogbot run,
// we will not cause a Frogbot run to fail but will instead log the error.
log.Debug("Looking for an existing Frogbot pull request comment. Deleting it if it exists...")
// Delete previous PR regular comments, if exists (not related to location of a change)
if err = DeleteExistingPullRequestComments(repo, client); err != nil {
err = errors.New("couldn't delete pull request comment: " + err.Error())
log.Error(fmt.Sprintf("%s:\n%v", commentRemovalErrorMsg, err))
return
}
// Delete previous PR review comments, if exists (related to location of a change)
if err = DeleteExistingPullRequestReviewComments(repo, pullRequestID, client); err != nil {
err = errors.New("couldn't delete pull request review comment: " + err.Error())
log.Error(fmt.Sprintf("%s:\n%v", commentRemovalErrorMsg, err))
return
}
}
Expand All @@ -49,9 +55,10 @@ func HandlePullRequestCommentsAfterScan(issues *IssuesCollection, repo *Reposito
err = errors.New("couldn't add pull request comment: " + err.Error())
return
}

// Handle review comments at the pull request
if err = addReviewComments(repo, pullRequestID, client, issues); err != nil {
err = errors.New("couldn't add review comments: " + err.Error())
err = errors.New("couldn't add pull request review comments: " + err.Error())
return
}
return
Expand Down

0 comments on commit 75b2f6e

Please sign in to comment.