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"
|
||||
)
|
||||
|
||||
struct Cache {
|
||||
token string `json:token`
|
||||
baseURL string `json:baseURL`
|
||||
orgName string `json:orgName`
|
||||
repoExclude string `json:repoExclude`
|
||||
pullBaseBranch string `json:pullBaseBranch`
|
||||
}
|
||||
|
||||
func main() {
|
||||
// default values
|
||||
var token string = "XXXXXXXXXXXXXXXXXX"
|
||||
var baseURL string = "https://inf-git.fh-rosenheim.de"
|
||||
var orgName string = "vv-inf-sose21"
|
||||
var repoExclude string = "exclude*"
|
||||
var pullBaseBranch string = "devel*"
|
||||
var values = Cache {
|
||||
token: "XXXXXXXXXXXXXXXXXX",
|
||||
baseURL: "https://inf-git.fh-rosenheim.de",
|
||||
orgName: "vv-inf-sose21",
|
||||
repoExclude: "exclude*",
|
||||
pullBaseBranch: "devel*",
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// Compile glob regex
|
||||
excludeRule, err := glob.Compile(repoExclude)
|
||||
excludeRule, err := glob.Compile(values.repoExclude)
|
||||
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 {
|
||||
error(3, "not able to compile regex '%s'", pullBaseBranch)
|
||||
error(3, "not able to compile regex '%s'", values.pullBaseBranch)
|
||||
}
|
||||
|
||||
// connect to gitlab
|
||||
client, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseURL))
|
||||
client, err := gitlab.NewClient(values.token, gitlab.WithBaseURL(values.baseURL))
|
||||
if err != nil {
|
||||
error(4, "Could not create Client: %v\n", err)
|
||||
}
|
||||
|
||||
// discover GroupID by name
|
||||
org, _, err := client.Groups.GetGroup(orgName)
|
||||
org, _, err := client.Groups.GetGroup(values.orgName)
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user