ghext

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReturnErr = iota
	ReturnBack
	ReturnComplete
)

Variables

View Source
var Cmd = &cli.Command{
	Category: "GitHub",
	Name:     "gh-mozhu",
	Aliases:  []string{"ghext"},
	Usage:    "A little toolkit using GitHub API",
	Commands: []*cli.Command{

		{
			Name:  "install",
			Usage: "Install this",
			Action: func(_ *cli.Context) (err error) {
				binName := path.Base(os.Args[0])
				if !strings.HasPrefix(binName, "gh-") {
					err = fmt.Errorf("extension name [%s] is error", binName)
					return
				}

				newPath := path.Join(ghConfig.DataDir(), "extensions", binName, binName)
				logger.Debug("gh extensions dir: ", newPath)
				err = utils.CopyFile(newPath, os.Args[0])
				if err != nil {
					return
				}
				logger.SuccessF("Installed: %s", newPath)
				return
			},
		},

		{
			Name:  "orgs",
			Usage: "List organizations for the authenticated user",
			Action: func(*cli.Context) (err error) {
				res, err := ListUserOrganizations()
				if err != nil {
					return
				}
				fmt.Println(res)
				return
			},
		},

		{
			Name:  "transfer",
			Usage: "Transfer a repository",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:     "owner",
					Aliases:  []string{"o"},
					Usage:    "The account owner of the repository",
					Required: true,
				},
				&cli.StringFlag{
					Name:     "repo",
					Aliases:  []string{"r"},
					Usage:    "The name of the repository",
					Required: true,
				},
				&cli.StringFlag{
					Name:     "new-owner",
					Aliases:  []string{"new", "n"},
					Usage:    "The username/organization whitch will be transferred to.",
					Required: true,
				},
			},
			Action: func(c *cli.Context) (err error) {
				res, err := TransferRepository(c.String("new-owner"), c.String("owner"), c.String("repo"))
				if err != nil {
					return
				}
				logger.Success(res)
				return
			},
		},
	},
}

Functions

func CommitTemplate

func CommitTemplate(typ int, scope, subject, body, footer string, isHideEmoji bool) (string, error)

func ListUserOrganizations

func ListUserOrganizations() (string, error)

func TransferRepository

func TransferRepository(newOwner, owner, repoName string) (res string, err error)

Types

type MessageTemplate

type MessageTemplate struct {
	Type MsgType
	Icon string
}

type MsgType

type MsgType int
const (
	Init MsgType = iota + 1
	Feat
	Fix
	Docs
	Style
	Perf
	Refactor
	Test
	Build
	CI
	Chore
	Revert
	Release
)

func (MsgType) String

func (i MsgType) String() string

type Organizations

type Organizations []struct {
	Login string `json:"login"`
}

type Transfer

type Transfer struct {
	NewOwner string `json:"new_owner"`
}

Transfer a repository

https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#transfer-a-repository

curl -L \
	-X POST \
	-H "Accept: application/vnd.github+json" \
	-H "Authorization: Bearer <YOUR-TOKEN>"\
	-H "X-GitHub-Api-Version: 2022-11-28" \
	https://api.github.com/repos/OWNER/REPO/transfer \
	-d '{"new_owner":"github","team_ids":[12,345],"new_name":"octorepo"}'

Jump to

Keyboard shortcuts

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