fileparser

package
v4.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 12 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFileContainsCommands

func CheckFileContainsCommands(content []byte, comment string) bool

CheckFileContainsCommands checks if the file content contains commands or not. `comment` is the string or character that indicates a comment: for example for Dockerfiles, it would be `#`.

func FormatActionlintError

func FormatActionlintError(errs []*actionlint.Error) error

FormatActionlintError combines the errors into a single one.

func GetJobName

func GetJobName(job *actionlint.Job) string

GetJobName returns Name.Value if non-nil, else returns "".

func GetLineNumber

func GetLineNumber(pos *actionlint.Pos) uint

GetLineNumber returns the line number for this position.

func GetOSesForJob

func GetOSesForJob(job *actionlint.Job) ([]string, error)

GetOSesForJob returns the OSes this job runs on.

func GetShellForStep

func GetShellForStep(step *actionlint.Step, job *actionlint.Job) (string, error)

GetShellForStep returns the shell that is used to run the given step.

func GetStepName

func GetStepName(step *actionlint.Step) string

GetStepName returns Name.Value if non-nil, else returns "".

func GetUses

func GetUses(step *actionlint.Step) *actionlint.String

GetUses returns the 'uses' statement in this step or nil if this step does not have one.

func IsGitHubOwnedAction

func IsGitHubOwnedAction(actionName string) bool

IsGitHubOwnedAction checks if this is a github specific action.

func IsGithubWorkflowFileCb added in v4.1.0

func IsGithubWorkflowFileCb(pathfn string) (bool, error)

IsGithubWorkflowFileCb determines if a file is a workflow as a callback to use for repo client's ListFiles() API.

func IsGitlabWorkflowFile added in v4.11.0

func IsGitlabWorkflowFile(pathfn string) (bool, error)

IsGitlabWorkflowFile determines if a file is a workflow as a callback to use for repo client's ListFiles() API.

func IsStepExecKind

func IsStepExecKind(step *actionlint.Step, kind actionlint.ExecKind) bool

IsStepExecKind compares input `step` ExecKind with `kind` and returns true on a match.

func IsStepWindows

func IsStepWindows(step *actionlint.Step) (bool, error)

IsStepWindows returns true if the step will be run on Windows.

func IsTemplateFile

func IsTemplateFile(pathfn string) bool

IsTemplateFile returns true if the file name contains a string commonly used in template files.

func IsWorkflowFile

func IsWorkflowFile(pathfn string) bool

IsWorkflowFile returns true if this is a GitHub workflow file.

func JobAlwaysRunsOnWindows

func JobAlwaysRunsOnWindows(job *actionlint.Job) (bool, error)

JobAlwaysRunsOnWindows returns true if the only OS that this job runs on is Windows.

func OnAllFilesDo added in v4.2.0

func OnAllFilesDo(repoClient clients.RepoClient, onFile DoWhileTrueOnFilename, args ...interface{}) error

OnAllFilesDo iterates through all files returned by `repoClient` and calls `onFile` fn on them until `onFile` returns error or a false value.

func OnMatchingFileContentDo added in v4.2.0

func OnMatchingFileContentDo(repoClient clients.RepoClient, matchPathTo PathMatcher,
	onFileContent DoWhileTrueOnFileContent, args ...interface{},
) error

OnMatchingFileContentDo matches all files listed by `repoClient` against `matchPathTo` and on every successful match, runs onFileContent fn on the file's contents. Continues iterating along the matched files until onFileContent returns either a false value or an error.

Types

type DoWhileTrueOnFileContent added in v4.2.0

type DoWhileTrueOnFileContent func(path string, content []byte, args ...interface{}) (bool, error)

DoWhileTrueOnFileContent takes a filepath, its content and optional variadic args. It returns a boolean indicating whether iterating over next files should continue.

type DoWhileTrueOnFilename added in v4.2.0

type DoWhileTrueOnFilename func(path string, args ...interface{}) (bool, error)

DoWhileTrueOnFilename takes a filename and optional variadic args and returns true if the next filename should continue to be processed.

type JobMatchResult added in v4.4.0

type JobMatchResult struct {
	Msg  string
	File checker.File
}

JobMatchResult represents the result of a matche.

func AnyJobsMatch added in v4.2.0

func AnyJobsMatch(workflow *actionlint.Workflow, jobMatchers []JobMatcher, fp string,
	logMsgNoMatch string,
) (JobMatchResult, bool)

AnyJobsMatch returns true if any of the jobs have a match in the given workflow.

func IsPackagingWorkflow added in v4.5.0

func IsPackagingWorkflow(workflow *actionlint.Workflow, fp string) (JobMatchResult, bool)

IsPackagingWorkflow checks for a packaging workflow.

type JobMatcher

type JobMatcher struct {
	// The text to be logged when a job match is found.
	LogText string
	// Each step in this field has a matching step in the job.
	Steps []*JobMatcherStep
}

JobMatcher is rule for matching a job.

type JobMatcherStep

type JobMatcherStep struct {
	// If set, the step's 'Uses' must match this field. Checks that the action name is the same.
	Uses string
	// If set, the step's 'With' have the keys and values that are in this field.
	With map[string]string
	// If set, the step's 'Run' must match this field. Does a regex match using this field.
	Run string
}

JobMatcherStep is a single step that needs to be matched.

type PathMatcher added in v4.2.0

type PathMatcher struct {
	Pattern       string
	CaseSensitive bool
}

PathMatcher represents a query for a filepath.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL