Skip to content

Commit 3e8b0c6

Browse files
committed
start clean
1 parent d37e974 commit 3e8b0c6

File tree

9 files changed

+19
-179
lines changed

9 files changed

+19
-179
lines changed

go.mod

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,8 @@ require (
121121
)
122122

123123
// eranturgeman:jas-violations-support
124-
replace github.com/jfrog/jfrog-cli-security => ../jfrog-cli-security
125-
126-
// replace github.com/jfrog/jfrog-cli-security => github.com/eranturgeman/jfrog-cli-security v0.0.0-20241204143029-e901cd468c75
127-
128-
// replace github.com/jfrog/jfrog-cli-security => github.com/eranturgeman/jfrog-cli-security v0.0.0-20241124185605-a69b532152fc
124+
// replace github.com/jfrog/jfrog-cli-security => ../jfrog-cli-security
125+
replace github.com/jfrog/jfrog-cli-security => github.com/eranturgeman/jfrog-cli-security v0.0.0-20241211070414-848d30bb3042
129126

130127
// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 dev
131128

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcej
5959
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
6060
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
6161
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
62+
github.com/eranturgeman/jfrog-cli-security v0.0.0-20241211070414-848d30bb3042 h1:0jz+yrWt4B5oS1jGMU78qgywpOr+Is4cLkGCZjlzpQ8=
63+
github.com/eranturgeman/jfrog-cli-security v0.0.0-20241211070414-848d30bb3042/go.mod h1:c4GycFVqXqYOjI/1FdJ1lUf//kqQBGEzds1iSn73OaM=
6264
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
6365
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
6466
github.com/forPelevin/gomoji v1.2.0 h1:9k4WVSSkE1ARO/BWywxgEUBvR/jMnao6EZzrql5nxJ8=

scanpullrequest/scanpullrequest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (cmd *ScanPullRequestCmd) Run(configAggregator utils.RepoAggregator, client
4141
return
4242
}
4343
}
44-
repoConfig.OutputWriter.SetHasInternetConnection( /*false*/ frogbotRepoConnection.IsConnected())
44+
repoConfig.OutputWriter.SetHasInternetConnection(frogbotRepoConnection.IsConnected())
4545
if repoConfig.PullRequestDetails, err = client.GetPullRequestByID(context.Background(), repoConfig.RepoOwner, repoConfig.RepoName, int(repoConfig.PullRequestDetails.ID)); err != nil {
4646
return
4747
}
@@ -310,7 +310,7 @@ func checkoutToCommitAtTempWorkingDir(scanDetails *utils.ScanDetails, commitHash
310310
}
311311

312312
func getAllIssues(cmdResults *results.SecurityCommandResults, allowedLicenses []string, includeVulnerabilities, hasViolationContext bool) (*issues.ScansIssuesCollection, error) {
313-
log.Info("Frogbot is configured to show all vulnerabilities")
313+
log.Info("Frogbot is configured to show all issues")
314314
simpleJsonResults, err := conversion.NewCommandResultsConvertor(conversion.ResultConvertParams{
315315
IncludeVulnerabilities: includeVulnerabilities,
316316
HasViolationContext: hasViolationContext,

utils/comment.go

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
commentRemovalErrorMsg = "An error occurred while attempting to remove older Frogbot pull request comments:"
3333
)
3434

35+
// In Scan PR, if there is an error, a comment will be added to the PR with the error message.
3536
func HandlePullRequestErrorComment(issues *issues.ScansIssuesCollection, repo *Repository, client vcsclient.VcsClient, pullRequestID int, scanError error) (err error) {
3637
if issues == nil {
3738
log.Debug("Can't generate error comment without issues collection")
@@ -46,6 +47,7 @@ func HandlePullRequestErrorComment(issues *issues.ScansIssuesCollection, repo *R
4647
return
4748
}
4849

50+
// In Scan PR, if there are no issues, comments will be added to the PR with a message that there are no issues.
4951
func HandlePullRequestCommentsAfterScan(issues *issues.ScansIssuesCollection, repo *Repository, client vcsclient.VcsClient, pullRequestID int) (err error) {
5052
if !repo.Params.AvoidPreviousPrCommentsDeletion {
5153
// The removal of comments may fail for various reasons,
@@ -91,7 +93,7 @@ func DeleteExistingPullRequestComments(repository *Repository, client vcsclient.
9193
"failed to get comments. the following details were used in order to fetch the comments: <%s/%s> pull request #%d. the error received: %s",
9294
repository.RepoOwner, repository.RepoName, int(repository.PullRequestDetails.ID), err.Error())
9395
}
94-
commentsToDelete := getFrogbotComments(repository.OutputWriter, comments)
96+
commentsToDelete := getFrogbotComments(comments)
9597
// Delete
9698
if len(commentsToDelete) > 0 {
9799
for _, commentToDelete := range commentsToDelete {
@@ -178,7 +180,7 @@ func addReviewComments(repo *Repository, pullRequestID int, client vcsclient.Vcs
178180
log.Debug("creating a review comment for", comment.Type, comment.Location.File, comment.Location.StartLine, comment.Location.StartColumn)
179181
if e := client.AddPullRequestReviewComments(context.Background(), repo.RepoOwner, repo.RepoName, pullRequestID, comment.CommentInfo); e != nil {
180182
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 {
182184
err = errors.New("couldn't add pull request comment, fallback to comment: " + err.Error())
183185
return
184186
}
@@ -197,15 +199,15 @@ func DeleteExistingPullRequestReviewComments(repo *Repository, pullRequestID int
197199
}
198200
// Delete old review comments
199201
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 {
201203
err = errors.New("couldn't delete pull request review comment: " + err.Error())
202204
return
203205
}
204206
}
205207
return
206208
}
207209

208-
func getFrogbotComments(writer outputwriter.OutputWriter, existingComments []vcsclient.CommentInfo) (reviewComments []vcsclient.CommentInfo) {
210+
func getFrogbotComments(existingComments []vcsclient.CommentInfo) (reviewComments []vcsclient.CommentInfo) {
209211
for _, comment := range existingComments {
210212
if outputwriter.IsFrogbotComment(comment.Content) {
211213
log.Debug("Deleting comment id:", comment.ID)
@@ -278,26 +280,6 @@ func groupSimilarJasIssues(issues []formats.SourceCodeRow) (groupedIssues []simi
278280
return
279281
}
280282

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-
301283
// We show different comments for each location and rule ID. (we group similar issues/violations to the same comment)
302284
func getSourceCodeRowId(issue formats.SourceCodeRow) string {
303285
return issue.RuleId + issue.Location.ToString()
@@ -321,18 +303,6 @@ func generateApplicabilityReviewContent(issue issues.ApplicableEvidences, writer
321303
return outputwriter.GenerateReviewCommentContent(outputwriter.ApplicableCveReviewContent(issue, writer), writer)
322304
}
323305

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-
336306
func generateSourceCodeReviewContent(commentType ReviewCommentType, violation bool, writer outputwriter.OutputWriter, similarIssues ...formats.SourceCodeRow) (content string) {
337307
switch commentType {
338308
case IacComment:

utils/comment_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
)
1313

1414
func TestGetFrogbotReviewComments(t *testing.T) {
15-
writer := &outputwriter.StandardOutput{}
1615
testCases := []struct {
1716
name string
1817
existingComments []vcsclient.CommentInfo
@@ -44,7 +43,7 @@ func TestGetFrogbotReviewComments(t *testing.T) {
4443
}
4544
for _, tc := range testCases {
4645
t.Run(tc.name, func(t *testing.T) {
47-
output := getFrogbotComments(writer, tc.existingComments)
46+
output := getFrogbotComments(tc.existingComments)
4847
assert.ElementsMatch(t, tc.expectedOutput, output)
4948
})
5049
}
@@ -205,8 +204,6 @@ func TestGroupSimilarJasIssues(t *testing.T) {
205204

206205
func TestGetNewReviewComments(t *testing.T) {
207206
writer := &outputwriter.StandardOutput{}
208-
209-
// repo := &Repository{OutputWriter: &outputwriter.StandardOutput{}}
210207
testCases := []struct {
211208
name string
212209
generateSecretsComments bool

utils/issues/issuescollection.go

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/jfrog/jfrog-cli-security/utils/severityutils"
99
)
1010

11-
// TODO: after refactor, move this to security-cli as a new formats or remove this and use the existing formats
1211
// Group issues by scan type
1312
type ScansIssuesCollection struct {
1413
formats.ScanStatus
@@ -264,60 +263,6 @@ func (ic *ScansIssuesCollection) GetApplicableEvidences() (evidences []Applicabl
264263
evidences = append(evidences, evidence)
265264
}
266265
return
267-
268-
// issueIdToApplicableInfo := map[string]formats.Applicability{}
269-
// issueIdToIssue := map[string]formats.VulnerabilityOrViolationRow{}
270-
// // Collect evidences from Violations
271-
// for _, securityViolation := range ic.ScaViolations {
272-
// issueId := results.GetIssueIdentifier(securityViolation.Cves, securityViolation.IssueId, "-")
273-
// if _, exists := issueIdToIssue[issueId]; exists {
274-
// // No need to add the same issue twice
275-
// continue
276-
// }
277-
// for _, cve := range securityViolation.Cves {
278-
// if cve.Applicability != nil && cve.Applicability.Status == jasutils.Applicable.String() {
279-
// // We only want applicable issues
280-
// issueIdToIssue[issueId] = securityViolation
281-
// issueIdToApplicableInfo[issueId] = *cve.Applicability
282-
// }
283-
// }
284-
// }
285-
// // Collect evidences from Vulnerabilities
286-
// for _, vulnerability := range ic.ScaVulnerabilities {
287-
// issueId := results.GetIssueIdentifier(vulnerability.Cves, vulnerability.IssueId, "-")
288-
// if _, exists := issueIdToIssue[issueId]; exists {
289-
// // No need to add the same issue twice
290-
// continue
291-
// }
292-
// for _, cve := range vulnerability.Cves {
293-
// if cve.Applicability != nil && cve.Applicability.Status == jasutils.Applicable.String() {
294-
// // We only want applicable issues
295-
// issueIdToIssue[issueId] = vulnerability
296-
// issueIdToApplicableInfo[issueId] = *cve.Applicability
297-
// }
298-
// }
299-
// }
300-
// // Create ApplicableEvidences from collected data
301-
// for issueId := range maps.Keys(issueIdToApplicableInfo) {
302-
// issue := issueIdToIssue[issueId]
303-
// applicableInfo := issueIdToApplicableInfo[issueId]
304-
// remediation := ""
305-
// if issue.JfrogResearchInformation != nil {
306-
// remediation = issue.JfrogResearchInformation.Remediation
307-
// }
308-
// for _, evidence := range applicableInfo.Evidence {
309-
// evidences = append(evidences, ApplicableEvidences{
310-
// Evidence: evidence,
311-
// Severity: issue.Severity,
312-
// ScannerDescription: applicableInfo.ScannerDescription,
313-
// IssueId: results.GetIssueIdentifier(issue.Cves, issue.IssueId, ","),
314-
// CveSummary: issue.Summary,
315-
// ImpactedDependency: results.GetDependencyId(issue.ImpactedDependencyName, issue.ImpactedDependencyVersion),
316-
// Remediation: remediation,
317-
// })
318-
// }
319-
// }
320-
// return
321266
}
322267

323268
// Violations
@@ -343,68 +288,3 @@ func (ic *ScansIssuesCollection) GetTotalVulnerabilities(includeSecrets bool) in
343288
}
344289
return total
345290
}
346-
347-
// func (ic *ScansIssuesCollection) GetTotal()
348-
349-
// ---------------------------------------
350-
351-
// func (ic *ScansIssuesCollection) GetScaIssues() (unique []formats.VulnerabilityOrViolationRow) {
352-
// return append(ic.ScaVulnerabilities, ic.ScaViolations...)
353-
// }
354-
355-
// func (ic *ScansIssuesCollection) GetUniqueIacIssues() (unique []formats.SourceCodeRow) {
356-
// return getUniqueJasIssues(ic.IacVulnerabilities, ic.IacViolations)
357-
// }
358-
359-
// func (ic *ScansIssuesCollection) GetUniqueSecretsIssues() (unique []formats.SourceCodeRow) {
360-
// return getUniqueJasIssues(ic.SecretsVulnerabilities, ic.SecretsViolations)
361-
// }
362-
363-
// func (ic *ScansIssuesCollection) GetUniqueSastIssues() (unique []formats.SourceCodeRow) {
364-
// return getUniqueJasIssues(ic.SastVulnerabilities, ic.SastViolations)
365-
// }
366-
367-
// func getUniqueJasIssues(vulnerabilities, violations []formats.SourceCodeRow) (unique []formats.SourceCodeRow) {
368-
// parsedIssues := datastructures.MakeSet[string]()
369-
// for _, violation := range violations {
370-
// issueId := violation.Location.ToString() + "|" + violation.Finding
371-
// if parsedIssues.Exists(issueId) {
372-
// continue
373-
// }
374-
// parsedIssues.Add(issueId)
375-
// unique = append(unique, violation)
376-
// }
377-
// for _, vulnerability := range vulnerabilities {
378-
// issueId := vulnerability.Location.ToString() + "|" + vulnerability.Finding
379-
// if parsedIssues.Exists(issueId) {
380-
// continue
381-
// }
382-
// parsedIssues.Add(issueId)
383-
// unique = append(unique, vulnerability)
384-
// }
385-
// return
386-
// }
387-
388-
// func (ic *ScansIssuesCollection) LicensesViolationsExists() bool {
389-
// return len(ic.LicensesViolations) > 0
390-
// }
391-
392-
// func (ic *ScansIssuesCollection) PresentableIssuesExists() bool {
393-
// return ic.ScaIssuesExists() || ic.IacIssuesExists() || ic.LicensesViolationsExists() || ic.SastIssuesExists()
394-
// }
395-
396-
// func (ic *ScansIssuesCollection) ViolationsExists() bool {
397-
// return len(ic.ScaViolations) > 0 || len(ic.IacViolations) > 0 || len(ic.SecretsViolations) > 0 || len(ic.SastViolations) > 0 || len(ic.LicensesViolations) > 0
398-
// }
399-
400-
// func (ic *ScansIssuesCollection) CountIssuesCollectionFindings() int {
401-
// count := 0
402-
403-
// count += len(ic.GetScaIssues())
404-
// count += len(ic.GetUniqueIacIssues())
405-
// count += len(ic.GetUniqueSecretsIssues())
406-
// count += len(ic.GetUniqueSastIssues())
407-
// count += len(ic.LicensesViolations)
408-
409-
// return count
410-
// }

utils/outputwriter/markdowntable.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import (
66
)
77

88
const (
9-
10-
// tableRowFirstColumnSeparator = "| :---------------------: |"
11-
// tableRowColumnSeparator = " :-----------------------------------: |"
12-
// cellFirstCellPlaceholder = "| %s |"
13-
// cellCellPlaceholder = " %s |"
14-
159
cellDefaultValue = "-"
1610

1711
firstCellPlaceholder = "| %s |"

utils/outputwriter/outputcontent.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func GenerateReviewCommentContent(content string, writer OutputWriter) string {
6363
}
6464

6565
// When can't create review comment, create a fallback comment by adding the location description to the content as a prefix
66-
func GetFallbackReviewCommentContent(content string, location formats.Location, writer OutputWriter) string {
66+
func GetFallbackReviewCommentContent(content string, location formats.Location) string {
6767
var contentBuilder strings.Builder
6868
contentBuilder.WriteString(MarkdownComment(ReviewCommentId))
6969
WriteContent(&contentBuilder, getFallbackCommentLocationDescription(location), content)
@@ -293,7 +293,7 @@ func PolicyViolationsContent(issues issues.ScansIssuesCollection, writer OutputW
293293
return ConvertContentToComments(policyViolationContent, writer, getDecoratorWithPolicyViolationTitle(writer))
294294
}
295295

296-
func getDecoratorWithPolicyViolationTitle(writer OutputWriter) func(int, string) string {
296+
func getDecoratorWithPolicyViolationTitle(writer OutputWriter) CommentDecorator {
297297
return func(commentCount int, content string) string {
298298
contentBuilder := strings.Builder{}
299299
// Decorate each part of the split content with a title as prefix and return the content
@@ -314,7 +314,7 @@ func getSecurityViolationsContent(issues issues.ScansIssuesCollection, writer Ou
314314
return ConvertContentToComments(content, writer, getDecoratorWithSecurityViolationTitle(writer))
315315
}
316316

317-
func getDecoratorWithSecurityViolationTitle(writer OutputWriter) func(int, string) string {
317+
func getDecoratorWithSecurityViolationTitle(writer OutputWriter) CommentDecorator {
318318
return func(commentCount int, content string) string {
319319
contentBuilder := strings.Builder{}
320320
// Decorate each part of the split content with a title as prefix and return the content
@@ -364,7 +364,7 @@ func getLicenseViolationsContent(issues issues.ScansIssuesCollection, writer Out
364364
return ConvertContentToComments(content, writer, getDecoratorWithLicenseViolationTitle(writer))
365365
}
366366

367-
func getDecoratorWithLicenseViolationTitle(writer OutputWriter) func(int, string) string {
367+
func getDecoratorWithLicenseViolationTitle(writer OutputWriter) CommentDecorator {
368368
return func(commentCount int, content string) string {
369369
contentBuilder := strings.Builder{}
370370
// Decorate each part of the split content with a title as prefix and return the content
@@ -450,7 +450,7 @@ func GetVulnerabilitiesContent(vulnerabilities []formats.VulnerabilityOrViolatio
450450
return ConvertContentToComments(content, writer, getDecoratorWithScaVulnerabilitiesTitle(writer))
451451
}
452452

453-
func getDecoratorWithScaVulnerabilitiesTitle(writer OutputWriter) func(int, string) string {
453+
func getDecoratorWithScaVulnerabilitiesTitle(writer OutputWriter) CommentDecorator {
454454
return func(commentCount int, content string) string {
455455
contentBuilder := strings.Builder{}
456456
// Decorate each part of the split content with a title as prefix and return the content

utils/outputwriter/outputcontent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func TestGenerateReviewComment(t *testing.T) {
810810
expectedOutput := GetExpectedTestOutput(t, test)
811811
output := GenerateReviewCommentContent(content, test.writer)
812812
if tc.location != nil {
813-
output = GetFallbackReviewCommentContent(content, *tc.location, test.writer)
813+
output = GetFallbackReviewCommentContent(content, *tc.location)
814814
}
815815
assert.Equal(t, expectedOutput, output)
816816
})

0 commit comments

Comments
 (0)