Skip to content

Commit

Permalink
fix(run-action): fix a bug that github_app_should_limit_repositories …
Browse files Browse the repository at this point in the history
…can't be excluded (#472)

* fix(run-action): fix a bug that github_app_should_limit_repositories can't be excluded

* test: add a test case
  • Loading branch information
suzuki-shunsuke authored Jun 8, 2024
1 parent 3a0bb48 commit 28ded74
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ type Exclude struct {
StepID string `yaml:"step_id"`
}

func (e *Exclude) FilePath() string {
if e.WorkflowFilePath != "" {
return e.WorkflowFilePath
}
return e.ActionFilePath
}

func Find(fs afero.Fs) string {
for _, filePath := range []string{"ghalint.yaml", ".ghalint.yaml", "ghalint.yml", ".ghalint.yml"} {
if _, err := fs.Stat(filePath); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/policy/github_app_should_limit_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (p *GitHubAppShouldLimitPermissionsPolicy) excluded(excludes []*config.Excl
if exclude.PolicyName != p.Name() {
continue
}
if exclude.WorkflowFilePath != filePath {
if exclude.FilePath() != filePath {
continue
}
if jobName != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/policy/github_app_should_limit_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *GitHubAppShouldLimitRepositoriesPolicy) excluded(cfg *config.Config, st
if exclude.PolicyName != p.Name() {
continue
}
if exclude.WorkflowFilePath != stepCtx.FilePath {
if exclude.FilePath() != stepCtx.FilePath {
continue
}
if stepCtx.Job != nil && exclude.JobName != stepCtx.Job.Name {
Expand Down
23 changes: 23 additions & 0 deletions pkg/policy/github_app_should_limit_repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ func TestGitHubAppShouldLimitRepositoriesPolicy_ApplyStep(t *testing.T) { //noli
},
},
},
{
name: "exclude action",
cfg: &config.Config{
Excludes: []*config.Exclude{
{
PolicyName: "github_app_should_limit_repositories",
ActionFilePath: "foo/action.yaml",
StepID: "token",
},
},
},
stepCtx: &policy.StepContext{
FilePath: "foo/action.yaml",
},
step: &workflow.Step{
Uses: "tibdex/github-app-token@v2",
ID: "token",
With: map[string]string{
"app_id": "xxx",
"private_key": "xxx",
},
},
},
}
p := &policy.GitHubAppShouldLimitRepositoriesPolicy{}
logE := logrus.NewEntry(logrus.New())
Expand Down

0 comments on commit 28ded74

Please sign in to comment.