Skip to content

Commit

Permalink
fix(repo): allow users to disable events
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Nov 20, 2023
1 parent e4f3af7 commit f542301
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion action/repo/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *Config) Add(client *vela.Client) error {
}

// check if the repository should allow deployment events
if event == constants.EventDeploy {
if event == constants.EventDeploy || event == AlternateDeploy {
r.AllowDeploy = vela.Bool(true)
}

Expand Down
4 changes: 4 additions & 0 deletions action/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ type Config struct {
Trusted bool
Active bool
Events []string
DropEvents []string
PipelineType string
Page int
PerPage int
Output string
}

// AlternateDeploy is a common representation of constants.EventDeploy.
const AlternateDeploy = "deploy"
25 changes: 24 additions & 1 deletion action/repo/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *Config) Update(client *vela.Client) error {
}

// check if the repository should allow deployment events
if event == constants.EventDeploy {
if event == constants.EventDeploy || event == AlternateDeploy {
r.AllowDeploy = vela.Bool(true)
}

Expand All @@ -68,6 +68,29 @@ func (c *Config) Update(client *vela.Client) error {
}
}

// iterate through all drop events provided
for _, event := range c.DropEvents {
if event == constants.EventPush {
r.AllowPush = vela.Bool(false)
}

if event == constants.EventPull {
r.AllowPull = vela.Bool(false)
}

if event == constants.EventTag {
r.AllowTag = vela.Bool(false)
}

if event == constants.EventDeploy || event == AlternateDeploy {
r.AllowDeploy = vela.Bool(false)
}

if event == constants.EventComment {
r.AllowComment = vela.Bool(false)
}
}

logrus.Tracef("updating repo %s/%s", c.Org, c.Name)

// send API call to modify a repository
Expand Down
3 changes: 2 additions & 1 deletion action/repo/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestRepo_Config_Update(t *testing.T) {
Trusted: false,
Active: true,
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
DropEvents: []string{"push", "pull_request", "comment", "deployment", "tag"},
PipelineType: "yaml",
Output: "",
},
Expand All @@ -61,7 +62,7 @@ func TestRepo_Config_Update(t *testing.T) {
Private: false,
Trusted: false,
Active: true,
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
DropEvents: []string{"deployment", "tag"},
PipelineType: "yaml",
Output: "dump",
},
Expand Down
5 changes: 2 additions & 3 deletions command/repo/add.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

//nolint:dupl // ignore similar code with update
package repo

import (
Expand Down Expand Up @@ -104,9 +103,9 @@ var CommandAdd = &cli.Command{
Value: "true",
},
&cli.StringSliceFlag{
EnvVars: []string{"VELA_EVENTS", "REPO_EVENTS"},
EnvVars: []string{"VELA_EVENTS", "REPO_EVENTS", "VELA_ADD_EVENTS", "REPO_ADD_EVENTS"},
Name: "event",
Aliases: []string{"e"},
Aliases: []string{"events", "add-event", "add-events", "e"},
Usage: "webhook event(s) repository responds to",
},
&cli.StringFlag{
Expand Down
18 changes: 11 additions & 7 deletions command/repo/update.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

//nolint:dupl // ignore similar code with add
package repo

import (
Expand Down Expand Up @@ -104,14 +103,16 @@ var CommandUpdate = &cli.Command{
Value: "true",
},
&cli.StringSliceFlag{
EnvVars: []string{"VELA_EVENTS", "REPO_EVENTS"},
EnvVars: []string{"VELA_EVENTS", "REPO_EVENTS", "VELA_ADD_EVENTS", "REPO_ADD_EVENTS"},
Name: "event",
Aliases: []string{"e"},
Aliases: []string{"events", "add-event", "add-events", "e"},
Usage: "webhook event(s) repository responds to",
Value: cli.NewStringSlice(
constants.EventPush,
constants.EventPull,
),
},
&cli.StringSliceFlag{
EnvVars: []string{"VELA_DROP_EVENTS", "REPO_DROP_EVENTS"},
Name: "drop-event",
Aliases: []string{"drop-events", "de"},
Usage: "remove webhook event(s) repository responds to",
},
&cli.StringFlag{
EnvVars: []string{"VELA_PIPELINE_TYPE", "PIPELINE_TYPE"},
Expand All @@ -136,6 +137,8 @@ EXAMPLES:
$ {{.HelpName}} --org MyOrg --repo MyRepo --event push --event pull_request
2. Update a repository with all event types enabled.
$ {{.HelpName}} --org MyOrg --repo MyRepo --event push --event pull_request --event tag --event deployment --event comment
3. Update a repository to disable the comment and deploy events.
$ {{.HelpName}} --org MyOrg --repo MyRepo --event push --drop-events deployment,comment
3. Update a repository with a longer build timeout.
$ {{.HelpName}} --org MyOrg --repo MyRepo --timeout 90
4. Update a repository when config or environment variables are set.
Expand Down Expand Up @@ -184,6 +187,7 @@ func update(c *cli.Context) error {
Trusted: c.Bool("trusted"),
Active: c.Bool("active"),
Events: c.StringSlice("event"),
DropEvents: c.StringSlice("drop-event"),
PipelineType: c.String("pipeline-type"),
Output: c.String(internal.FlagOutput),
}
Expand Down

0 comments on commit f542301

Please sign in to comment.