Skip to content

Commit

Permalink
fork: rename namespace to group
Browse files Browse the repository at this point in the history
The (sub)group support is being added to project creation and 'group' is the
name being used there, which is easier to understand for the general users,
with no gitlab internals knowledge. With that, it's better to rename the
already supported feature on fork.

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Dec 23, 2020
1 parent 98db094 commit b34ae86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions cmd/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var forkCmd = &cobra.Command{
noWaitFork, _ := cmd.Flags().GetBool("no-wait")
waitFork = !noWaitFork
forkData.TargetName, _ = cmd.Flags().GetString("name")
forkData.TargetNamespace, _ = cmd.Flags().GetString("namespace")
forkData.TargetGroup, _ = cmd.Flags().GetString("group")
forkData.TargetPath, _ = cmd.Flags().GetString("path")

if len(args) == 1 {
Expand All @@ -43,8 +43,8 @@ var forkCmd = &cobra.Command{
func forkFromOrigin(cmd *cobra.Command, args []string) {
// Check for custom target namespace
remote := lab.User()
if forkData.TargetNamespace != "" {
remote = forkData.TargetNamespace
if forkData.TargetGroup != "" {
remote = forkData.TargetGroup
}

if _, err := gitconfig.Local("remote." + remote + ".url"); err == nil {
Expand Down Expand Up @@ -106,8 +106,8 @@ func forkToUpstream(cmd *cobra.Command, args []string) {
// the clone may happen in a different name/path when compared to
// the original source project
namespace := ""
if forkData.TargetNamespace != "" {
namespace = forkData.TargetNamespace + "/"
if forkData.TargetGroup != "" {
namespace = forkData.TargetGroup + "/"
}

name := forkData.SrcProject
Expand All @@ -125,8 +125,8 @@ func forkToUpstream(cmd *cobra.Command, args []string) {

func determineForkRemote(project string) string {
name := lab.User()
if forkData.TargetNamespace != "" {
name = forkData.TargetNamespace
if forkData.TargetGroup != "" {
name = forkData.TargetGroup
}
if strings.Split(project, "/")[0] == name {
// #78 allow upstream remote to be added when "origin" is
Expand All @@ -140,7 +140,7 @@ func init() {
forkCmd.Flags().BoolP("skip-clone", "s", false, "skip clone after remote fork")
forkCmd.Flags().Bool("no-wait", false, "don't wait for forking operation to finish")
forkCmd.Flags().StringP("name", "n", "", "fork project with a different name")
forkCmd.Flags().StringP("namespace", "m", "", "fork project in a different namespace")
forkCmd.Flags().StringP("group", "g", "", "fork project in a different group (namespace)")
forkCmd.Flags().StringP("path", "p", "", "fork project with a different path")
// useHTTP is defined in "project_create.go"
forkCmd.Flags().BoolVar(&useHTTP, "http", false, "fork using HTTP protocol instead of SSH")
Expand Down
16 changes: 8 additions & 8 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ func FindProject(project string) (*gitlab.Project, error) {
}

type ForkStruct struct {
SrcProject string
TargetName string
TargetNamespace string
TargetPath string
SrcProject string
TargetName string
TargetGroup string
TargetPath string
}

// isCustomTargetSet checks if at least one destination value is set
func (fs ForkStruct) isCustomTargetSet() bool {
return fs.TargetName != "" || fs.TargetNamespace != "" || fs.TargetPath != ""
return fs.TargetName != "" || fs.TargetGroup != "" || fs.TargetPath != ""
}

// Fork creates a user fork of a GitLab project using the specified protocol
Expand All @@ -234,8 +234,8 @@ func Fork(data ForkStruct, useHTTP bool, wait bool) (string, error) {
name := parts[1]
namespace := ""
if data.isCustomTargetSet() {
if data.TargetNamespace != "" {
namespace = data.TargetNamespace + "/"
if data.TargetGroup != "" {
namespace = data.TargetGroup + "/"
}
// Project name takes precedence over path for finding a project
// on Gitlab through API
Expand Down Expand Up @@ -273,7 +273,7 @@ func Fork(data ForkStruct, useHTTP bool, wait bool) (string, error) {
}
forkOpts = &gitlab.ForkProjectOptions{
Name: gitlab.String(data.TargetName),
Namespace: gitlab.String(data.TargetNamespace),
Namespace: gitlab.String(data.TargetGroup),
Path: gitlab.String(data.TargetPath),
}
}
Expand Down

0 comments on commit b34ae86

Please sign in to comment.