mirror of https://gitlab.com/gitlab-org/cli.git
Added recursive option
This commit is contained in:
parent
65118b82fc
commit
7c012d1aca
|
@ -19,6 +19,7 @@ const (
|
|||
|
||||
type Options struct {
|
||||
Group string
|
||||
Recursive bool
|
||||
ProjectPerPage int
|
||||
ProjectPage int
|
||||
AgentPerPage int
|
||||
|
@ -62,6 +63,8 @@ This is an experimental feature. Use at your own risk.
|
|||
checkManifestUsageCmd.Flags().IntVarP(&opts.ProjectPerPage, "per-page", "P", 30, "Number of projects to list per page")
|
||||
checkManifestUsageCmd.Flags().IntVarP(&opts.AgentPage, "agent-page", "a", 1, "Page number for projects")
|
||||
checkManifestUsageCmd.Flags().IntVarP(&opts.AgentPerPage, "agent-per-page", "A", 30, "Number of projects to list per page")
|
||||
// checkManifestUsageCmd.Flags().BoolP(&opts.Recursive, "recursive", "r", false, "Recursively check subgroups")
|
||||
checkManifestUsageCmd.Flags().BoolVarP(&opts.Recursive, "recursive", "r", false, "Recursively check subgroups")
|
||||
|
||||
return checkManifestUsageCmd
|
||||
}
|
||||
|
@ -71,33 +74,63 @@ func checkManifestUsageInGroup(opts *Options) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
color := opts.IO.Color()
|
||||
|
||||
// new line
|
||||
err = checkGroup(apiClient, opts.Group, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if opts.Recursive {
|
||||
var groups []*gitlab.Group
|
||||
groups, _, err = listAllGroupsForGroup(apiClient, opts.Group, *opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, group := range groups {
|
||||
err = checkGroup(apiClient, group.FullPath, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkGroup(apiClient *gitlab.Client, group string, opts *Options) error {
|
||||
var projects []*gitlab.Project
|
||||
var resp *gitlab.Response
|
||||
projects, resp, err = listAllProjectsForGroup(apiClient, *opts)
|
||||
projects, resp, err := listAllProjectsForGroup(apiClient, group, *opts)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
color := opts.IO.Color()
|
||||
opts.IO.Log(color.ProgressIcon(), fmt.Sprintf("Checking %d of %d projects (Page %d of %d)\n", len(projects), resp.TotalItems, resp.CurrentPage, resp.TotalPages))
|
||||
for _, prj := range projects {
|
||||
checkManifestUsageInProject(apiClient, opts, prj)
|
||||
}
|
||||
// new line
|
||||
opts.IO.Log()
|
||||
|
||||
return err
|
||||
opts.IO.Log()
|
||||
return nil
|
||||
}
|
||||
|
||||
func listAllProjectsForGroup(apiClient *gitlab.Client, opts Options) ([]*gitlab.Project, *gitlab.Response, error) {
|
||||
func listAllGroupsForGroup(apiClient *gitlab.Client, group string, opts Options) ([]*gitlab.Group, *gitlab.Response, error) {
|
||||
l := &gitlab.ListDescendantGroupsOptions{}
|
||||
return apiClient.Groups.ListDescendantGroups(group, l)
|
||||
}
|
||||
|
||||
func listAllProjectsForGroup(apiClient *gitlab.Client, group string, opts Options) ([]*gitlab.Project, *gitlab.Response, error) {
|
||||
l := &gitlab.ListGroupProjectsOptions{}
|
||||
|
||||
l.PerPage = opts.ProjectPerPage
|
||||
l.Page = opts.ProjectPage
|
||||
|
||||
return apiClient.Groups.ListGroupProjects(opts.Group, l)
|
||||
return apiClient.Groups.ListGroupProjects(group, l)
|
||||
}
|
||||
|
||||
func checkManifestUsageInProject(apiClient *gitlab.Client, opts *Options, project *gitlab.Project) error {
|
||||
|
|
Loading…
Reference in New Issue