gitee_cli/README.md

272 lines
8.6 KiB
Markdown
Raw Permalink Normal View History

2024-04-07 17:49:39 +08:00
## Gitee CLI
> 诞生背景:对于开发者来说,日常的开发往往离不开 terminal以往的流程一般是编写代码 -> 提交代码 -> 创建 Pull Request -> 测试 -> Bug Fix -> 重新测试 -> 测试通过 -> Code Review -> 合入主线,
> 创建 Pull Request 等一系列动作往往只能在 web 端进行操作往往需要切换上下文Gitee CLI 因而诞生,旨在减少上下文的切换.
## 部分功能示例
![img.png](doc/images/preview.png)
## Usage
### 构建方式
2024-04-07 20:47:49 +08:00
#### Homebrew 安装
> 目前暂时还未向官方仓库提交 formula 文件,需手动添加 tab
```shell
brew tap JJ-H/tap
brew install gitee
```
#### 手动安装
2024-04-07 17:49:39 +08:00
```shell
git clone https://github.com/JJ-H/gitee_cli.git
cd gitee_cli
mkdir $HOME/.gitee
cp config/config.yml.example $HOME/.gitee/config.yml
go build -o bin/gitee main.go
sudo cp ./bin/gitee /usr/local/bin/gitee
```
### 配置说明
```shell
# 个人私人令牌,用于 V5 鉴权
access_token: xxxxxxxx
api_prefix: https://gitee.com/api/v5
# 用户在 Gitee 上的 ID
user_id: xxxxx
# 用户名
user_name: xxx
# 非仓库目录下执行 gitee cli 命令默认仓库全路径(配置你比较常用的仓库)
2024-04-09 20:46:50 +08:00
default_path_with_namespace: test/test
2024-04-07 17:49:39 +08:00
# cookie 用于企业版 API 鉴权(由于加密登录的问题,此处暂时需要手动复制 cookie[可使用 gitee config cookie xxxxxx]
cookies_jar: xxxxxxx
```
#### 可通过 gitee config [key] [value] 的方式设置
```shell
gitee config access_token xxxxxx
# 用户 ID 可使用如下命令查询(请精准输入你的username)
➜ ~ gitee user search JJ-H
用户 ID7484706
用户名称JJ-H
用户主页https://gitee.com/JJ-H
```
### Tab 自动补全!!!(强烈建议不要跳过这一步)
> 得益于框架的优秀设计Gitee CLI 支持快速生成 Tab 自动补全脚本,目前支持 bash、fish、powershell、zsh
```shell
➜ ~ gitee completion --help
Generate the autocompletion script for gitee for the specified shell.
See each sub-command's help for details on how to use the generated script.
Usage:
gitee completion [command]
Available Commands:
bash Generate the autocompletion script for bash
fish Generate the autocompletion script for fish
powershell Generate the autocompletion script for powershell
zsh Generate the autocompletion script for zsh
Flags:
-h, --help help for completion
Use "gitee completion [command] --help" for more information about a command.
```
#### 下面以 zsh 为例
```shell
# Linux 用户
gitee completion zsh > "${fpath[1]}/_gitee"
# 执行完毕后在 ~/.zshrc 中增加如下语句:
source ${fpath[1]}/_gitee
# macOS 用户
gitee completion zsh > $(brew --prefix)/share/zsh/site-functions/_gitee
# 执行完毕后在 ~/.zshrc 中增加如下语句:
source $(brew --prefix)/share/zsh/site-functions/_gitee
```
重启终端,输入 gitee 按下 tab您将得到如下自动补全提示子命令同样支持
```shell
➜ ~ gitee [press tab]
auth -- Authenticate Gitee CLI with gitee selector
build -- Build a k8s pod by note a specified pull request
completion -- Generate the autocompletion script for the specified shell
config -- Manage Gitee CLI config, Usage: config key [value]
selector -- Manage enterprises
help -- Help about any command
lightPr -- Create a lightPr
pr -- Manage pull requests
ssh-key -- Manage ssh-keys
user -- User related command
```
### 使用方式
```shell
➜ ~ gitee --help
Gitee CLI is a tool which interact with gitee server seamlessly via terminal
Usage:
gitee [command]
Available Commands:
auth Authenticate Gitee CLI with gitee selector_tui
completion Generate the autocompletion script for the specified shell
config Manage Gitee CLI config, Usage: config key [value]
enterprise Manage enterprises
help Help about any command
issue Manage issues
pr Manage pull requests
ssh-key Manage ssh-keys
user User related command
Flags:
-h, --help help for gitee
-v, --version version for gitee
Use "gitee [command] --help" for more information about a command.
```
### Auth 相关
```shell
➜ ~ gitee auth --help
Authenticate Gitee CLI with gitee selector
Usage:
gitee auth [flags]
Flags:
-f, --cookies-file string path to a file containing cookies
-h, --help help for auth
```
### Config 相关
```shell
➜ ~ gitee config --help
Manage Gitee CLI config, Usage: config key [value]
Usage:
gitee config [flags]
Flags:
-h, --help help for config
```
### Pull Request 相关
- 列出当前所在仓库下我审查的 Pull Request `gitee pr list [flags]`
> 说明:列表模式下,按 c 将拷贝 pull request iid 至粘贴板,按 v 预览详情,按 d 预览 diff回车使用浏览器打开
2024-04-16 00:48:37 +08:00
![img.png](doc/images/gitee_pr.gif)
2024-04-07 17:49:39 +08:00
- 根据 commit 找到对应的被合入至当前分支的 Pull Request `gitee pr list -c <commit>`
```shell
2024-04-16 10:08:24 +08:00
➜ ~ gitee pr list -c "80b4ef95c0d"
2024-04-07 17:49:39 +08:00
请在仓库目录下执行该命令!
➜ ~ cd /home/git/gitee
2024-04-16 10:08:24 +08:00
➜ gitee (master) ✔ gitee pr list -c "80b4ef95c0d"
2024-04-07 17:49:39 +08:00
该 commit 由 PR: 「修改仓库模糊查询支持namespace级联查询修复全英文字符查询时只匹配path问题」 合入,访问地址: https://gitee.com/hightest/settings/pulls19977
```
- 创建 pull_request
```shell
➜ ~ gitee pr create
请输入标题feature -> master
请输入目标分支master
? 填写 Pull Request 内容 <Received>
创建 PR「feature -> master」 成功访问地址https://gitee.com/hightest/settings/pulls/3
```
- 评论 Pull request一般用于触发 webhook
```shell
➜ gitee (master) ✔ gitee pr note -i 19995 /approve
评论成功!
```
2024-04-16 10:08:24 +08:00
- 评审通过 Pull Request
```shell
➜ gitee (master) ✔ gitee pr review 19995
审查通过🏅
```
- 关闭 Pull Request
```shell
➜ gitee (master) ✔ gitee pr close 19995
关闭 PR 成功🏅
```
2024-04-07 17:49:39 +08:00
### Issue 相关
- 创建 issue
```shell
➜ ~ gitee issue create --feature
请选择要创建的任务类型
> 需求
Press q to quit.
请输入标题 这是需求标题
? 填写 Issue 描述 <Received>
创建工作项 「需这是需求标题」成功访问地址https://gitee.com/kepler-planet-wireless/dashboard/issues?id=I9A7ZY
```
- issue 列表
2024-04-16 00:48:37 +08:00
> 说明:列表模式下,按 c 将拷贝 issue ident 至粘贴板,按 v 预览详情,按 s 变更状态,回车使用浏览器打开
2024-04-07 17:49:39 +08:00
2024-04-16 00:48:37 +08:00
![img.png](doc/images/gitee_issue.gif)
2024-04-07 17:49:39 +08:00
### SSH Key 相关
```shell
➜ ~ gitee ssh-key --help
Manage ssh-keys
Usage:
gitee ssh-key [command]
Available Commands:
add Add a ssh pub key for personal
delete delete a specified ssh key
list List personal ssh pub keys
Flags:
-h, --help help for ssh-key
Use "gitee ssh-key [command] --help" for more information about a command.
```
- 获取当前账户所有已上传的公钥 `gitee ssh-key list`
```shell
➜ gitee (master) ✔ gitee ssh-key list
+--------------+----------------------------------------------------+--------------------------------+
| SSH KEY ID | KEY SHA | PREVIEW URL |
+--------------+----------------------------------------------------+--------------------------------+
| 3123223 | ssh-rsa AAAAB3NzaC1yc2EAAAADAAXCSAABAQC6r/S6pJsv8x | https://gitee.com/keys/3123223 |
| 3233333 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQ786AABgQCgiABu1TWbSI | https://gitee.com/keys/3233333 |
| 3242234 | ssh-ed25519 AAAAC3NzaC1lZDI1N765SAAAIISV/On6vy1UNg | https://gitee.com/keys/3242234 |
| 2322332 | ssh-rsa AAAAB3NzaC1yc2EAAAADAADSDAABAQCpKcep+/DlEb | https://gitee.com/keys/2322332 |
| 1233562 | ssh-ed25519 AAAAC3NzaC1lZDIASDSASAAAIA9aZBvftMp1dT | https://gitee.com/keys/1233562 |
+--------------+----------------------------------------------------+--------------------------------+
```
- 添加本地 ssh pub key
```shell
➜ ~ gitee ssh-key add -t "Macbook Pro"
请选择要上传的 SSH 公钥
/Users/JJ-H/.ssh/hexo-deploy-key.pub
/Users/JJ-H/.ssh/id_ed25519.pub
> /Users/JJ-H/.ssh/id_rsa.pub
Press q to quit.
添加 ssh key 「Macbook Pro」 成功访问地址https://gitee.com/keys/449311
```
- 删除已上传的ssh 公钥
```shell
➜ ~ gitee ssh-key delete 449311
删除公钥成功
```
### 其余功能各位自行通过 help 探索~
### 参考文献
- [A Git command to jump from a commit SHA to the PR on GitHub](https://tekin.co.uk/2020/06/jump-from-a-git-commit-to-the-pr-in-one-command)