ghubcmd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApiCmd = &gcli.Command{
	Name: "api",
	Desc: "github api helper commands",
	Subs: []*gcli.Command{
		ApiCommitCmd,
		ApiTagCmd,
	},
}

ApiCmd groups github api commands.

View Source
var ApiCommitCmd = &gcli.Command{
	Name: "commit",
	Desc: "github commit api commands",
	Subs: []*gcli.Command{
		ApiCommitLatestCmd,
	},
}

ApiCommitCmd groups github commit api commands.

View Source
var ApiCommitLatestCmd = &gcli.Command{
	Name: "latest",
	Desc: "get latest commit info by github api",
	Help: `
# Examples:
  {$fullCmd} -r owner/repo
`,
	Config: func(c *gcli.Command) {
		c.StrOpt2(&apiLatestCommitOpts.RepoPath, "repo, r", "repository path, format: owner/repo")
	},
	Func: func(c *gcli.Command, _ []string) error {
		repoPath, err := apiLatestCommitOpts.toInput()
		if err != nil {
			return err
		}

		gh := app.Ghub()
		if strutil.IsBlank(gh.Token) {
			return c.NewErr("github token is empty, please configure github.token or GITHUB_PA_TOKEN")
		}

		info, err := gh.GetLatestCommit(repoPath)
		if err != nil {
			return err
		}

		show.AList("latest github commit", map[string]any{
			"Repo":    repoPath,
			"SHA":     info.SHA,
			"Author":  info.Commit.Author.Name,
			"Email":   info.Commit.Author.Email,
			"Date":    info.Commit.Author.Date,
			"Message": info.Commit.Message,
			"URL":     info.HTMLURL,
		})
		return nil
	},
}

ApiCommitLatestCmd gets latest commit info by github api.

View Source
var ApiTagAddCmd = &gcli.Command{
	Name: "add",
	Desc: "create annotated tag by github api, similar to `git tag -a`",
	Help: `
# Examples:
  {$fullCmd} -r owner/repo --sha abc123 -v v1.2.3 -m "release v1.2.3"
  {$fullCmd} -r owner/repo --sha abc123 -v 1.2.3 -m "release v1.2.3" --tagger-name kite --tagger-email kite@example.com
`,
	Config: func(c *gcli.Command) {
		apiTagAddOpts.BindProxyConfirm(c)
		c.BoolOpt(&apiTagAddOpts.DryRun, "dry-run", "dry", false, "run workflow, but dont real execute command")
		c.StrOpt2(&apiTagAddOpts.RepoPath, "repo, r", "repository path, format: owner/repo")
		c.StrOpt(&apiTagAddOpts.SHA, "sha", "", "target commit sha")
		c.StrOpt2(&apiTagAddOpts.Version, "version, v", "tag version, eg: v2.0.1")
		c.StrOpt2(&apiTagAddOpts.Message, "message, m", "annotated tag message")
		c.StrOpt(&apiTagAddOpts.TaggerName, "tagger-name", "", "tagger name for annotated tag")
		c.StrOpt(&apiTagAddOpts.TaggerEmail, "tagger-email", "", "tagger email for annotated tag")
	},
	Func: func(c *gcli.Command, _ []string) error {
		gh := app.Ghub()
		if strutil.IsBlank(gh.Token) {
			return c.NewErr("github token is empty, please configure github.token or GITHUB_PA_TOKEN")
		}

		in, err := apiTagAddOpts.resolveCreateInput(gh)
		if err != nil {
			return err
		}

		show.AList("create github tag", map[string]any{
			"Repo":         in.RepoPath,
			"SHA":          in.Object,
			"Version":      in.Version,
			"Message":      in.Message,
			"Tagger Name":  in.Tagger.Name,
			"Tagger Email": in.Tagger.Email,
			"Dry Run":      apiTagAddOpts.DryRun,
		})

		if apiTagAddOpts.DryRun {
			return nil
		}

		resp, err := gh.CreateAnnotatedTag(in)
		if err != nil {
			return err
		}

		colorp.Successf("Successful create github tag: %s\n", in.Version)
		if resp.Ref != "" {
			colorp.Infof("Created ref: %s\n", resp.Ref)
		}
		if resp.Object.SHA != "" {
			colorp.Infof("Tag object SHA: %s\n", resp.Object.SHA)
		}
		return nil
	},
}

ApiTagAddCmd creates an annotated tag by GitHub API.

View Source
var ApiTagCmd = &gcli.Command{
	Name: "tag",
	Desc: "github tag api commands",
	Subs: []*gcli.Command{
		ApiTagAddCmd,
		ApiTagListCmd,
	},
}

ApiTagCmd groups github tag api commands.

View Source
var ApiTagListCmd = &gcli.Command{
	Name:    "list",
	Aliases: []string{"ls"},
	Desc:    "list tags by github api",
	Help: `
# Examples:
  {$fullCmd} -r owner/repo
  {$fullCmd} -r owner/repo --limit 10
`,
	Config: func(c *gcli.Command) {
		c.StrOpt2(&apiTagListOpts.RepoPath, "repo, r", "repository path, format: owner/repo")
		c.IntOpt2(&apiTagListOpts.Limit, "limit, l", "max tags count for listing")
	},
	Func: func(c *gcli.Command, _ []string) error {
		in, err := apiTagListOpts.toInput()
		if err != nil {
			return err
		}

		gh := app.Ghub()
		if strutil.IsBlank(gh.Token) {
			return c.NewErr("github token is empty, please configure github.token or GITHUB_PA_TOKEN")
		}

		items, err := gh.ListTags(in)
		if err != nil {
			return err
		}

		if len(items) == 0 {
			colorp.Infof("No tags found for the repository: %s\n", in.RepoPath)
			return nil
		}

		colorp.Infof("Tags for the repository %s:\n", in.RepoPath)
		for _, item := range items {
			line := "  " + item.Name
			if item.Commit.SHA != "" {
				line += "  " + item.Commit.SHA
			}
			colorp.Cyanf("%s\n", line)
		}
		return nil
	},
}

ApiTagListCmd lists tags by github api.

View Source
var DownloadAssetCmd = &gcli.Command{
	Name:    "down",
	Desc:    "checkout an new branch for development from `source` remote",
	Aliases: []string{"download"},
	Func: func(c *gcli.Command, args []string) error {

		return errorx.New("TODO")
	},
}

DownloadAssetCmd instance

View Source
var GhOpts = struct {
	gitcmd.AutoGitDir
	cmdbiz.CommonOpts
}{}

GhOpts object

View Source
var GithubCmd = &gcli.Command{
	Name:    "github",
	Aliases: []string{"gh", "hub", "ghub"},
	Desc:    "useful tools for use github",
	Subs: []*gcli.Command{
		ApiCmd,
		DownloadAssetCmd,
		gitcmd.NewPullRequestCmd(),
		gitcmd.BatchCmd,
		gitcmd.NewBranchCmd(),
		gitcmd.NewCloneCmd(configProvider),
		gitcmd.NewAddCommitCmd(),
		gitcmd.NewAddCommitPush(),
		gitcmd.NewUpdateCmd(),
		gitcmd.NewUpdatePushCmd(),
		gitcmd.NewOpenRemoteCmd(configProvider),
	},
	Config: func(c *gcli.Command) {
		GhOpts.BindCommonFlags(c)
		GhOpts.BindChdirFlags(c)

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

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

GithubCmd commands

Functions

This section is empty.

Types

type ApiTagAddOptionsForTestType

type ApiTagAddOptionsForTestType = apiTagAddOptions

ApiTagAddOptionsForTestType exports test-only option shape.

var ApiTagAddOptionsForTest ApiTagAddOptionsForTestType

ApiTagAddOptionsForTest provides test access for input normalization.

func (*ApiTagAddOptionsForTestType) ToCreateInputForTest

func (o *ApiTagAddOptionsForTestType) ToCreateInputForTest() (ghapi.TagCreateInput, error)

ToCreateInputForTest converts options to API input in tests.

Jump to

Keyboard shortcuts

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