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

cmd: handle multiple config paths #15

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 38 additions & 10 deletions cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,18 @@ func (h *PRCommentHandler) HandlePRE(ctx context.Context, payload []byte) error
if err != nil {
return err
}
actionCfgPath := os.Getenv("CONFIG_PATH")
owner := event.PullRequest.Base.Repo.GetOwner().GetLogin()
repoName := event.PullRequest.Base.Repo.GetName()
ghSha := event.PullRequest.Base.GetSHA()
cfgFile, err := github.GetConfigFile(ghClient, owner, repoName, actionCfgPath, ghSha)

actionCfgPath, cfgFile, err := getActionsCfg(ghClient, owner, repoName, ghSha)
if err != nil {
return fmt.Errorf("unable to get config %q file: %s\n", actionCfgPath, err)
return err
}
if actionCfgPath == "" {
return fmt.Errorf("unable to find config files in sha %s", ghSha)
}

var c actions.PRBlockerConfig
err = yaml.Unmarshal(cfgFile, &c)
if err != nil {
Expand All @@ -146,7 +150,7 @@ func (h *PRCommentHandler) HandlePRE(ctx context.Context, payload []byte) error
return l.HandlePRE(c, &event)
}

func (h *PRCommentHandler) HandleSE(ctx context.Context, payload []byte) error{
func (h *PRCommentHandler) HandleSE(ctx context.Context, payload []byte) error {
var event gh.StatusEvent
if err := json.Unmarshal(payload, &event); err != nil {
return errors.Wrap(err, "failed to parse issue comment event payload")
Expand All @@ -157,14 +161,18 @@ func (h *PRCommentHandler) HandleSE(ctx context.Context, payload []byte) error{
if err != nil {
return err
}
actionCfgPath := os.Getenv("CONFIG_PATH")
owner := event.Repo.GetOwner().GetLogin()
repoName := event.Repo.GetName()
ghSha := event.GetSHA()
cfgFile, err := github.GetConfigFile(ghClient, owner, repoName, actionCfgPath, ghSha)

actionCfgPath, cfgFile, err := getActionsCfg(ghClient, owner, repoName, ghSha)
if err != nil {
return fmt.Errorf("unable to get config %q file: %s\n", actionCfgPath, err)
return err
}
if actionCfgPath == "" {
return fmt.Errorf("unable to find config files in sha %s", ghSha)
}

var c actions.PRBlockerConfig
err = yaml.Unmarshal(cfgFile, &c)
if err != nil {
Expand All @@ -187,14 +195,18 @@ func (h *PRCommentHandler) HandlePRRE(ctx context.Context, payload []byte) error
if err != nil {
return err
}
actionCfgPath := os.Getenv("CONFIG_PATH")
owner := event.PullRequest.Base.Repo.GetOwner().GetLogin()
repoName := event.PullRequest.Base.Repo.GetName()
ghSha := event.PullRequest.Base.GetSHA()
cfgFile, err := github.GetConfigFile(ghClient, owner, repoName, actionCfgPath, ghSha)

actionCfgPath, cfgFile, err := getActionsCfg(ghClient, owner, repoName, ghSha)
if err != nil {
return fmt.Errorf("unable to get config %q file: %s\n", actionCfgPath, err)
return err
}
if actionCfgPath == "" {
return fmt.Errorf("unable to find config files in sha %s", ghSha)
}

var c actions.PRBlockerConfig
err = yaml.Unmarshal(cfgFile, &c)
if err != nil {
Expand All @@ -204,3 +216,19 @@ func (h *PRCommentHandler) HandlePRRE(ctx context.Context, payload []byte) error

return l.HandlePRRE(c, &event)
}

func getActionsCfg(ghClient *gh.Client, owner, repoName, ghSha string) (string, []byte, error) {
actionCfgPath := os.Getenv("CONFIG_PATHS")
configPaths := strings.Split(actionCfgPath, ",")
for _, configPath := range configPaths {
cfgFile, err := github.GetConfigFile(ghClient, owner, repoName, configPath, ghSha)
switch {
case actions.IsNotFound(err) || actions.IsNotFound(errors.Unwrap(err)):
continue
case err != nil:
return "", nil, fmt.Errorf("unable to get config %q file: %s %T\n", configPath, err, errors.Unwrap(err))
}
return configPath, cfgFile, nil
}
return "", nil, nil
}
4 changes: 2 additions & 2 deletions install/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module "gce-advanced-container" {
value = "80"
},
{
name = "CONFIG_PATH"
value = ".github/cilium-actions.yml"
name = "CONFIG_PATHS"
value = ".github/cilium-actions.yml,.github/maintainers-little-helper.yaml"
},
{
name = "LISTEN_ADDRESS"
Expand Down
2 changes: 1 addition & 1 deletion install/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ variable "service_account_name" {
variable "container_image" {
description = "The image name to deploy"
type = string
default = "quay.io/cilium/github-actions:v1.0.2"
default = "quay.io/cilium/github-actions:v1.0.3"
}