Skip to content

Commit 074c98d

Browse files
authored
fix(repo): add missing approve-build flag to add and update (#530)
1 parent ddb971f commit 074c98d

File tree

9 files changed

+79
-13
lines changed

9 files changed

+79
-13
lines changed

action/repo/add.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (c *Config) Add(client *vela.Client) error {
3939
Trusted: vela.Bool(c.Trusted),
4040
Active: vela.Bool(c.Active),
4141
PipelineType: vela.String(c.PipelineType),
42+
ApproveBuild: vela.String(c.ApproveBuild),
4243
}
4344

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

action/repo/add_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestRepo_Config_Add(t *testing.T) {
4747
Active: true,
4848
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
4949
PipelineType: "yaml",
50+
ApproveBuild: "fork-always",
5051
Output: "",
5152
},
5253
},
@@ -88,6 +89,7 @@ func TestRepo_Config_Add(t *testing.T) {
8889
Active: true,
8990
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
9091
PipelineType: "yaml",
92+
ApproveBuild: "fork-no-write",
9193
Output: "json",
9294
},
9395
},
@@ -130,6 +132,7 @@ func TestRepo_Config_Add(t *testing.T) {
130132
Active: true,
131133
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
132134
PipelineType: "yaml",
135+
ApproveBuild: "never",
133136
Output: "yaml",
134137
},
135138
},

action/repo/repo.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Config struct {
2020
Active bool
2121
Events []string
2222
PipelineType string
23+
ApproveBuild string
2324
Page int
2425
PerPage int
2526
Output string

action/repo/update.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (c *Config) Update(client *vela.Client) error {
3737
Trusted: vela.Bool(c.Trusted),
3838
Active: vela.Bool(c.Active),
3939
PipelineType: vela.String(c.PipelineType),
40+
ApproveBuild: vela.String(c.ApproveBuild),
4041
}
4142

4243
if len(c.Events) > 0 {

action/repo/update_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestRepo_Config_Update(t *testing.T) {
4343
Active: true,
4444
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
4545
PipelineType: "yaml",
46+
ApproveBuild: "fork-always",
4647
Output: "",
4748
},
4849
},
@@ -82,6 +83,7 @@ func TestRepo_Config_Update(t *testing.T) {
8283
Active: true,
8384
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
8485
PipelineType: "yaml",
86+
ApproveBuild: "fork-no-write",
8587
Output: "json",
8688
},
8789
},
@@ -122,6 +124,7 @@ func TestRepo_Config_Update(t *testing.T) {
122124
Active: true,
123125
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
124126
PipelineType: "yaml",
127+
ApproveBuild: "never",
125128
Output: "yaml",
126129
},
127130
},

action/repo/validate.go

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package repo
55
import (
66
"fmt"
77

8+
"github.com/go-vela/types/constants"
89
"github.com/sirupsen/logrus"
910
)
1011

@@ -28,5 +29,20 @@ func (c *Config) Validate() error {
2829
}
2930
}
3031

32+
// check if approve build setting is valid if supplied
33+
if c.Action == "add" || c.Action == "update" {
34+
if len(c.ApproveBuild) > 0 &&
35+
c.ApproveBuild != constants.ApproveForkAlways &&
36+
c.ApproveBuild != constants.ApproveForkNoWrite &&
37+
c.ApproveBuild != constants.ApproveNever {
38+
return fmt.Errorf(
39+
"invalid input for approve-build: must be `%s`, `%s`, or `%s`",
40+
constants.ApproveForkAlways,
41+
constants.ApproveForkNoWrite,
42+
constants.ApproveNever,
43+
)
44+
}
45+
}
46+
3147
return nil
3248
}

action/repo/validate_test.go

+34-13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ func TestRepo_Config_Validate(t *testing.T) {
3030
Output: "",
3131
},
3232
},
33+
{
34+
failure: true,
35+
config: &Config{
36+
Action: "add",
37+
Org: "github",
38+
Name: "octocat",
39+
ApproveBuild: "invalid",
40+
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
41+
},
42+
},
3343
{
3444
failure: false,
3545
config: &Config{
@@ -70,19 +80,30 @@ func TestRepo_Config_Validate(t *testing.T) {
7080
{
7181
failure: false,
7282
config: &Config{
73-
Action: "update",
74-
Org: "github",
75-
Name: "octocat",
76-
Link: "https://github.com/github/octocat",
77-
Clone: "https://github.com/github/octocat.git",
78-
Branch: "main",
79-
Timeout: 60,
80-
Visibility: "public",
81-
Private: false,
82-
Trusted: false,
83-
Active: true,
84-
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
85-
Output: "",
83+
Action: "update",
84+
Org: "github",
85+
Name: "octocat",
86+
Link: "https://github.com/github/octocat",
87+
Clone: "https://github.com/github/octocat.git",
88+
Branch: "main",
89+
Timeout: 60,
90+
Visibility: "public",
91+
Private: false,
92+
Trusted: false,
93+
Active: true,
94+
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
95+
ApproveBuild: "fork-no-write",
96+
Output: "",
97+
},
98+
},
99+
{
100+
failure: true,
101+
config: &Config{
102+
Action: "update",
103+
Org: "github",
104+
Name: "octocat",
105+
ApproveBuild: "invalid",
106+
Events: []string{"push", "pull_request", "comment", "deployment", "tag"},
86107
},
87108
},
88109
{

command/repo/add.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3+
//nolint:dupl // ignore duplicate of update
34
package repo
45

56
import (
@@ -115,6 +116,12 @@ var CommandAdd = &cli.Command{
115116
Usage: "type of base pipeline for the compiler to render",
116117
Value: constants.PipelineTypeYAML,
117118
},
119+
&cli.StringFlag{
120+
EnvVars: []string{"VELA_APPROVE_BUILD", "REPO_APPROVE_BUILD"},
121+
Name: "approve-build",
122+
Aliases: []string{"ab", "approve-build-setting"},
123+
Usage: "when to require admin approval to run builds from outside contributors (`fork-always`, `fork-no-write`, or `never`)",
124+
},
118125

119126
// Output Flags
120127

@@ -139,6 +146,8 @@ EXAMPLES:
139146
$ {{.HelpName}} --org MyOrg --repo MyRepo --counter 90
140147
6. Add a repository with a starlark pipeline file.
141148
$ {{.HelpName}} --org MyOrg --repo MyRepo --pipeline-type starlark
149+
7. Add a repository with approve build setting set to fork-no-write.
150+
$ {{.HelpName}} --org MyOrg --repo MyRepo --approve-build fork-no-write
142151
143152
DOCUMENTATION:
144153
@@ -182,6 +191,7 @@ func add(c *cli.Context) error {
182191
Active: c.Bool("active"),
183192
Events: c.StringSlice("event"),
184193
PipelineType: c.String("pipeline-type"),
194+
ApproveBuild: c.String("approve-build"),
185195
Output: c.String(internal.FlagOutput),
186196
}
187197

command/repo/update.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3+
//nolint:dupl // ignore duplicate of add
34
package repo
45

56
import (
@@ -115,6 +116,12 @@ var CommandUpdate = &cli.Command{
115116
Usage: "type of base pipeline for the compiler to render",
116117
Value: constants.PipelineTypeYAML,
117118
},
119+
&cli.StringFlag{
120+
EnvVars: []string{"VELA_APPROVE_BUILD", "REPO_APPROVE_BUILD"},
121+
Name: "approve-build",
122+
Aliases: []string{"ab", "approve-build-setting"},
123+
Usage: "when to require admin approval to run builds from outside contributors (`fork-always`, `fork-no-write`, or `never`)",
124+
},
118125

119126
// Output Flags
120127

@@ -137,6 +144,8 @@ EXAMPLES:
137144
$ {{.HelpName}}
138145
5. Update a repository with a new build number.
139146
$ {{.HelpName}} --org MyOrg --repo MyRepo --counter 200
147+
6. Update a repository with approve build setting set to fork-always.
148+
$ {{.HelpName}} --org MyOrg --repo MyRepo --approve-build fork-always
140149
141150
DOCUMENTATION:
142151
@@ -180,6 +189,7 @@ func update(c *cli.Context) error {
180189
Active: c.Bool("active"),
181190
Events: c.StringSlice("event"),
182191
PipelineType: c.String("pipeline-type"),
192+
ApproveBuild: c.String("approve-build"),
183193
Output: c.String(internal.FlagOutput),
184194
}
185195

0 commit comments

Comments
 (0)