glabcmd

package
v0.0.0-...-a91fe3a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GitLabCmd = &gcli.Command{
	Name:    "gitlab",
	Desc:    "useful tool commands for use gitlab",
	Aliases: []string{"gl", "glab"},
	Subs: []*gcli.Command{
		ResolveConflictCmd,
		MergeRequestCmd,
		gitcmd.BatchCmd,
		gitcmd.NewInitFlowCmd(),
		gitcmd.NewBranchCmd(),
		gitcmd.NewCheckoutCmd(),
		gitcmd.NewCloneCmd(configProvider),
		gitcmd.NewUpdateCmd(),
		gitcmd.NewUpdatePushCmd(),
		gitcmd.NewAddCommitPush(),
		gitcmd.NewAddCommitCmd(),
		gitcmd.NewOpenRemoteCmd(configProvider),
	},
	Config: func(c *gcli.Command) {
		glOpts.BindChdirFlags(c)

		c.On(events.OnCmdRunBefore, func(ctx *gcli.HookCtx) (stop bool) {
			wd := c.WorkDir()
			c.Infoln("[kite.GLAB] Workdir:", wd)
			return false
		})

		c.On(events.OnCmdSubNotFound, gitcmd.RedirectToGitx)
	},
}

GitLabCmd commands

View Source
var (

	// MergeRequestCmd command
	MergeRequestCmd = &gcli.Command{
		Name:    "merge-request",
		Aliases: []string{"pr", "mr", "pull-request"},
		Desc:    "Create new merge requests(PR/MR) by given project information",
		Config: func(c *gcli.Command) {
			mrOpts.BindCommonFlags(c)

			c.BoolOpt(&mrOpts.new, "new", "", false,
				"Open new PR page link on browser. eg: http://my.gitlab.com/group/repo/merge_requests/new",
			)
			c.BoolOpt2(&mrOpts.direct, "direct,d", "The PR is direct from fork to main repository")

			c.StrOpt(&mrOpts.openBr, "open", "o", "Set target branch and open PR link on browser")
			c.StrOpt(&mrOpts.source, "source", "s", "The source branch name, default is current `BRANCH`")
			c.StrOpt(&mrOpts.target, "target", "t", "The target branch name, default is current `BRANCH`")
			c.AddArg("repoPath", "The project name with path in self-host gitlab.\nif empty will fetch from workdir")
		},
		Help: `
Special:
  @, h, HEAD - Current branch name.
  @s         - Source branch name.
  @t         - Target branch name.
`,
		Examples: `
  {$binWithCmd}                       Will generate PR link for fork 'HEAD_BRANCH' to main 'HEAD_BRANCH'
  {$binWithCmd} -o h                  Will open PR link for fork 'HEAD_BRANCH' to main 'HEAD_BRANCH' on browser
  {$binWithCmd} -o qa                 Will open PR link for main 'HEAD_BRANCH' to main 'qa' on browser
  {$binWithCmd} -t qa                 Will generate PR link for main 'HEAD_BRANCH' to main 'qa'
  {$binWithCmd} -t qa --direct        Will generate PR link for fork 'HEAD_BRANCH' to main 'qa'
  # Will generate PR link for 'group/repo', from 'dev' to 'qa' branch
  {binWithCmd} -o dev -t qa group/repo
`,
		Func: mergeRequestHandle,
	}
)
View Source
var ResolveConflictCmd = &gcli.Command{
	Name: "resolve",
	Desc: "Resolve conflicts preparing for current git branch.",
	Help: `Workflow:
1. will checkout to <cyan>branch</cyan>
2. will update code by <cyan>git pull</cyan>
3. update the <cyan>branch</cyan> codes from source repository
4. merge current-branch codes from source repository
5. please resolve conflicts by tools or manual
`,
	Aliases: []string{"rc"},
	Config: func(c *gcli.Command) {
		rcOpts.BindCommonFlags(c)

		c.AddArg("branch", "The conflicts target branch name. eg: qa, pre, master", true)
	},
	Func: func(c *gcli.Command, args []string) error {
		gl := app.Glab()
		lr := gl.LoadRepo(rcOpts.Workdir)

		curBr := lr.CurBranchName()
		br := c.Arg("branch").String()
		br = lr.ResolveAlias(br)

		rr := cmdutil.NewRunner(func(rr *cmdutil.Runner) {
			rr.Workdir = rcOpts.Workdir
			rr.DryRun = rcOpts.DryRun
		})

		rr.GitCmd("fetch", "-np", gl.DefaultRemote)
		rr.GitCmd("fetch", "-np", gl.SourceRemote)

		if lr.HasLocalBranch(br) {
			rr.GitCmd("checkout", br)

			if lr.HasOriginBranch(br) {
				rr.GitCmd("pull", gl.DefaultRemote, br)
			} else {
				rr.GitCmd("push", "-u", gl.DefaultRemote, br)
			}

			rr.GitCmd("pull", gl.SourceRemote, br)
		} else if lr.HasOriginBranch(br) {

			rr.GitCmd("checkout", "--track", gl.OriginBranch(br)).
				GitCmd("pull", gl.SourceRemote, br)
		} else if lr.HasSourceBranch(br) {
			rr.GitCmd("checkout", "--track", gl.SourceBranch(br)).
				GitCmd("push", "-u", gl.DefaultRemote)
		} else {
			return c.NewErrf("branch %q not found in local and remotes", br)
		}

		if err := rr.Run(); err != nil {
			return err
		}
		c.Println("---------------------------------------------------------------------")

		_ = lr.Cmd("pull", gl.SourceRemote, curBr).Run()

		c.Println("---------------------------------------------------------------------")
		colorp.Successln("Now, please resolve conflicts by tools or manual ...")
		colorp.Infoln("TIP 1: If you want stop resolve, can run:\n  git merge --abort && git checkout", curBr)
		colorp.Warnln("TIP 2: Can execute follow command after resolved for quick commit:")
		colorp.Infoln("  git add . && git commit && git push && kite gl pr -o head && git checkout", curBr)
		return nil
	},
}

ResolveConflictCmd instance

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL