make config set via args or ENV-Vars
This commit is contained in:
parent
e6c684b99c
commit
afa8b71a41
121
merge/merge.go
121
merge/merge.go
@ -74,30 +74,103 @@ var CmdMerge = cli.Command{
|
||||
Usage: "run script for merge subcommand",
|
||||
Description: `run script for merge subcommand`,
|
||||
Action: runMerge,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "token",
|
||||
Usage: "GitLab Access Token",
|
||||
EnvVars: []string{"TOKEN"},
|
||||
Required: false,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "url",
|
||||
Usage: "GitLab Base URL",
|
||||
EnvVars: []string{"BASE_URL"},
|
||||
Required: false,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "group-id",
|
||||
Usage: "Group ID where repositories are stored",
|
||||
EnvVars: []string{"GROUP_ID"},
|
||||
Required: false,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "group-name",
|
||||
Usage: "Group Name where repositories are stored, it's used if group-id is not set",
|
||||
EnvVars: []string{"GROUP_NAME"},
|
||||
Required: false,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "repo-ignore-pattern",
|
||||
Usage: "Repo Ignore Pattern",
|
||||
EnvVars: []string{"REPO_IGNORE_PATTERN"},
|
||||
Required: false,
|
||||
},
|
||||
|
||||
&cli.StringFlag{
|
||||
Name: "branch-pattern",
|
||||
Usage: "Merge Branches with patter",
|
||||
EnvVars: []string{"BRANCH_PATTERN"},
|
||||
Required: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// runMerge run script for merge subcommand
|
||||
func runMerge(ctx *cli.Context) error {
|
||||
values := loadCache()
|
||||
interactive := false
|
||||
|
||||
// ask for infos
|
||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Base URL:", Default: values.baseURL}, &values.baseURL); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Token:", Default: values.token}, &values.token); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := survey.AskOne(&survey.Input{Message: "Group Name:", Default: values.orgName}, &values.orgName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := survey.AskOne(&survey.Input{Message: "Ignore Repo with patter:", Default: values.repoExclude}, &values.repoExclude); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := survey.AskOne(&survey.Input{Message: "Merge Branches with patter:", Default: values.pullBaseBranch}, &values.pullBaseBranch); err != nil {
|
||||
return err
|
||||
if ctx.IsSet("token") {
|
||||
values.token = ctx.String("token")
|
||||
} else {
|
||||
interactive = true
|
||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Token:", Default: values.token}, &values.token); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
saveCache(values)
|
||||
if ctx.IsSet("url") {
|
||||
values.baseURL = ctx.String("url")
|
||||
} else {
|
||||
interactive = true
|
||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Base URL:", Default: values.baseURL}, &values.baseURL); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
orgID := ctx.Int("group-id")
|
||||
if orgID == 0 {
|
||||
if ctx.IsSet("group-name") {
|
||||
values.orgName = ctx.String("group-name")
|
||||
} else {
|
||||
interactive = true
|
||||
if err := survey.AskOne(&survey.Input{Message: "Group Name:", Default: values.orgName}, &values.orgName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.IsSet("repo-ignore-pattern") {
|
||||
values.repoExclude = ctx.String("repo-ignore-pattern")
|
||||
} else {
|
||||
interactive = true
|
||||
if err := survey.AskOne(&survey.Input{Message: "Ignore Repo with patter:", Default: values.repoExclude}, &values.repoExclude); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.IsSet("branch-pattern") {
|
||||
values.pullBaseBranch = ctx.String("branch-pattern")
|
||||
} else {
|
||||
interactive = true
|
||||
if err := survey.AskOne(&survey.Input{Message: "Merge Branches with patter:", Default: values.pullBaseBranch}, &values.pullBaseBranch); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if interactive {
|
||||
saveCache(values)
|
||||
}
|
||||
|
||||
// Compile glob regex
|
||||
excludeRule, err := glob.Compile(values.repoExclude)
|
||||
@ -115,19 +188,23 @@ func runMerge(ctx *cli.Context) error {
|
||||
return fmt.Errorf("Could not create Client: %v\n", err)
|
||||
}
|
||||
|
||||
// discover GroupID by name
|
||||
org, _, err := client.Groups.GetGroup(values.orgName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error cant get information for Organisation \"%s\": %v", values.orgName, err)
|
||||
if orgID == 0 {
|
||||
// discover GroupID by name
|
||||
org, _, err := client.Groups.GetGroup(values.orgName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error cant get information for Organisation \"%s\": %v", values.orgName, err)
|
||||
}
|
||||
fmt.Printf("Found \"%s\"\n", org.WebURL)
|
||||
|
||||
orgID = org.ID
|
||||
}
|
||||
fmt.Printf("Found \"%s\"\n", org.WebURL)
|
||||
|
||||
var repoList []*gitlab.Project
|
||||
var page = 1
|
||||
fmt.Printf("Retrieving repository list...\n")
|
||||
for {
|
||||
fmt.Printf("%d", page)
|
||||
repos, _, err := client.Groups.ListGroupProjects(org.ID, &gitlab.ListGroupProjectsOptions{
|
||||
repos, _, err := client.Groups.ListGroupProjects(orgID, &gitlab.ListGroupProjectsOptions{
|
||||
ListOptions: gitlab.ListOptions{PerPage: 10, Page: page},
|
||||
Archived: utils.OptBool(false),
|
||||
IncludeSubgroups: utils.OptBool(false),
|
||||
|
Loading…
Reference in New Issue
Block a user