forked from bitrise-steplib/steps-git-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
126 lines (106 loc) · 3.3 KB
/
config.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"fmt"
"os"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-tools/go-steputils/input"
)
// Config ...
type Config struct {
CloneIntoDir string
RepositoryURL string
Commit string
Tag string
Branch string
CloneDepth int
PRRepositoryCloneURL string
PRID int
BranchDest string
PRMergeBranch string
ResetRepository bool
BuildURL string
BuildAPIToken string
UpdateSubmodules bool
ManualMerge bool
}
func newConfig() (Config, []error) {
config := Config{
Commit: os.Getenv("commit"),
Tag: os.Getenv("tag"),
Branch: os.Getenv("branch"),
PRRepositoryCloneURL: os.Getenv("pull_request_repository_url"),
BranchDest: os.Getenv("branch_dest"),
PRMergeBranch: os.Getenv("pull_request_merge_branch"),
BuildURL: os.Getenv("build_url"),
BuildAPIToken: os.Getenv("build_api_token"),
}
var errs []error
// required
err := input.ValidateIfNotEmpty(os.Getenv("clone_into_dir"))
if err != nil {
errs = append(errs, fmt.Errorf("clone_into_dir: %v", err))
} else {
config.CloneIntoDir = os.Getenv("clone_into_dir")
}
err = input.ValidateIfNotEmpty(os.Getenv("repository_url"))
if err != nil {
errs = append(errs, fmt.Errorf("repository_url: %v", err))
} else {
config.RepositoryURL = os.Getenv("repository_url")
}
// numbers
num, err := input.ValidateInt(os.Getenv("clone_depth"))
if err != nil {
errs = append(errs, fmt.Errorf("clone_depth: %v", err))
} else {
config.CloneDepth = num
}
num, err = input.ValidateInt(os.Getenv("pull_request_id"))
if err != nil {
errs = append(errs, fmt.Errorf("pull_request_id: %v", err))
} else {
config.PRID = num
}
// bools
err = input.ValidateWithOptions(os.Getenv("reset_repository"), "Yes", "No")
if err != nil {
errs = append(errs, fmt.Errorf("reset_repository: %v", err))
} else {
config.ResetRepository = os.Getenv("reset_repository") == "Yes"
}
err = input.ValidateWithOptions(os.Getenv("manual_merge"), "yes", "no")
if err != nil {
errs = append(errs, fmt.Errorf("manual_merge: %v", err))
} else {
config.ManualMerge = os.Getenv("manual_merge") == "yes"
}
err = input.ValidateWithOptions(os.Getenv("update_submodules"), "yes", "no")
if err != nil {
errs = append(errs, fmt.Errorf("update_submodules: %v", err))
} else {
config.UpdateSubmodules = os.Getenv("update_submodules") == "yes"
}
return config, errs
}
func (c Config) print() {
log.Infof("Git Clone config:")
log.Printf("- CloneIntoDir: %s", c.CloneIntoDir)
log.Printf("- RepositoryURL: %s", c.RepositoryURL)
log.Printf("- UpdateSubmodules: %t", c.UpdateSubmodules)
log.Infof("Git Checkout config:")
log.Printf("- Commit: %s", c.Commit)
log.Printf("- Tag: %s", c.Tag)
log.Printf("- Branch: %s", c.Branch)
log.Printf("- CloneDepth: %d", c.CloneDepth)
log.Infof("Git Pull Request config:")
log.Printf("- PRRepositoryCloneURL: %s", c.PRRepositoryCloneURL)
log.Printf("- PRID: %d", c.PRID)
log.Printf("- BranchDest: %s", c.BranchDest)
log.Printf("- PRMergeBranch: %s", c.PRMergeBranch)
log.Printf("- ResetRepository: %t", c.ResetRepository)
log.Printf("- ManualMerge: %t", c.ManualMerge)
log.Infof("Bitrise Build config:")
log.Printf("- BuildURL: %s", c.BuildURL)
log.Printf("- BuildAPIToken: %s", c.BuildAPIToken)
fmt.Println()
}