Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ GitLab: Documentation and cleaner errors #2821

Merged
merged 9 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion checker/raw_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ const (
// DangerousWorkflowData contains raw results
// for dangerous workflow check.
type DangerousWorkflowData struct {
Workflows []DangerousWorkflow
Workflows []DangerousWorkflow
NumWorkflows int
}

// DangerousWorkflow represents a dangerous workflow.
Expand All @@ -332,6 +333,7 @@ type WorkflowJob struct {
// TokenPermissionsData represents data about a permission failure.
type TokenPermissionsData struct {
TokenPermissions []TokenPermission
NumTokens int
}

// PermissionLocation represents a declaration type.
Expand Down
2 changes: 1 addition & 1 deletion checks/evaluation/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Contributors(name string, dl checker.DetailLogger,

sort.Strings(names)

if len(name) > 0 {
if len(names) > 0 {
dl.Info(&checker.LogMessage{
Text: fmt.Sprintf("contributors work for %v", strings.Join(names, ",")),
})
Expand Down
4 changes: 4 additions & 0 deletions checks/evaluation/dangerous_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func DangerousWorkflow(name string, dl checker.DetailLogger,
return checker.CreateRuntimeErrorResult(name, e)
}

if r.NumWorkflows == 0 {
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
return checker.CreateInconclusiveResult(name, "no workflows found")
}

for _, e := range r.Workflows {
var text string
switch e.Type {
Expand Down
4 changes: 4 additions & 0 deletions checks/evaluation/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func TokenPermissions(name string, c *checker.CheckRequest, r *checker.TokenPerm
return checker.CreateRuntimeErrorResult(name, e)
}

if r.NumTokens == 0 {
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
return checker.CreateInconclusiveResult(name, "no github tokens found")
}

score, err := applyScorePolicy(r, c)
if err != nil {
return checker.CreateRuntimeErrorResult(name, err)
Expand Down
2 changes: 2 additions & 0 deletions checks/raw/dangerous_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ var validateGitHubActionWorkflowPatterns fileparser.DoWhileTrueOnFileContent = f
return true, nil
}

pdata.NumWorkflows += 1
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved

workflow, errs := actionlint.Parse(content)
if len(errs) > 0 && workflow == nil {
return false, fileparser.FormatActionlintError(errs)
Expand Down
2 changes: 2 additions & 0 deletions checks/raw/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ var validateGitHubActionTokenPermissions fileparser.DoWhileTrueOnFileContent = f
return true, nil
}

pdata.results.NumTokens += 1
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved

workflow, errs := actionlint.Parse(content)
if len(errs) > 0 && workflow == nil {
return false, fileparser.FormatActionlintError(errs)
Expand Down
1 change: 0 additions & 1 deletion clients/gitlabrepo/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (handler *branchesHandler) setup() error {
handler.repourl.project, &gitlab.ListOptions{})
if err != nil && resp.StatusCode != 404 {
handler.errSetup = fmt.Errorf("request for external status checks failed with error %w", err)
return
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
}

projectApprovalRule, resp, err := handler.glClient.Projects.GetApprovalConfiguration(handler.repourl.project)
Expand Down
5 changes: 4 additions & 1 deletion clients/gitlabrepo/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ func releasesFrom(data []*gitlab.Release) []clients.Release {
for _, r := range data {
release := clients.Release{
TagName: r.TagName,
URL: r.Assets.Links[0].DirectAssetURL,
TargetCommitish: r.CommitPath,
}
if len(r.Assets.Links) > 0 {
release.URL = r.Assets.Links[0].DirectAssetURL
}

for _, a := range r.Assets.Sources {
release.Assets = append(release.Assets, clients.ReleaseAsset{
Name: a.Format,
Expand Down
2 changes: 0 additions & 2 deletions clients/gitlabrepo/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ func (handler *tarballHandler) getFileContent(filename string) ([]byte, error) {
fmt.Printf("err: %v\n", err)
return nil, fmt.Errorf("error during tarballHandler.setup: %w", err)
}
fmt.Printf("handler.tempDir: %v\n", handler.tempDir)
fmt.Printf("filename: %v\n", filename)
content, err := os.ReadFile(filepath.Join(handler.tempDir, filename))
if err != nil {
return content, fmt.Errorf("os.ReadFile: %w", err)
Expand Down