@@ -32,6 +32,7 @@ const (
32
32
commentRemovalErrorMsg = "An error occurred while attempting to remove older Frogbot pull request comments:"
33
33
)
34
34
35
+ // In Scan PR, if there is an error, a comment will be added to the PR with the error message.
35
36
func HandlePullRequestErrorComment (issues * issues.ScansIssuesCollection , repo * Repository , client vcsclient.VcsClient , pullRequestID int , scanError error ) (err error ) {
36
37
if issues == nil {
37
38
log .Debug ("Can't generate error comment without issues collection" )
@@ -46,6 +47,7 @@ func HandlePullRequestErrorComment(issues *issues.ScansIssuesCollection, repo *R
46
47
return
47
48
}
48
49
50
+ // In Scan PR, if there are no issues, comments will be added to the PR with a message that there are no issues.
49
51
func HandlePullRequestCommentsAfterScan (issues * issues.ScansIssuesCollection , repo * Repository , client vcsclient.VcsClient , pullRequestID int ) (err error ) {
50
52
if ! repo .Params .AvoidPreviousPrCommentsDeletion {
51
53
// The removal of comments may fail for various reasons,
@@ -91,7 +93,7 @@ func DeleteExistingPullRequestComments(repository *Repository, client vcsclient.
91
93
"failed to get comments. the following details were used in order to fetch the comments: <%s/%s> pull request #%d. the error received: %s" ,
92
94
repository .RepoOwner , repository .RepoName , int (repository .PullRequestDetails .ID ), err .Error ())
93
95
}
94
- commentsToDelete := getFrogbotComments (repository . OutputWriter , comments )
96
+ commentsToDelete := getFrogbotComments (comments )
95
97
// Delete
96
98
if len (commentsToDelete ) > 0 {
97
99
for _ , commentToDelete := range commentsToDelete {
@@ -178,7 +180,7 @@ func addReviewComments(repo *Repository, pullRequestID int, client vcsclient.Vcs
178
180
log .Debug ("creating a review comment for" , comment .Type , comment .Location .File , comment .Location .StartLine , comment .Location .StartColumn )
179
181
if e := client .AddPullRequestReviewComments (context .Background (), repo .RepoOwner , repo .RepoName , pullRequestID , comment .CommentInfo ); e != nil {
180
182
log .Debug ("couldn't add pull request review comment, fallback to regular comment: " + e .Error ())
181
- if err = client .AddPullRequestComment (context .Background (), repo .RepoOwner , repo .RepoName , outputwriter .GetFallbackReviewCommentContent (comment .CommentInfo .Content , comment .Location , repo . OutputWriter ), pullRequestID ); err != nil {
183
+ if err = client .AddPullRequestComment (context .Background (), repo .RepoOwner , repo .RepoName , outputwriter .GetFallbackReviewCommentContent (comment .CommentInfo .Content , comment .Location ), pullRequestID ); err != nil {
182
184
err = errors .New ("couldn't add pull request comment, fallback to comment: " + err .Error ())
183
185
return
184
186
}
@@ -197,15 +199,15 @@ func DeleteExistingPullRequestReviewComments(repo *Repository, pullRequestID int
197
199
}
198
200
// Delete old review comments
199
201
if len (existingComments ) > 0 {
200
- if err = client .DeletePullRequestReviewComments (context .Background (), repo .RepoOwner , repo .RepoName , pullRequestID , getFrogbotComments (repo . OutputWriter , existingComments )... ); err != nil {
202
+ if err = client .DeletePullRequestReviewComments (context .Background (), repo .RepoOwner , repo .RepoName , pullRequestID , getFrogbotComments (existingComments )... ); err != nil {
201
203
err = errors .New ("couldn't delete pull request review comment: " + err .Error ())
202
204
return
203
205
}
204
206
}
205
207
return
206
208
}
207
209
208
- func getFrogbotComments (writer outputwriter. OutputWriter , existingComments []vcsclient.CommentInfo ) (reviewComments []vcsclient.CommentInfo ) {
210
+ func getFrogbotComments (existingComments []vcsclient.CommentInfo ) (reviewComments []vcsclient.CommentInfo ) {
209
211
for _ , comment := range existingComments {
210
212
if outputwriter .IsFrogbotComment (comment .Content ) {
211
213
log .Debug ("Deleting comment id:" , comment .ID )
@@ -278,26 +280,6 @@ func groupSimilarJasIssues(issues []formats.SourceCodeRow) (groupedIssues []simi
278
280
return
279
281
}
280
282
281
- // // We group issues by their watches, so we can add all the watches to the same comment.
282
- // func groupSimilarIssues(issues []formats.SourceCodeRow) (groupedIssues []formats.SourceCodeRow, issuesWatches map[string][]formats.ViolationContext) {
283
- // issuesWatches = make(map[string][]formats.ViolationContext)
284
- // for _, issue := range issues {
285
- // if issue.Watch == "" {
286
- // // no violation context, just add to the list
287
- // groupedIssues = append(groupedIssues, issue)
288
- // continue
289
- // }
290
- // id := getSourceCodeRowId(issue)
291
- // if watches, ok := issuesWatches[id]; ok {
292
- // issuesWatches[id] = append(watches, issue.ViolationContext)
293
- // continue
294
- // }
295
- // groupedIssues = append(groupedIssues, issue)
296
- // issuesWatches[id] = []formats.ViolationContext{issue.ViolationContext}
297
- // }
298
- // return groupedIssues, issuesWatches
299
- // }
300
-
301
283
// We show different comments for each location and rule ID. (we group similar issues/violations to the same comment)
302
284
func getSourceCodeRowId (issue formats.SourceCodeRow ) string {
303
285
return issue .RuleId + issue .Location .ToString ()
@@ -321,18 +303,6 @@ func generateApplicabilityReviewContent(issue issues.ApplicableEvidences, writer
321
303
return outputwriter .GenerateReviewCommentContent (outputwriter .ApplicableCveReviewContent (issue , writer ), writer )
322
304
}
323
305
324
- // func generateSourceCodeVulnerabilityReviewContent(commentType ReviewCommentType, issue formats.SourceCodeRow, writer outputwriter.OutputWriter) (content string) {
325
- // switch commentType {
326
- // case IacComment:
327
- // return outputwriter.GenerateReviewCommentContent(outputwriter.IacReviewContent(issue, writer), writer)
328
- // case SastComment:
329
- // return outputwriter.GenerateReviewCommentContent(outputwriter.SastReviewContent(issue, writer), writer)
330
- // case SecretComment:
331
- // return outputwriter.GenerateReviewCommentContent(outputwriter.SecretReviewContent(issue, writer), writer)
332
- // }
333
- // return
334
- // }
335
-
336
306
func generateSourceCodeReviewContent (commentType ReviewCommentType , violation bool , writer outputwriter.OutputWriter , similarIssues ... formats.SourceCodeRow ) (content string ) {
337
307
switch commentType {
338
308
case IacComment :
0 commit comments