Li Hui Blog

Li Hui Blog
在时代的层林尽染中书写时代的年华。效能(2022)
  1. 首页
  2. Linux
  3. CLI应用
  4. 正文

[CLI应用学习]时间使用GitHub CLI

9月 21, 2020 462点热度 0人点赞 0条评论

前言

不久前 GitHub发布了自己的CLI应用,不得不多说,在微软收购GitHub迎来的大的进步,近期出现了很多很多的大动作,发布CLI应用,发布移动端的应用等等,虽然不一定和微软有必然关系,不过GitHub最近确实不错。本期主要是学习GitHub CLI 的应用,并分析GitHub CLI的优缺点。

问题前置: GitHub api 好像不是那么好连接 要想办法的。

内容

首先展示GitHub CLI 的功能 支持整个的工作流(处理issue 拉取请求 check 发行 和更多) 脚本和个性化 商业同样适用 代码开源

ZXgPoA

首先我们来进行安装 本次采用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)-> 开发者->

image-20200920222758765

8ARrPY

hi3msq

在此处生成token 然后给予相应的权限(推荐给予部分权限,熟练者可以给予全部权限,权限问题,很严重的呀)

UC7wfe

本文示例中 我只给予了token仓库和读组织的的权限(CLI 应用要求的最小的权限),其他的权限都没有给,应该此次使用不会涉及到太多其他方面的问题。

然后点击生成token 因为token只保留一次 记得要保存(安全期间可以不保存,毕竟连你都不知道,其他人更不知道了)

进入登陆环节

$ gh auth login

返回结果

8Im1NS

此时选择第一个 商业服务器选择第二个

而后开始选择登陆方式[两种 第一种通过浏览器登录 第二种通过 token登陆],我们前面申请了token 此处使用token登陆。

OIYtNE

而后填入自己的token

2o9WYP

注意此处最小的权限是repo和读取组织权限

此后是通过何种方式进行连接(我个人比较倾向于ssh连接方式)

SwiKa1

此时连接建立完成✅

整体流程如下图所示

qyu7f0

我们可以发现 这个登陆的流程相对来说比较简单 此时账号已经登陆上去了。

指令表格

因为GitHub是和Git仓库是相连的,因此需要在Git仓库中使用(且仓库链接到远程的GitHub)

GH命令官网 https://cli.github.com/manual/

全部命令如下表

一级指令 二级指令
alias
delete
list
set
api
auth
login
logout
refresh
status
completion
config
get
set
gist
create
edit
list
view
issue
close
create
list
reopen
status
view
pr
checkout
checks
close
create
diff
list
merge
ready
reopen
review
status
view
release
create
delete
download
list
upload
view
repo
clone
create
fork
view

简单演示

因为指令相对来说较多 只使用其中几个演示。

显示GitHub仓库信息

切换到连接到GitHub的仓库,使用下面的命令行

命令行

$ gh repo view

返回结果

eqYJm5

显示issue

同样在上述的仓库 使用下面的命令行

$ gh issue list

返回结果

M3AAGQ

总结

优点: 可以使用命令行操作GitHub的内容,比较的简单,比较快速就可以使用,较为友好。

缺点: 当前应用还存在一些问题 例如 gh release create 在使用brew安装的时候无法使用。显示只有这些指令( alias api auth completion config gist help issue pr repo)可以使用。

总体感觉还是不错的,希望GitHub可以将这个应用越做越好。

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: CLI GitHub
最后更新:9月 21, 2020

Li Hui

这个人很懒,什么都没留下

点赞
下一篇 >

文章评论

取消回复

Li Hui

这个人很懒,什么都没留下

归档
  • 2022年10月 / 1篇
  • 2022年6月 / 1篇
  • 2022年1月 / 6篇
  • 2021年2月 / 1篇
  • 2021年1月 / 8篇
  • 2020年12月 / 1篇
  • 2020年11月 / 2篇
  • 2020年9月 / 23篇
分类
  • Git系列 / 6篇
  • Linux / 10篇
    • CLI应用 / 2篇
    • Docker / 1篇
  • Shell / 2篇
  • Uncategorized / 1篇
  • 从0到1 / 1篇
  • 博客优化 / 3篇
  • 各系列总章节 / 1篇
  • 周年总结 / 1篇
  • 安全 / 2篇
  • 年度总结 / 1篇
  • 年度计划 / 1篇
  • 感想 / 3篇
  • 技术 / 2篇
    • gocd / 1篇
  • 敏捷开发 / 1篇
  • 未分类 / 6篇
  • 知识 / 1篇
  • 读书 / 3篇

COPYRIGHT © 2021 lihui.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

京ICP备2020048539号-3