remove gitlab namespaces concept

This commit is contained in:
Jay Gabriels
2020-08-12 19:26:41 -07:00
parent e813103dfe
commit e427bcf07d
7 changed files with 7 additions and 38 deletions

View File

@@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
## [1.3.2] - unrealeased
## [1.4.1] - unrealeased
### Added
- GHORG_GITHUB_TOPICS to filter cloning repos matching specified topics; thanks @ryanaross
- GHORG_MATCH_PREFIX to filter cloning repos by prefix
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
### Changed
### Deprecated
### Removed
- GHORG_GITLAB_DEFAULT_NAMESPACE
### Fixed
### Security

View File

@@ -59,8 +59,8 @@ $ vi $HOME/.config/ghorg/conf.yaml # (optional but recommended)
$ ghorg clone someorg
$ ghorg clone someorg --concurrency=50 --token=bGVhdmUgYSBjb21tZW50IG9uIGlzc3VlIDY2
$ ghorg clone someuser --clone-type=user --protocol=ssh --branch=develop --color=off
$ ghorg clone gitlab-org --scm=gitlab --namespace=gitlab-org/security-products
$ ghorg clone gitlab-org --scm=gitlab --base-url=https://gitlab.internal.yourcompany.com --preserve-dir
$ ghorg clone gitlab-group --scm=gitlab --base-url=https://gitlab.internal.yourcompany.com --preserve-dir
$ ghorg clone gitlab-group/gitlab-subgroup --scm=gitlab --base-url=https://gitlab.internal.yourcompany.com
$ ghorg clone --help
```

View File

@@ -55,7 +55,6 @@ func init() {
cloneCmd.Flags().StringVarP(&scmType, "scm", "s", "", "GHORG_SCM_TYPE - type of scm used, github, gitlab or bitbucket (default github)")
// TODO: make gitlab terminology make sense https://about.gitlab.com/2016/01/27/comparing-terms-gitlab-github-bitbucket/
cloneCmd.Flags().StringVarP(&cloneType, "clone-type", "c", "", "GHORG_CLONE_TYPE - clone target type, user or org (default org)")
cloneCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "GHORG_GITLAB_DEFAULT_NAMESPACE - gitlab only: limits clone targets to a specific namespace e.g. --namespace=gitlab-org/security-products")
cloneCmd.Flags().BoolVar(&skipArchived, "skip-archived", false, "GHORG_SKIP_ARCHIVED - skips archived repos, github/gitlab only")
cloneCmd.Flags().BoolVar(&skipArchived, "preserve-dir", false, "GHORG_PRESERVE_DIRECTORY_STRUCTURE - clones repos in a directory structure that matches gitlab namespaces eg company/unit/subunit/app would clone into *_ghorg/unit/subunit/app, gitlab only")
cloneCmd.Flags().BoolVar(&backup, "backup", false, "GHORG_BACKUP - backup mode, clone as mirror, no working copy (ignores branch parameter)")
@@ -108,10 +107,6 @@ func cloneFunc(cmd *cobra.Command, argz []string) {
os.Setenv("GHORG_BITBUCKET_USERNAME", cmd.Flag("bitbucket-username").Value.String())
}
if cmd.Flags().Changed("namespace") {
os.Setenv("GHORG_GITLAB_DEFAULT_NAMESPACE", cmd.Flag("namespace").Value.String())
}
if cmd.Flags().Changed("clone-type") {
cloneType := strings.ToLower(cmd.Flag("clone-type").Value.String())
os.Setenv("GHORG_CLONE_TYPE", cloneType)

View File

@@ -76,7 +76,6 @@ func initConfig() {
getOrSetDefaults("GHORG_CLONE_PROTOCOL")
getOrSetDefaults("GHORG_CLONE_TYPE")
getOrSetDefaults("GHORG_SCM_TYPE")
getOrSetDefaults("GHORG_GITLAB_DEFAULT_NAMESPACE")
getOrSetDefaults("GHORG_COLOR")
getOrSetDefaults("GHORG_SKIP_ARCHIVED")
getOrSetDefaults("GHORG_BACKUP")
@@ -126,8 +125,6 @@ func getOrSetDefaults(envVar string) {
os.Setenv(envVar, "org")
case "GHORG_SCM_TYPE":
os.Setenv(envVar, "github")
case "GHORG_GITLAB_DEFAULT_NAMESPACE":
os.Setenv(envVar, "unset")
case "GHORG_COLOR":
os.Setenv(envVar, "on")
case "GHORG_SKIP_ARCHIVED":

View File

@@ -13,7 +13,6 @@ func TestDefaultSettings(t *testing.T) {
protocol := os.Getenv("GHORG_CLONE_PROTOCOL")
scm := os.Getenv("GHORG_SCM_TYPE")
cloneType := os.Getenv("GHORG_CLONE_TYPE")
namespace := os.Getenv("GHORG_GITLAB_DEFAULT_NAMESPACE")
if branch != "master" {
t.Errorf("Default branch should be master, got: %v", branch)
@@ -31,10 +30,6 @@ func TestDefaultSettings(t *testing.T) {
t.Errorf("Default clone type should be org, got: %v", cloneType)
}
if namespace != "unset" {
t.Errorf("Default gitlab namespace type should be unset, got: %v", namespace)
}
}
func TestVerifyTokenSet(t *testing.T) {

View File

@@ -1,7 +1,6 @@
package gitlab
import (
"fmt"
"os"
"strings"
@@ -11,7 +10,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
)
// GetOrgRepos fetches repo data
// GetOrgRepos fetches repo data from a specific group
func GetOrgRepos(targetOrg string) ([]repo.Data, error) {
repoData := []repo.Data{}
client, err := determineClient()
@@ -20,21 +19,14 @@ func GetOrgRepos(targetOrg string) ([]repo.Data, error) {
colorlog.PrintError(err)
}
namespace := os.Getenv("GHORG_GITLAB_DEFAULT_NAMESPACE")
opt := &gitlab.ListGroupProjectsOptions{
ListOptions: gitlab.ListOptions{
PerPage: 50,
PerPage: 100,
Page: 1,
},
IncludeSubgroups: gitlab.Bool(true),
}
if namespace == "unset" {
colorlog.PrintInfo("No namespace set, to reduce results use namespace flag e.g. --namespace=gitlab-org/security-products")
fmt.Println("")
}
for {
// Get the first page with projects.
ps, resp, err := client.Groups.ListGroupProjects(targetOrg, opt)
@@ -47,15 +39,6 @@ func GetOrgRepos(targetOrg string) ([]repo.Data, error) {
// List all the projects we've found so far.
for _, p := range ps {
// If it is set, then filter only repos from the namespace
// if p.PathWithNamespace == "the namespace the user indicated" eg --namespace=org/namespace
if namespace != "unset" {
if strings.HasPrefix(p.PathWithNamespace, strings.ToLower(namespace)) == false {
continue
}
}
if os.Getenv("GHORG_SKIP_ARCHIVED") == "true" {
if p.Archived == true {
continue
@@ -114,6 +97,7 @@ func determineClient() (*gitlab.Client, error) {
return gitlab.NewClient(token)
}
// GetUserRepos gets all of a users gitlab repos
func GetUserRepos(targetUsername string) ([]repo.Data, error) {
cloneData := []repo.Data{}

View File

@@ -30,9 +30,6 @@ GHORG_SCM_BASE_URL:
# flag (--token, -t) eg: --token=bGVhdmUgYSBjb21tZW50IG9uIGlzc3VlIDY2
GHORG_GITLAB_TOKEN:
# flag (--namespace, -n)
GHORG_GITLAB_DEFAULT_NAMESPACE:
# clones repos in a directory structure that matches gitlab namespaces eg company/unit/subunit/app would clone into *_ghorg/unit/subunit/app
# default: false
# flag (--preserve-dir)