littlebot
Published on 2025-04-09 / 0 Visits
0

【源码】基于Go语言的Gitee命令行交互工具

项目简介

Gitee CLI 是一款面向开发者的命令行工具。在日常开发里,开发者在编写代码、提交代码、创建 Pull Request 等操作时需频繁切换上下文,且创建 Pull Request 等操作通常只能在 web 端进行。Gitee CLI 解决了这一痛点,让开发者能在 terminal 中无缝与 Gitee 服务器交互,减少上下文切换,提高开发效率。

项目的主要特性和功能

  1. 全流程命令行操作:覆盖从代码提交到 Pull Request 的创建、测试、审查、合入等开发常见操作,无需在 terminal 和 web 端频繁切换。
  2. 多功能管理:支持对 Pull Request、Issue、SSH Key 等进行管理,如创建、评论、关闭、评审 Pull Request,创建 Issue,管理 SSH 公钥等。
  3. 便捷配置:可通过 gitee config [key] [value] 轻松设置个人私人令牌、用户 ID、用户名等配置信息。
  4. 自动补全支持:支持为 bash、fish、powershell、zsh 等多种 shell 生成 Tab 自动补全脚本,提升操作便捷性。

安装使用步骤

安装

Homebrew 安装

目前需手动添加 tab: shell brew tap JJ-H/tap brew install gitee

手动安装

shell 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 access_token: xxxxxxxx api_prefix: https://gitee.com/api/v5 user_id: xxxxx user_name: xxx default_path_with_namespace: test/test cookies_jar: xxxxxxx 可通过 gitee config [key] [value] 的方式设置,例如: shell gitee config access_token xxxxxx 用户 ID 可使用如下命令查询(请精准输入你的 username): shell ➜ ~ gitee user search JJ-H 用户 ID:7484706 用户名称:JJ-H 用户主页:https://gitee.com/JJ-H

Tab 自动补全设置(以 zsh 为例)

Linux 用户

shell gitee completion zsh > "${fpath[1]}/_gitee" source ${fpath[1]}/_gitee

macOS 用户

shell gitee completion zsh > $(brew --prefix)/share/zsh/site-functions/_gitee source $(brew --prefix)/share/zsh/site-functions/_gitee 重启终端,输入 gitee 按下 tab 即可享受自动补全提示。

使用示例

Pull Request 相关

  • 列出当前所在仓库下我审查的 Pull Request:gitee pr list [flags]
  • 根据 commit 找到对应的被合入至当前分支的 Pull Request:gitee pr list -c <commit>
  • 创建 pull_request:gitee pr create
  • 评论 Pull request:gitee pr note -i [iid] [comment]
  • 评审通过 Pull Request:gitee pr review [iid]
  • 关闭 Pull Request:gitee pr close [iid]

Issue 相关

  • 创建 issue:gitee issue create --feature
  • 查看 issue 列表:gitee issue list

SSH Key 相关

  • 获取当前账户所有已上传的公钥:gitee ssh-key list
  • 添加本地 ssh pub key:gitee ssh-key add -t "Macbook Pro"
  • 删除已上传的 ssh 公钥:gitee ssh-key delete [key_id]

下载地址

点击下载 【提取码: 4003】【解压密码: www.makuang.net】