Make config set via args or ENV-Vars (#11)
close #1 Reviewed-on: #11 Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
e6c684b99c
commit
7db6bbf357
121
merge/merge.go
121
merge/merge.go
@ -74,30 +74,103 @@ var CmdMerge = cli.Command{
|
|||||||
Usage: "run script for merge subcommand",
|
Usage: "run script for merge subcommand",
|
||||||
Description: `run script for merge subcommand`,
|
Description: `run script for merge subcommand`,
|
||||||
Action: runMerge,
|
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
|
// runMerge run script for merge subcommand
|
||||||
func runMerge(ctx *cli.Context) error {
|
func runMerge(ctx *cli.Context) error {
|
||||||
values := loadCache()
|
values := loadCache()
|
||||||
|
interactive := false
|
||||||
|
|
||||||
// ask for infos
|
if ctx.IsSet("token") {
|
||||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Base URL:", Default: values.baseURL}, &values.baseURL); err != nil {
|
values.token = ctx.String("token")
|
||||||
return err
|
} else {
|
||||||
}
|
interactive = true
|
||||||
if err := survey.AskOne(&survey.Input{Message: "GitLab Token:", Default: values.token}, &values.token); err != nil {
|
if err := survey.AskOne(&survey.Input{Message: "GitLab Token:", Default: values.token}, &values.token); err != nil {
|
||||||
return err
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Compile glob regex
|
||||||
excludeRule, err := glob.Compile(values.repoExclude)
|
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)
|
return fmt.Errorf("Could not create Client: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// discover GroupID by name
|
if orgID == 0 {
|
||||||
org, _, err := client.Groups.GetGroup(values.orgName)
|
// discover GroupID by name
|
||||||
if err != nil {
|
org, _, err := client.Groups.GetGroup(values.orgName)
|
||||||
return fmt.Errorf("Error cant get information for Organisation \"%s\": %v", values.orgName, err)
|
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 repoList []*gitlab.Project
|
||||||
var page = 1
|
var page = 1
|
||||||
fmt.Printf("Retrieving repository list...\n")
|
fmt.Printf("Retrieving repository list...\n")
|
||||||
for {
|
for {
|
||||||
fmt.Printf("%d", page)
|
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},
|
ListOptions: gitlab.ListOptions{PerPage: 10, Page: page},
|
||||||
Archived: utils.OptBool(false),
|
Archived: utils.OptBool(false),
|
||||||
IncludeSubgroups: utils.OptBool(false),
|
IncludeSubgroups: utils.OptBool(false),
|
||||||
|
Loading…
Reference in New Issue
Block a user