Skip to content

Commit 41b5431

Browse files
authored
Add .git with remote details before clone if needed (#459)
1 parent dcb8fe0 commit 41b5431

File tree

10 files changed

+221
-190
lines changed

10 files changed

+221
-190
lines changed

.frogbot/frogbot-config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
branches:
55
- dev
66
scan:
7+
emailReceivers:
8+
79
projects:
810
- workingDirs:
911
- action

.github/workflows/frogbot-scan-and-fix.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ jobs:
1616
# The repository scanning will be triggered periodically on the following branches.
1717
branch: [ "dev" ]
1818
steps:
19-
- uses: actions/checkout@v3
20-
with:
21-
ref: ${{ matrix.branch }}
2219

2320
# Install prerequisites
2421
- name: Setup Go
@@ -48,6 +45,10 @@ jobs:
4845
# The GitHub token automatically generated for the job
4946
JF_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5047

48+
# [Mandatory]
49+
# The name of the branch on which Frogbot will perform the scan
50+
JF_GIT_BASE_BRANCH: ${{ matrix.branch }}
51+
5152
# [Optional, default: https://api.github.com]
5253
# API endpoint to GitHub
5354
# JF_GIT_API_ENDPOINT: https://github.example.com

.github/workflows/frogbot-scan-pr.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ jobs:
1212
# "frogbot" GitHub environment can approve the pull request to be scanned.
1313
environment: frogbot
1414
steps:
15-
- uses: actions/checkout@v3
16-
with:
17-
ref: ${{ github.event.pull_request.head.sha }}
18-
1915
# Install prerequisites
2016
- name: Setup Go
2117
uses: actions/setup-go@v3
@@ -35,3 +31,9 @@ jobs:
3531
# [Mandatory]
3632
# The GitHub token automatically generated for the job
3733
JF_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
JF_SMTP_SERVER: ${{ secrets.JF_SMTP_SERVER }}
36+
37+
JF_SMTP_PASSWORD: ${{ JF_SMTP_PASSWORD }}
38+
39+
JF_SMTP_USER: ${{ JF_SMTP_USER }}

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ require (
77
github.com/golang/mock v1.6.0
88
github.com/google/go-github/v45 v45.2.0
99
github.com/jfrog/build-info-go v1.9.8
10-
github.com/jfrog/froggit-go v1.13.2
10+
github.com/jfrog/froggit-go v1.13.4
1111
github.com/jfrog/gofrog v1.3.0
12-
github.com/jfrog/jfrog-cli-core/v2 v2.41.1
12+
github.com/jfrog/jfrog-cli-core/v2 v2.41.2
1313
github.com/jfrog/jfrog-client-go v1.31.5
1414
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
1515
github.com/stretchr/testify v1.8.4

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -877,12 +877,12 @@ github.com/jedib0t/go-pretty/v6 v6.4.6 h1:v6aG9h6Uby3IusSSEjHaZNXpHFhzqMmjXcPq1R
877877
github.com/jedib0t/go-pretty/v6 v6.4.6/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
878878
github.com/jfrog/build-info-go v1.9.8 h1:D8/ga+YgQpqp/CJj2zteS4/twmSy8zvm1v9lCd2Kv1M=
879879
github.com/jfrog/build-info-go v1.9.8/go.mod h1:t31QRpH5xUJKw8XkQlAA+Aq7aanyS1rrzpcK8xSNVts=
880-
github.com/jfrog/froggit-go v1.13.2 h1:L71CPAfkjMn/hst9UdMYxSV1yiED0UmCICJsYbziZ6U=
881-
github.com/jfrog/froggit-go v1.13.2/go.mod h1:0jRAaZZusaFFnITosmx6CA60SKryuoaCasJyUrP/c1s=
880+
github.com/jfrog/froggit-go v1.13.4 h1:+pHq3iNkKFvojXCJ74sDV+UsV4Thsi03dsu36jkS7Rc=
881+
github.com/jfrog/froggit-go v1.13.4/go.mod h1:0jRAaZZusaFFnITosmx6CA60SKryuoaCasJyUrP/c1s=
882882
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
883883
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
884-
github.com/jfrog/jfrog-cli-core/v2 v2.41.1 h1:jFRuQdqY3DE1hfy6opzRz5dWrAbYJPN4tFnou794PKE=
885-
github.com/jfrog/jfrog-cli-core/v2 v2.41.1/go.mod h1:YqB9rEJF1P7uGLIPUvF5qdDDf1zM5f4DneIQNkqyAfs=
884+
github.com/jfrog/jfrog-cli-core/v2 v2.41.2 h1:Gnp93JcDAnHHCN3SHqam2K/S9yJcytS4q+MQd6vv9Ck=
885+
github.com/jfrog/jfrog-cli-core/v2 v2.41.2/go.mod h1:YqB9rEJF1P7uGLIPUvF5qdDDf1zM5f4DneIQNkqyAfs=
886886
github.com/jfrog/jfrog-client-go v1.31.5 h1:dYVgIJzMwX+EU9GEELKPSHFLyfW6UrrjZWMEZtAyx6A=
887887
github.com/jfrog/jfrog-client-go v1.31.5/go.mod h1:icb00ZJN/mMMNkQduHDkzpqsXH9Flwi3f3COYexq3Nc=
888888
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=

scanpullrequest/scanpullrequest_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ func createGitLabHandler(t *testing.T, projectName string) http.HandlerFunc {
702702
assert.NoError(t, err)
703703
_, err = w.Write(comments)
704704
assert.NoError(t, err)
705+
case r.RequestURI == fmt.Sprintf("/api/v4/projects/jfrog%s", "%2F"+projectName):
706+
jsonResponse := `{"id": 3,"visibility": "private","ssh_url_to_repo": "[email protected]:diaspora/diaspora-project-site.git","http_url_to_repo": "https://example.com/diaspora/diaspora-project-site.git"}`
707+
_, err := w.Write([]byte(jsonResponse))
708+
assert.NoError(t, err)
705709
}
706710
}
707711
}

scanrepository/scanmultiplerepositories_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ func createScanRepoGitHubHandler(t *testing.T, port *string, response interface{
124124
assert.NoError(t, err)
125125
return
126126
}
127+
if r.RequestURI == fmt.Sprintf("/repos/jfrog/%s", projectName) {
128+
jsonResponse := `{"id": 1296269,"node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5","name": "Hello-World","full_name": "octocat/Hello-World","private": false,"description": "This your first repo!","ssh_url": "[email protected]:octocat/Hello-World.git","clone_url": "https://github.com/octocat/Hello-World.git","visibility": "public"}`
129+
_, err := w.Write([]byte(jsonResponse))
130+
assert.NoError(t, err)
131+
return
132+
}
127133
}
128134
}
129135
}

scanrepository/scanrepository.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (cfp *ScanRepositoryCmd) scanAndFixRepository(repository *utils.Repository,
6565
}
6666

6767
func (cfp *ScanRepositoryCmd) scanAndFixBranch(repository *utils.Repository) (err error) {
68-
clonedRepoDir, restoreBaseDir, err := cfp.cloneRepositoryAndCheckoutToBranch(repository.RepoName)
68+
clonedRepoDir, restoreBaseDir, err := cfp.cloneRepositoryAndCheckoutToBranch()
6969
if err != nil {
7070
return
7171
}
@@ -96,7 +96,19 @@ func (cfp *ScanRepositoryCmd) setCommandPrerequisites(repository *utils.Reposito
9696
SetMinSeverity(repository.MinSeverity)
9797
cfp.aggregateFixes = repository.Git.AggregateFixes
9898
cfp.OutputWriter = outputwriter.GetCompatibleOutputWriter(repository.GitProvider)
99-
cfp.gitManager, err = utils.NewGitManager(cfp.details.Username, cfp.details.Token, cfp.details.Git, cfp.dryRun, cfp.dryRunRepoPath)
99+
repositoryInfo, err := client.GetRepositoryInfo(context.Background(), cfp.details.RepoOwner, cfp.details.RepoName)
100+
if err != nil {
101+
return
102+
}
103+
remoteHttpsGitUrl := repositoryInfo.CloneInfo.HTTP
104+
cfp.gitManager, err = utils.NewGitManager().
105+
SetAuth(cfp.details.Username, cfp.details.Token).
106+
SetDryRun(cfp.dryRun, cfp.dryRunRepoPath).
107+
SetRemoteGitUrl(remoteHttpsGitUrl)
108+
if err != nil {
109+
return
110+
}
111+
_, err = cfp.gitManager.SetGitParams(cfp.details.Git)
100112
return
101113
}
102114

@@ -359,15 +371,14 @@ func (cfp *ScanRepositoryCmd) preparePullRequestDetails(vulnerabilitiesDetails .
359371
return pullRequestTitle, prBody, nil
360372
}
361373

362-
func (cfp *ScanRepositoryCmd) cloneRepositoryAndCheckoutToBranch(repoName string) (tempWd string, restoreDir func() error, err error) {
374+
func (cfp *ScanRepositoryCmd) cloneRepositoryAndCheckoutToBranch() (tempWd string, restoreDir func() error, err error) {
363375
if cfp.dryRun {
364-
tempWd = filepath.Join(cfp.dryRunRepoPath, repoName)
376+
tempWd = filepath.Join(cfp.dryRunRepoPath, cfp.details.RepoName)
365377
} else {
366378
// Create temp working directory
367-
tempWd, err = fileutils.CreateTempDir()
368-
}
369-
if err != nil {
370-
return
379+
if tempWd, err = fileutils.CreateTempDir(); err != nil {
380+
return
381+
}
371382
}
372383
log.Debug("Created temp working directory:", tempWd)
373384

@@ -407,7 +418,9 @@ func (cfp *ScanRepositoryCmd) createVulnerabilitiesMap(scanResults *xrayutils.Ex
407418
}
408419
}
409420
}
410-
log.Debug("Frogbot will attempt to resolve the following vulnerable dependencies:\n", strings.Join(maps.Keys(vulnerabilitiesMap), ",\n"))
421+
if len(vulnerabilitiesMap) > 0 {
422+
log.Debug("Frogbot will attempt to resolve the following vulnerable dependencies:\n", strings.Join(maps.Keys(vulnerabilitiesMap), ",\n"))
423+
}
411424
return vulnerabilitiesMap, nil
412425
}
413426

0 commit comments

Comments
 (0)