前言
不久前 GitHub发布了自己的CLI应用,不得不多说,在微软收购GitHub迎来的大的进步,近期出现了很多很多的大动作,发布CLI应用,发布移动端的应用等等,虽然不一定和微软有必然关系,不过GitHub最近确实不错。本期主要是学习GitHub CLI 的应用,并分析GitHub CLI的优缺点。
问题前置: GitHub api 好像不是那么好连接 要想办法的。
内容
首先展示GitHub CLI 的功能 支持整个的工作流(处理issue 拉取请求 check 发行 和更多) 脚本和个性化 商业同样适用 代码开源
首先我们来进行安装 本次采用MacBook来安装 命令如下:
$ brew install gh
此处因为某些原因brew的下载速度不是很理想,可以采用换用清华的源进行调整https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/ 其中可能会遇到一些其他的问题 比如brew link gh 显示权限不足 可以 chmod 77 {{提示的路径}} 而后再次运行 brew link gh即可
安装完成后即可以使用
gh
返回结果
Work seamlessly with GitHub from the command line.
USAGE
gh <command> <subcommand> [flags]
CORE COMMANDS
issue: Manage issues
pr: Manage pull requests
repo: Create, clone, fork, and view repositories
ADDITIONAL COMMANDS
alias: Create command shortcuts
api: Make an authenticated GitHub API request
auth: Login, logout, and refresh your authentication
completion: Generate shell completion scripts
config: Manage configuration for gh
gist: Create gists
help: Help about any command
FLAGS
--help Show help for command
--version Show gh version
EXAMPLES
$ gh issue create
$ gh repo clone cli/cli
$ gh pr checkout 321
ENVIRONMENT VARIABLES
GITHUB_TOKEN: an authentication token for github.com API requests. Setting this avoids
being prompted to authenticate and takes precedence over previously stored credentials.
GITHUB_ENTERPRISE_TOKEN: an authentication token for API requests to GitHub Enterprise.
GH_REPO: specify the GitHub repository in the "[HOST/]OWNER/REPO" format for commands
that otherwise operate on a local repository.
GH_HOST: specify the GitHub hostname for commands that would otherwise assume
the "github.com" host when not in a context of an existing repository.
GH_EDITOR, GIT_EDITOR, VISUAL, EDITOR (in order of precedence): the editor tool to use
for authoring text.
BROWSER: the web browser to use for opening links.
DEBUG: set to any value to enable verbose output to standard error. Include values "api"
or "oauth" to print detailed information about HTTP requests or authentication flow.
GLAMOUR_STYLE: the style to use for rendering Markdown. See
https://github.com/charmbracelet/glamour#styles
NO_COLOR: avoid printing ANSI escape sequences for color output.
LEARN MORE
Use "gh <command> <subcommand> --help" for more information about a command.
Read the manual at https://cli.github.com/manual
FEEDBACK
Open an issue using “gh issue create -R cli/cli”
使用CLI 登陆
命令行
gh auth login {{token}} #token 获取的方式如下面所示
获取的token |
---|
1. 登陆GitHub的网站 设置(setting)-> 开发者-> |
在此处生成token 然后给予相应的权限(推荐给予部分权限,熟练者可以给予全部权限,权限问题,很严重的呀)
本文示例中 我只给予了token仓库和读组织的的权限(CLI 应用要求的最小的权限),其他的权限都没有给,应该此次使用不会涉及到太多其他方面的问题。
然后点击生成token 因为token只保留一次 记得要保存(安全期间可以不保存,毕竟连你都不知道,其他人更不知道了)
进入登陆环节
$ gh auth login
返回结果
此时选择第一个 商业服务器选择第二个
而后开始选择登陆方式[两种 第一种通过浏览器登录 第二种通过 token登陆],我们前面申请了token 此处使用token登陆。
而后填入自己的token
注意此处最小的权限是repo和读取组织权限
此后是通过何种方式进行连接(我个人比较倾向于ssh连接方式)
此时连接建立完成✅
整体流程如下图所示
我们可以发现 这个登陆的流程相对来说比较简单 此时账号已经登陆上去了。
指令表格
因为GitHub是和Git仓库是相连的,因此需要在Git仓库中使用(且仓库链接到远程的GitHub)
GH命令官网 https://cli.github.com/manual/
全部命令如下表
简单演示
因为指令相对来说较多 只使用其中几个演示。
显示GitHub仓库信息
切换到连接到GitHub的仓库,使用下面的命令行
命令行
$ gh repo view
返回结果
显示issue
同样在上述的仓库 使用下面的命令行
$ gh issue list
返回结果
总结
优点: 可以使用命令行操作GitHub的内容,比较的简单,比较快速就可以使用,较为友好。
缺点: 当前应用还存在一些问题 例如 gh release create 在使用brew安装的时候无法使用。显示只有这些指令( alias api auth completion config gist help issue pr repo)可以使用。
总体感觉还是不错的,希望GitHub可以将这个应用越做越好。
文章评论