refactored values into struct
This commit is contained in:
parent
da176cfd4e
commit
b5b48fe224
44
main.go
44
main.go
@ -13,51 +13,61 @@ var (
|
|||||||
Version = "dev"
|
Version = "dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
struct Cache {
|
||||||
|
token string `json:token`
|
||||||
|
baseURL string `json:baseURL`
|
||||||
|
orgName string `json:orgName`
|
||||||
|
repoExclude string `json:repoExclude`
|
||||||
|
pullBaseBranch string `json:pullBaseBranch`
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// default values
|
// default values
|
||||||
var token string = "XXXXXXXXXXXXXXXXXX"
|
var values = Cache {
|
||||||
var baseURL string = "https://inf-git.fh-rosenheim.de"
|
token: "XXXXXXXXXXXXXXXXXX",
|
||||||
var orgName string = "vv-inf-sose21"
|
baseURL: "https://inf-git.fh-rosenheim.de",
|
||||||
var repoExclude string = "exclude*"
|
orgName: "vv-inf-sose21",
|
||||||
var pullBaseBranch string = "devel*"
|
repoExclude: "exclude*",
|
||||||
|
pullBaseBranch: "devel*",
|
||||||
|
}
|
||||||
|
|
||||||
// ask for infos
|
// ask for infos
|
||||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Base URL:", Default: baseURL}, &baseURL); err != nil {
|
if err := survey.AskOne(&survey.Input{Message: "GitLab Base URL:", Default: values.baseURL}, &values.baseURL); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Token:", Default: token}, &token); err != nil {
|
if err := survey.AskOne(&survey.Input{Message: "GitLab Token:", Default: values.token}, &values.token); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err := survey.AskOne(&survey.Input{Message: "Group Name:", Default: orgName}, &orgName); err != nil {
|
if err := survey.AskOne(&survey.Input{Message: "Group Name:", Default: values.orgName}, &values.orgName); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err := survey.AskOne(&survey.Input{Message: "Ignore Repo with patter:", Default: repoExclude}, &repoExclude); err != nil {
|
if err := survey.AskOne(&survey.Input{Message: "Ignore Repo with patter:", Default: values.repoExclude}, &values.repoExclude); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err := survey.AskOne(&survey.Input{Message: "Merge Branches with patter:", Default: pullBaseBranch}, &pullBaseBranch); err != nil {
|
if err := survey.AskOne(&survey.Input{Message: "Merge Branches with patter:", Default: values.pullBaseBranch}, &values.pullBaseBranch); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile glob regex
|
// Compile glob regex
|
||||||
excludeRule, err := glob.Compile(repoExclude)
|
excludeRule, err := glob.Compile(values.repoExclude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(2, "not able to compile regex '%s'", repoExclude)
|
error(2, "not able to compile regex '%s'", values.repoExclude)
|
||||||
}
|
}
|
||||||
baseBranchRule, err := glob.Compile(pullBaseBranch)
|
baseBranchRule, err := glob.Compile(values.pullBaseBranch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(3, "not able to compile regex '%s'", pullBaseBranch)
|
error(3, "not able to compile regex '%s'", values.pullBaseBranch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect to gitlab
|
// connect to gitlab
|
||||||
client, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseURL))
|
client, err := gitlab.NewClient(values.token, gitlab.WithBaseURL(values.baseURL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(4, "Could not create Client: %v\n", err)
|
error(4, "Could not create Client: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// discover GroupID by name
|
// discover GroupID by name
|
||||||
org, _, err := client.Groups.GetGroup(orgName)
|
org, _, err := client.Groups.GetGroup(values.orgName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(5, "Error cant get information for Organisation \"%s\": %v", orgName, err)
|
error(5, "Error cant get information for Organisation \"%s\": %v", values.orgName, err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Found \"%s\"\n", org.WebURL)
|
fmt.Printf("Found \"%s\"\n", org.WebURL)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user