Skip to content

Commit

Permalink
Merge branch 'main' into gitlab_tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Wert <[email protected]>
  • Loading branch information
N8BWert authored Sep 21, 2022
2 parents 8519ac4 + 0f87094 commit 6952c0d
Show file tree
Hide file tree
Showing 30 changed files with 265 additions and 308 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/depsreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- name: 'Checkout Repository'
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- name: 'Dependency Review'
uses: actions/dependency-review-action@23d1ffffb6fa5401173051ec21eba8c35242733f
uses: actions/dependency-review-action@2b96ea7f03d82de498e97b42e6bee3f7cb0dafaa
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
Expand Down Expand Up @@ -50,17 +49,13 @@ linters:
- misspell
- nakedret
- nestif
- noctx
- nolintlint
- paralleltest
- predeclared
- staticcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
Expand Down
2 changes: 2 additions & 0 deletions checker/check_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
)

// CheckResult captures result from a check run.
//
//nolint:govet
type CheckResult struct {
Name string
Expand Down Expand Up @@ -94,6 +95,7 @@ type CheckDetail struct {

// LogMessage is a structure that encapsulates detail's information.
// This allows updating the definition easily.
//
//nolint:govet
type LogMessage struct {
Text string // A short string explaining why the detail was recorded/logged.
Expand Down
1 change: 1 addition & 0 deletions checks/fileparser/listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ func TestOnMatchingFileContent(t *testing.T) {
}

// TestOnAllFilesDo tests the OnAllFilesDo function.
//
//nolint:gocognit
func TestOnAllFilesDo(t *testing.T) {
t.Parallel()
Expand Down
2 changes: 1 addition & 1 deletion checks/raw/branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
mainBranchName = "main"
)

//nolint: govet
// nolint: govet
type branchArg struct {
err error
name string
Expand Down
1 change: 1 addition & 0 deletions checks/raw/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestLicenseFileCheck(t *testing.T) {
},
}

//nolint: paralleltest
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
for _, ext := range tt.extensions {
Expand Down
2 changes: 1 addition & 1 deletion checks/raw/shell_download_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func validateShellFileAndRecord(pathfn string, startLine, endLine uint, content
// TODO: support other interpreters.
// Example: https://github.com/apache/airflow/blob/main/scripts/ci/kubernetes/ci_run_kubernetes_tests.sh#L75
// HOST_PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info[0]}.{sys.version_info[1]}")')``
// nolinter
// nolint
if ok && isShellInterpreterOrCommand([]string{i}) {
start, end := getLine(startLine, endLine, node)
e := validateShellFileAndRecord(pathfn, start, end,
Expand Down
3 changes: 3 additions & 0 deletions clients/githubrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func CreateGithubRepoClientWithTransport(ctx context.Context, rt http.RoundTripp
languages: &languagesHandler{
ghclient: client,
},
tarball: tarballHandler{
httpClient: httpClient,
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion clients/githubrepo/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func parseCheckRuns(data *checkRunsGraphqlData) checkRunCache {
return checkCache
}

//nolint:all
//nolint
func commitsFrom(data *graphqlData, repoOwner, repoName string) ([]clients.Commit, error) {
ret := make([]clients.Commit, 0)
for _, commit := range data.Repository.Object.Commit.History.Nodes {
Expand Down
1 change: 1 addition & 0 deletions clients/githubrepo/roundtripper/tokens/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func main() {
panic(err)
}

//nolint: gosec // internal server.
if err := http.Serve(l, nil); err != nil {
panic(err)
}
Expand Down
7 changes: 4 additions & 3 deletions clients/githubrepo/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type tarballHandler struct {
once *sync.Once
ctx context.Context
repo *github.Repository
httpClient *http.Client
commitSHA string
tempDir string
tempTarFile string
Expand Down Expand Up @@ -122,9 +123,9 @@ func (handler *tarballHandler) getTarball() error {
if err != nil {
return fmt.Errorf("http.NewRequestWithContext: %w", err)
}
resp, err := http.DefaultClient.Do(req)
resp, err := handler.httpClient.Do(req)
if err != nil {
return fmt.Errorf("http.DefaultClient.Do: %w", err)
return fmt.Errorf("handler.httpClient.Do: %w", err)
}
defer resp.Body.Close()

Expand Down Expand Up @@ -154,7 +155,7 @@ func (handler *tarballHandler) getTarball() error {
return nil
}

//nolint: gocognit
// nolint: gocognit
func (handler *tarballHandler) extractTarball() error {
in, err := os.OpenFile(handler.tempTarFile, os.O_RDONLY, 0o644)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion clients/githubrepo/tarball_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func setup(inputFile string) (tarballHandler, error) {
return tarballHandler, nil
}

//nolint: gocognit
// nolint: gocognit
func TestExtractTarball(t *testing.T) {
t.Parallel()
testcases := []struct {
Expand Down
11 changes: 6 additions & 5 deletions clients/gitlabrepo/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (handler *branchesHandler) init(repourl *repoURL) {
handler.once = new(sync.Once)
}


// nolint: nestif
func (handler *branchesHandler) setup() error {
handler.once.Do(func() {
if !strings.EqualFold(handler.repourl.commitSHA, clients.HeadSHA) {
Expand Down Expand Up @@ -75,6 +77,7 @@ func (handler *branchesHandler) setup() error {

projectStatusChecks, resp, err := handler.glClient.ExternalStatusChecks.ListProjectStatusChecks(
handler.repourl.projectID, &gitlab.ListOptions{})

if err != nil && resp.StatusCode != 404 && resp.StatusCode != 401 {
handler.errSetup = fmt.Errorf("request for external status checks failed with error %w", err)
return
Expand Down Expand Up @@ -179,7 +182,6 @@ func (handler *branchesHandler) getBranch(commitOrBranch string) (*clients.Branc
return nil, fmt.Errorf("could not obtain the branch: %w", err)
}
}

if bran.Protected {
protectedBranch, _, err := handler.glClient.ProtectedBranches.GetProtectedBranch(handler.repourl.projectID, bran.Name)
if err != nil {
Expand All @@ -188,6 +190,7 @@ func (handler *branchesHandler) getBranch(commitOrBranch string) (*clients.Branc

projectStatusChecks, resp, err := handler.glClient.ExternalStatusChecks.ListProjectStatusChecks(
handler.repourl.projectID, &gitlab.ListOptions{})

// Project Status Checks are only allowed for GitLab ultimate members so we will assume they are
// null if user does not have permissions.
if err != nil && resp.StatusCode != 404 && resp.StatusCode != 401 {
Expand Down Expand Up @@ -225,10 +228,8 @@ func makeBranchRefFrom(branch *gitlab.Branch, protectedBranch *gitlab.ProtectedB
projectApprovalRule *gitlab.ProjectApprovals,
) *clients.BranchRef {
requiresStatusChecks := newFalse()
if projectStatusChecks != nil {
if len(projectStatusChecks) > 0 {
requiresStatusChecks = newTrue()
}
if len(projectStatusChecks) > 0 {
requiresStatusChecks = newTrue()
}

statusChecksRule := clients.StatusChecksRule{
Expand Down
5 changes: 1 addition & 4 deletions clients/gitlabrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type Client struct {
languages *languagesHandler
ctx context.Context
tarball tarballHandler
}

// InitRepo sets up the GitLab project in local storage for improving performance and GitLab token usage efficiency.
func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string) error {
Expand Down Expand Up @@ -119,10 +118,8 @@ func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string) error {
// Init languagesHandler
client.languages.init(client.repourl)

// Init tarballHandler.
// Init tarballHandler
client.tarball.init(client.ctx, client.repourl, client.repo, commitSHA)
return nil
}

func (client *Client) URI() string {
return fmt.Sprintf("%s/%s/%s", client.repourl.hostname, client.repourl.owner, client.repourl.projectID)
Expand Down
2 changes: 2 additions & 0 deletions clients/gitlabrepo/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (handler *commitsHandler) init(repourl *repoURL) {
handler.once = new(sync.Once)
}


// nolint: gocognit
func (handler *commitsHandler) setup() error {
handler.once.Do(func() {
commits, _, err := handler.glClient.Commits.ListCommits(handler.repourl.projectID, &gitlab.ListCommitsOptions{})
Expand Down
1 change: 0 additions & 1 deletion clients/gitlabrepo/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (handler *contributorsHandler) setup() error {
}

// TODO: Handle many users of same name

if len(users) == 0 {
continue
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/package_managers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cmd
import (
"bytes"
"errors"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -143,7 +143,7 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) {

return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(tt.args.result)),
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
}, nil
}).AnyTimes()
got, err := fetchGitRepositoryFromNPM(tt.args.packageName, p)
Expand Down Expand Up @@ -423,7 +423,7 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {

return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(tt.args.result)),
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
}, nil
}).AnyTimes()
got, err := fetchGitRepositoryFromPYPI(tt.args.packageName, p)
Expand Down Expand Up @@ -692,7 +692,7 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {

return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(tt.args.result)),
Body: io.NopCloser(bytes.NewBufferString(tt.args.result)),
}, nil
}).AnyTimes()
got, err := fetchGitRepositoryFromRubyGems(tt.args.packageName, p)
Expand Down
2 changes: 1 addition & 1 deletion cmd/packagemanager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type packageManagerClient interface {

type packageManager struct{}

//nolint: noctx
// nolint: noctx
func (c *packageManager) Get(url, packageName string) (*http.Response, error) {
const timeout = 10
client := &http.Client{
Expand Down
1 change: 1 addition & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func serveCmd(o *options.Options) *cobra.Command {
port = "8080"
}
fmt.Printf("Listening on localhost:%s\n", port)
//nolint: gosec // unsused.
err = http.ListenAndServe(fmt.Sprintf("0.0.0.0:%s", port), nil)
if err != nil {
// TODO(log): Should this actually panic?
Expand Down
3 changes: 2 additions & 1 deletion cron/internal/data/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (

// Adds "project=${PROJECT},dependency=true" to the repositories metadata.
// Args:
// file path to old_projects.csv new_projects.csv
//
// file path to old_projects.csv new_projects.csv
func main() {
if len(os.Args) != 3 {
panic("must provide 2 arguments")
Expand Down
1 change: 1 addition & 0 deletions cron/internal/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func scriptHandler(w http.ResponseWriter, r *http.Request) {
func main() {
http.HandleFunc("/", scriptHandler)
fmt.Printf("Starting HTTP server on port 8080 ...\n")
// nolint:gosec // internal server.
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cron/internal/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (

var ignoreRuntimeErrors = flag.Bool("ignoreRuntimeErrors", false, "if set to true any runtime errors will be ignored")

//nolint: gocognit
// nolint: gocognit
func processRequest(ctx context.Context,
batchRequest *data.ScorecardBatchRequest,
blacklistedChecks []string, bucketURL, rawBucketURL, apiBucketURL string,
Expand Down Expand Up @@ -267,6 +267,7 @@ func main() {
// Exposed for monitoring runtime profiles
go func() {
// TODO(log): Previously Fatal. Need to handle the error here.
//nolint: gosec // internal server.
logger.Info(fmt.Sprintf("%v", http.ListenAndServe(":8080", nil)))
}()

Expand Down
2 changes: 1 addition & 1 deletion docs/checks/internal/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
1 change: 1 addition & 0 deletions docs/checks/internal/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
var checksYAML []byte

// Check stores a check's information.
//
//nolint:govet
type Check struct {
Risk string `yaml:"risk"`
Expand Down
3 changes: 1 addition & 2 deletions e2e/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package e2e

import (
"context"
"io/ioutil"
"os"

"github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -85,7 +84,7 @@ var _ = Describe("E2E TEST:"+checks.CheckTokenPermissions, func() {
It("Should return token permission for a local repo client", func() {
dl := scut.TestDetailLogger{}

tmpDir, err := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
Expect(err).Should(BeNil())
defer os.RemoveAll(tmpDir)

Expand Down
7 changes: 4 additions & 3 deletions pkg/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/ossf/scorecard/v4/log"
)

//nolint
// nolint: govet
type jsonCheckResult struct {
Name string
Details []string
Expand All @@ -45,7 +45,7 @@ type jsonCheckDocumentationV2 struct {
// Can be extended if needed.
}

//nolint
// nolint: govet
type jsonCheckResultV2 struct {
Details []string `json:"details"`
Score int `json:"score"`
Expand All @@ -71,8 +71,9 @@ func (s jsonFloatScore) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%.1f", s)), nil
}

//nolint:govet
// JSONScorecardResultV2 exports results as JSON for new detail format.
//
//nolint:govet
type JSONScorecardResultV2 struct {
Date string `json:"date"`
Repo jsonRepoV2 `json:"repo"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/scorecard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Loading

0 comments on commit 6952c0d

Please sign in to comment.