-
Notifications
You must be signed in to change notification settings - Fork 12
/
validate.go
50 lines (42 loc) · 1.2 KB
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: Apache-2.0
package repo
import (
"fmt"
"github.com/go-vela/types/constants"
"github.com/sirupsen/logrus"
)
// Validate verifies the configuration provided.
func (c *Config) Validate() error {
logrus.Debug("validating repo configuration")
// check if repository action is not get
if c.Action != "get" {
// check if repository org is set
if len(c.Org) == 0 {
return fmt.Errorf("no repo org provided")
}
// check if repository action is not syncAll
if c.Action != "syncAll" {
// check if repository name is set
if len(c.Name) == 0 {
return fmt.Errorf("no repo name provided")
}
}
}
// check if approve build setting is valid if supplied
if c.Action == "add" || c.Action == "update" {
if len(c.ApproveBuild) > 0 &&
c.ApproveBuild != constants.ApproveForkAlways &&
c.ApproveBuild != constants.ApproveForkNoWrite &&
c.ApproveBuild != constants.ApproveOnce &&
c.ApproveBuild != constants.ApproveNever {
return fmt.Errorf(
"invalid input for approve-build: must be `%s`, `%s`, `%s`, or `%s`",
constants.ApproveForkAlways,
constants.ApproveForkNoWrite,
constants.ApproveOnce,
constants.ApproveNever,
)
}
}
return nil
}