Skip to content

Commit 6ef785d

Browse files
committed
Initial implementation of go-git client
Signed-off-by: Azeem Shaikh <[email protected]>
1 parent b5254fe commit 6ef785d

47 files changed

Lines changed: 1490 additions & 1437 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
# Initializes the CodeQL tools for scanning.
6363
- name: Initialize CodeQL
6464

65-
uses: github/codeql-action/init@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v1
65+
uses: github/codeql-action/init@16964e90ba004cdf0cd845b866b5df21038b7723 # v1
6666
with:
6767
languages: ${{ matrix.language }}
6868
queries: +security-extended
@@ -74,7 +74,7 @@ jobs:
7474
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
7575
# If this step fails, then you should remove it and run the build manually (see below)
7676
- name: Autobuild
77-
uses: github/codeql-action/autobuild@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v1
77+
uses: github/codeql-action/autobuild@16964e90ba004cdf0cd845b866b5df21038b7723 # v1
7878

7979
# ℹ️ Command-line programs to run using the OS shell.
8080
# 📚 https://git.io/JvXDl
@@ -88,4 +88,4 @@ jobs:
8888
# make release
8989

9090
- name: Perform CodeQL Analysis
91-
uses: github/codeql-action/analyze@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v1
91+
uses: github/codeql-action/analyze@16964e90ba004cdf0cd845b866b5df21038b7723 # v1

.github/workflows/docker.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
fetch-depth: 2
4242
- id: files
4343
name: Get changed files
44-
uses: tj-actions/changed-files@5ce975c6021a0b11062c547acb6c26c96a34a8c5 #v35.6.2
44+
uses: tj-actions/changed-files@bd376fbcfae914347656e4c70801e2a3fafed05b #v35.7.0
4545
with:
4646
files_ignore: '**.md'
4747
- id: docs_only_check
@@ -70,7 +70,7 @@ jobs:
7070
repo-token: ${{ secrets.GITHUB_TOKEN }}
7171
- name: Cache builds
7272
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
73-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
73+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
7474
with:
7575
# In order:
7676
# * Module download cache
@@ -118,7 +118,7 @@ jobs:
118118
repo-token: ${{ secrets.GITHUB_TOKEN }}
119119
- name: Cache builds
120120
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
121-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
121+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
122122
with:
123123
# In order:
124124
# * Module download cache
@@ -166,7 +166,7 @@ jobs:
166166
repo-token: ${{ secrets.GITHUB_TOKEN }}
167167
- name: Cache builds
168168
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
169-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
169+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
170170
with:
171171
# In order:
172172
# * Module download cache
@@ -214,7 +214,7 @@ jobs:
214214
repo-token: ${{ secrets.GITHUB_TOKEN }}
215215
- name: Cache builds
216216
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
217-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
217+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
218218
with:
219219
# In order:
220220
# * Module download cache
@@ -262,7 +262,7 @@ jobs:
262262
repo-token: ${{ secrets.GITHUB_TOKEN }}
263263
- name: Cache builds
264264
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
265-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
265+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
266266
with:
267267
# In order:
268268
# * Module download cache
@@ -310,7 +310,7 @@ jobs:
310310
repo-token: ${{ secrets.GITHUB_TOKEN }}
311311
- name: Cache builds
312312
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
313-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
313+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
314314
with:
315315
# In order:
316316
# * Module download cache
@@ -358,7 +358,7 @@ jobs:
358358
repo-token: ${{ secrets.GITHUB_TOKEN }}
359359
- name: Cache builds
360360
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
361-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
361+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
362362
with:
363363
# In order:
364364
# * Module download cache

.github/workflows/integration.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ jobs:
7171
with:
7272
files: ./e2e-coverage.out
7373
verbose: true
74+
75+
- name: Run GitLab E2E #using retry because the GitHub token is being throttled.
76+
uses: nick-invision/retry@943e742917ac94714d2f408a0e8320f2d1fcafcd
77+
with:
78+
max_attempts: 3
79+
retry_on: error
80+
timeout_minutes: 30
81+
command: make e2e-gitlab
82+
83+
- name: codecov
84+
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # 2.1.0
85+
with:
86+
files: ./e2e-coverage.out
87+
verbose: true

.github/workflows/main.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
- name: Cache builds
4545
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
46-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 #v3.2.6
46+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
4747
with:
4848
path: |
4949
~/go/pkg/mod
@@ -88,7 +88,7 @@ jobs:
8888
repo-token: ${{ secrets.GITHUB_TOKEN }}
8989
- name: Cache builds
9090
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
91-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
91+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
9292
with:
9393
path: |
9494
~/go/pkg/mod
@@ -136,7 +136,7 @@ jobs:
136136
repo-token: ${{ secrets.GITHUB_TOKEN }}
137137
- name: Cache builds
138138
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
139-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
139+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
140140
with:
141141
path: |
142142
~/go/pkg/mod
@@ -219,7 +219,7 @@ jobs:
219219
repo-token: ${{ secrets.GITHUB_TOKEN }}
220220
- name: Cache builds
221221
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
222-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
222+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
223223
with:
224224
path: |
225225
~/go/pkg/mod
@@ -267,7 +267,7 @@ jobs:
267267
repo-token: ${{ secrets.GITHUB_TOKEN }}
268268
- name: Cache builds
269269
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
270-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
270+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
271271
with:
272272
path: |
273273
~/go/pkg/mod
@@ -315,7 +315,7 @@ jobs:
315315
repo-token: ${{ secrets.GITHUB_TOKEN }}
316316
- name: Cache builds
317317
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
318-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
318+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
319319
with:
320320
path: |
321321
~/go/pkg/mod
@@ -363,7 +363,7 @@ jobs:
363363
repo-token: ${{ secrets.GITHUB_TOKEN }}
364364
- name: Cache builds
365365
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
366-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
366+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
367367
with:
368368
path: |
369369
~/go/pkg/mod
@@ -411,7 +411,7 @@ jobs:
411411
repo-token: ${{ secrets.GITHUB_TOKEN }}
412412
- name: Cache builds
413413
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
414-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
414+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
415415
with:
416416
path: |
417417
~/go/pkg/mod
@@ -459,7 +459,7 @@ jobs:
459459
repo-token: ${{ secrets.GITHUB_TOKEN }}
460460
- name: Cache builds
461461
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
462-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
462+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
463463
with:
464464
path: |
465465
~/go/pkg/mod
@@ -507,7 +507,7 @@ jobs:
507507
repo-token: ${{ secrets.GITHUB_TOKEN }}
508508
- name: Cache builds
509509
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
510-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
510+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
511511
with:
512512
path: |
513513
~/go/pkg/mod
@@ -555,7 +555,7 @@ jobs:
555555
repo-token: ${{ secrets.GITHUB_TOKEN }}
556556
- name: Cache builds
557557
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
558-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
558+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
559559
with:
560560
path: |
561561
~/go/pkg/mod
@@ -603,7 +603,7 @@ jobs:
603603
repo-token: ${{ secrets.GITHUB_TOKEN }}
604604
- name: Cache builds
605605
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
606-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
606+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
607607
with:
608608
path: |
609609
~/go/pkg/mod
@@ -651,7 +651,7 @@ jobs:
651651
repo-token: ${{ secrets.GITHUB_TOKEN }}
652652
- name: Cache builds
653653
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
654-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
654+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
655655
with:
656656
path: |
657657
~/go/pkg/mod
@@ -699,7 +699,7 @@ jobs:
699699
repo-token: ${{ secrets.GITHUB_TOKEN }}
700700
- name: Cache builds
701701
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
702-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
702+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
703703
with:
704704
path: |
705705
~/go/pkg/mod
@@ -771,7 +771,7 @@ jobs:
771771

772772
- name: Cache builds
773773
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
774-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
774+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
775775
with:
776776
path: |
777777
~/go/pkg/mod
@@ -818,7 +818,7 @@ jobs:
818818
repo-token: ${{ secrets.GITHUB_TOKEN }}
819819
- name: Cache builds
820820
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
821-
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
821+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
822822
with:
823823
path: |
824824
~/go/pkg/mod

.github/workflows/scorecard-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ jobs:
4747
retention-days: 5
4848

4949
- name: "Upload SARIF results"
50-
uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v1
50+
uses: github/codeql-action/upload-sarif@16964e90ba004cdf0cd845b866b5df21038b7723 # v1
5151
with:
5252
sarif_file: results.sarif

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ e2e-gh-token: build-scorecard check-env | $(GINKGO)
334334
# Run e2e tests. GITHUB_AUTH_TOKEN set to secrets.GITHUB_TOKEN must be used to run this.
335335
TOKEN_TYPE="GITHUB_TOKEN" $(GINKGO) --race -p -v -cover -coverprofile=e2e-coverage.out --keep-separate-coverprofiles ./...
336336

337+
e2e-gitlab-token: ## Runs e2e tests that require a GITLAB_TOKEN
338+
TOKEN_TYPE="GITLAB_PAT" $(GINKGO) --race -p -vv --focus '.*GitLab Token' ./...
339+
340+
e2e-gitlab: ## Runs e2e tests for GitLab only. TOKEN_TYPE is not used (since these are public APIs), but must be set to something
341+
TOKEN_TYPE="GITLAB_PAT" $(GINKGO) --race -p -vv --focus '.*GitLab' ./...
342+
337343
e2e-attestor: ## Runs e2e tests for scorecard-attestor
338344
cd attestor/e2e; go test -covermode=atomic -coverprofile=e2e-coverage.out; cd ../..
339345

checker/client.go

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ package checker
1717
import (
1818
"context"
1919
"fmt"
20+
"os"
2021

2122
"github.com/ossf/scorecard/v4/clients"
2223
ghrepo "github.com/ossf/scorecard/v4/clients/githubrepo"
24+
glrepo "github.com/ossf/scorecard/v4/clients/gitlabrepo"
2325
"github.com/ossf/scorecard/v4/clients/localdir"
2426
"github.com/ossf/scorecard/v4/clients/ossfuzz"
2527
"github.com/ossf/scorecard/v4/log"
@@ -35,7 +37,9 @@ func GetClients(ctx context.Context, repoURI, localURI string, logger *log.Logge
3537
clients.VulnerabilitiesClient, // vulnClient
3638
error,
3739
) {
38-
var githubRepo clients.Repo
40+
var repo clients.Repo
41+
var makeRepoError error
42+
3943
if localURI != "" {
4044
localRepo, errLocal := localdir.MakeLocalDirRepo(localURI)
4145
var retErr error
@@ -50,18 +54,46 @@ func GetClients(ctx context.Context, repoURI, localURI string, logger *log.Logge
5054
retErr
5155
}
5256

53-
githubRepo, errGitHub := ghrepo.MakeGithubRepo(repoURI)
54-
if errGitHub != nil {
55-
return githubRepo,
56-
nil,
57-
nil,
58-
nil,
59-
nil,
60-
fmt.Errorf("getting local directory client: %w", errGitHub)
57+
_, experimental := os.LookupEnv("SCORECARD_EXPERIMENTAL")
58+
var repoClient clients.RepoClient
59+
60+
//nolint:nestif
61+
if experimental && glrepo.DetectGitLab(repoURI) {
62+
repo, makeRepoError = glrepo.MakeGitlabRepo(repoURI)
63+
if makeRepoError != nil {
64+
return repo,
65+
nil,
66+
nil,
67+
nil,
68+
nil,
69+
fmt.Errorf("getting local directory client: %w", makeRepoError)
70+
}
71+
72+
var err error
73+
repoClient, err = glrepo.CreateGitlabClientWithToken(ctx, os.Getenv("GITLAB_AUTH_TOKEN"), repo)
74+
if err != nil {
75+
return repo,
76+
nil,
77+
nil,
78+
nil,
79+
nil,
80+
fmt.Errorf("error creating gitlab client: %w", err)
81+
}
82+
} else {
83+
repo, makeRepoError = ghrepo.MakeGithubRepo(repoURI)
84+
if makeRepoError != nil {
85+
return repo,
86+
nil,
87+
nil,
88+
nil,
89+
nil,
90+
fmt.Errorf("getting local directory client: %w", makeRepoError)
91+
}
92+
repoClient = ghrepo.CreateGithubRepoClient(ctx, logger)
6193
}
6294

63-
return githubRepo, /*repo*/
64-
ghrepo.CreateGithubRepoClient(ctx, logger), /*repoClient*/
95+
return repo, /*repo*/
96+
repoClient, /*repoClient*/
6597
ossfuzz.CreateOSSFuzzClient(ossfuzz.StatusURL), /*ossFuzzClient*/
6698
clients.DefaultCIIBestPracticesClient(), /*ciiClient*/
6799
clients.DefaultVulnerabilitiesClient(), /*vulnClient*/

0 commit comments

Comments
 (0)