git-cnb, 一个 cnb 专属的 Git 命令行扩展工具, 可以使用 git 命令行的方式在终端快捷查看 cnb 的信息,比如仓库,用户,issue,pr,release 等等。
二进制安装 [荐]
curl https://cnb.cool/looc/git-cnb/-/git/raw/main/install.sh -sSfL | sh
使用 golang 安装
go install cnb.cool/looc/git-cnb@latest
作为 git 的一个扩展子命令行工具来使用。
NOTE: 由于需要调用 CNB 的 openapi 获取相关信息,所以需要使用环境变量来配置 CNB 的 Token, token 的权限取决于使用到的功能,可按需来配置 token 权限。
$ export CNB_TOKEN="... your token ..."
如果你同时需要操作多个域名不同的 CNB, 可以为每个域名配置不同的 CNB_TOKEN,规则为 CNB_TOKEN_{domain-without-dot}(环境变量不支持., 这里使用域名去掉.的后缀来区分,比如
$ export CNB_TOKEN_cnbcool=".. your token ..." #cnb.cool $ export CNB_TOKEN_cnbdev=".. your token ..." #cnb.dev
TOKEN至少需要如下权限:
repo-notes:r
repo-pr:r
repo-code:rw
repo-basic-info:r
account-profile:r
group-manage:rw
你也可以再云原生构建中使用 git-cnb, 默认使用云原生构建的环境变量 CNB_TOKEN, 如果默认的 TOKEN 权限不满足你的需求,可以手动指定,比如使用 CNB_TOKEN_cnbcool。
stages: - name: build jobs: - name: 使用 git-cnb image: docker.cnb.cool/looc/git-cnb:latest script: git-cnb -h
$ git cnb -h
Available Commands:
commit Manage commits
completion Generate the autocompletion script for the specified shell
download Download raw files from repository
groups Manage gruops
help Help about any command
info Print information of this repo
issue Manage issue
knowledges Manage knowledges
pull Manage pull requests
release Manage releases
stars Print star trend info of this repo
stats Print stats information of this repo
version Print the version number of git-cnb
Flags:
--domain string domain, eg: cnb.cool, default: cnb.cool
-h, --help help for git-cnb
--repo string repo name, eg: looc/git-cnb
如果你是在一个 git 目录下使用,git-cnb 会自动解析当前仓库的信息,获取到 api 的 domain 以及 reponame。
你也可以手动指定 domain 和 reponame, 比如: git cnb --domain=cnb.cool --repo=looc/git-cnb stars
git-cnb 也提供了一些 cnb 插件,你可以使用插件来快速完成一些复杂的任务。