用于获取 Git 提交信息并将其存储在配置文件中的 CLI 工具
项目描述
Git 应用版本
一个用 Python 编写的 CLI 工具,用于获取 Git 提交信息并将它们存储在配置文件中。
支持的格式:
- JSON
- YAML
- XML
- INI
- CSV
- Shell 脚本变量
典型用例:部署时,运行此命令并导入 git 版本配置文件。
要求
- Python 2.7 或 >= 3.4
- python pip打包工具
安装
赶紧跑 :
pip install git-app-version
或者下载Linux amd64 的最新二进制版本:
wget https://github.com/csanquer/git-app-version/releases/download/v1.0.0/git-app-version_linux_amd64.tar.gz
tar -xvzf git-app-version_linux_amd64.tar.gz
sudo mv git-app-version /usr/local/bin/
sudo chmod a+x /usr/local/bin/git-app-version
用法
帮助
寻求帮助
git-app-version -h
帮助结果
Usage: git-app-version [OPTIONS] [REPOSITORY] [COMMIT]
Get Git commit informations and store them in a config file
REPOSITORY git repository path, Default is the current directory.
COMMIT git commit to check, Default is HEAD.
Options:
-V, --version
-q, --quiet silent mode
-o, --output TEXT output file path (without extension).
Default is '<repository-path>/version'.
-f, --format [all|json|yml|xml|ini|csv|sh]
output file format and extension, use 'all'
to output all format, can be set several
times , Default is json.
-n, --namespace TEXT namespace like notation in version file, use
dot separator to segment namespaces e.g.:
'foo.bar.git'. Default is 'app_version' for
XML and INI and no namespace for JSON and
YAML. Never used for CSV or Shell file.
-m, --meta METADATA meta data to add, format = "<key>=<value>",
can be set several times
-d, --csv-delimiter TEXT CSV delimiter, default=","
-e, --csv-eol [lf|crlf] CSV end of line, lf = Unix new line, crlf =
windows new line, default=lf
-u, --csv-quote TEXT CSV quoting character, default='"'
-h, --help Show this message and exit.
获取提交信息
将 git 提交信息存储到 json 文件中
# git-app-version -o <output-file-without-extension> -f <file-format> <my-git-repository>
git-app-version -o version -f json
输出 :
Git commit :
---------------- ----------------------------------------
abbrev_commit 40aaf83
author_date 2015-09-05T16:14:16+0000
author_email paul.durand@example.com
author_name Paul Durand
author_timestamp 1441469656
branches master develop
commit_date 2015-09-05T16:14:16+0000
commit_timestamp 1441469656
committer_email paul.durand@example.com
committer_name Paul Durand
deploy_date 2016-06-21T09:33:01+0000
deploy_timestamp 1466501581
full_commit 40aaf83894b98898895d478f8b7cc4a866b1d62c
message new feature
top_branches master
version v1.1.0-3-g439e52
---------------- ----------------------------------------
written to :
<my-git-repository>/version.json
这将在当前目录中生成一个 version.json 文件(如果此目录是 git 存储库)。
您可以一次生成多种格式:
git-app-version -o version -f json -f yml -f xml -f ini -f sh
元数据:添加自定义字段
您可以使用 --meta / -m 选项添加自定义元数据字段(可以多次使用):
git-app-version -m foo=bar -m custom_key=custom_value
输出 :
Git commit :
---------------- ----------------------------------------
abbrev_commit 40aaf83
author_date 2015-09-05T16:14:16+0000
author_email paul.durand@example.com
author_name Paul Durand
author_timestamp 1441469656
branches master develop
commit_date 2015-09-05T16:14:16+0000
commit_timestamp 1441469656
committer_email paul.durand@example.com
committer_name Paul Durand
custom_key custom_value
deploy_date 2016-06-21T09:33:01+0000
deploy_timestamp 1466501581
foo bar
full_commit 40aaf83894b98898895d478f8b7cc4a866b1d62c
message new feature
top_branches master
version v1.1.0-3-g439e52
---------------- ----------------------------------------
written to :
<my-git-repository>/version.json
提交信息字段
-
full_commit:Git SHA1 提交哈希,
例如:40aaf83894b98898895d478f8b7cc4a866b1d62c
-
abbrev_commit:Git SHA1 提交哈希缩写符号(x 重要的第一个字符),
例如:40aaf83
-
version:命令的结果
git describe --tags --always
,见git-describe,如果没有找到版本,默认使用缩写提交例如:v1.1.0-3-g439e52
-
消息:Git 提交消息
-
commit_date : iso8601格式的 Git 提交日期,
例如:2016-03-01T09:33:33+0000
-
commit_timestamp:时间戳格式的 Git 提交日期,
例如:1456824813
-
author_date : iso8601格式的 Git 作者日期,
例如:2016-03-02T11:33:45+0000
-
author_timestamp:时间戳格式的 Git 作者日期,
例如:1456918425
-
deploy_date : iso8601格式的当前日期(运行该工具时) ,
例如:2016-03-02T11:33:45+0000
-
deploy_timestamp:时间戳格式的当前日期(运行工具时),
例如:1456918425
-
分支:提交所属的分支,
例如:['master', 'develop']
-
top_branches:提交是 HEAD 提交的分支,
例如:['主人']
-
committer_name:Git 提交者名称,
例如:保罗·杜兰德
-
committer_email:Git 提交者电子邮件,
-
author_name : Git 作者姓名,
例如:保罗·杜兰德
-
author_email : Git 作者邮箱,
文件格式
-
json
没有命名空间
git-app-version -f json
结果
{ "version": "v1.1.0-3-g439e52", "full_commit": "40aaf83894b98898895d478f8b7cc4a866b1d62c", "abbrev_commit": "40aaf83", "branches": [ "develop", "master" ], "top_branches": [ "master" ], "committer_email": "paul.durand@example.com", "committer_name": "Paul Durand", "author_name": "Paul Durand", "author_email": "paul.durand@example.com", "commit_date": "2015-09-05T16:14:16+0000", "commit_timestamp": "1441469656", "author_date": "2015-09-05T16:14:16+0000", "author_timestamp": "1441469656", "deploy_date": "2016-06-21T09:33:01+0000", "deploy_timestamp": "1466501581", "message": "new feature" }
带命名空间
git-app-version -f json -n git.infos
结果
{ "git": { "infos": { "version": "v1.1.0-3-g439e52", "full_commit": "40aaf83894b98898895d478f8b7cc4a866b1d62c", "abbrev_commit": "40aaf83", "branches": [ "develop", "master" ], "top_branches": [ "master" ], "committer_email": "paul.durand@example.com", "committer_name": "Paul Durand", "author_name": "Paul Durand", "author_email": "paul.durand@example.com", "commit_date": "2015-09-05T16:14:16+0000", "commit_timestamp": "1441469656", "author_date": "2015-09-05T16:14:16+0000", "author_timestamp": "1441469656", "deploy_date": "2016-06-21T09:33:01+0000", "deploy_timestamp": "1466501581", "message": "new feature" } } }
-
yml
没有命名空间
git-app-version -f yml
结果
--- 'version': 'v1.1.0-3-g439e52' 'full_commit': '40aaf83894b98898895d478f8b7cc4a866b1d62c' 'abbrev_commit': '40aaf83' 'committer_name': 'Paul Durand' 'committer_email': 'paul.durand@example.com' 'author_name': 'Paul Durand' 'author_email': 'paul.durand@example.com' 'commit_date': '2015-09-05T16:14:16+0000' 'commit_timestamp': '1441469656' 'author_date': '2015-09-05T16:14:16+0000' 'author_timestamp': '1441469656' 'deploy_date': '2016-06-21T09:32:57+0000' 'deploy_timestamp': '1466501577' 'message': 'new feature' 'branches': - 'develop' - 'master' 'top_branches': - 'master'
带命名空间
git-app-version -f yml -n git.infos
结果
--- 'git': 'infos': 'version': 'v1.1.0-3-g439e52' 'full_commit': '40aaf83894b98898895d478f8b7cc4a866b1d62c' 'abbrev_commit': '40aaf83' 'committer_name': 'Paul Durand' 'committer_email': 'paul.durand@example.com' 'author_name': 'Paul Durand' 'author_email': 'paul.durand@example.com' 'commit_date': '2015-09-05T16:14:16+0000' 'commit_timestamp': '1441469656' 'author_date': '2015-09-05T16:14:16+0000' 'author_timestamp': '1441469656' 'deploy_date': '2016-06-21T09:32:57+0000' 'deploy_timestamp': '1466501577' 'message': 'new feature' 'branches': - 'develop' - 'master' 'top_branches': - 'master'
-
xml
使用默认命名空间
git-app-version -f xml
结果
<?xml version='1.0' encoding='UTF-8'?> <app_version> <version>v1.1.0-3-g439e52</version> <full_commit>40aaf83894b98898895d478f8b7cc4a866b1d62c</full_commit> <abbrev_commit>40aaf83</abbrev_commit> <commit_date>2015-09-05T16:14:16+0000</commit_date> <commit_timestamp>1441469656</commit_timestamp> <author_date>2015-09-05T16:14:16+0000</author_date> <author_timestamp>1441469656</author_timestamp> <deploy_date>2016-06-21T09:32:53+0000</deploy_date> <deploy_timestamp>1466501573</deploy_timestamp> <committer_name>Paul Durand</committer_name> <committer_email>paul.durand@example.com</committer_email> <author_name>Paul Durand</author_name> <author_email>paul.durand@example.com</author_email> <message>new feature</message> <branches>develop</branches> <branches>master</branches> <top_branches>master</top_branches> </app_version>
带命名空间
git-app-version -f xml -n git.infos
结果
<?xml version='1.0' encoding='UTF-8'?> <git> <infos> <version>v1.1.0-3-g439e52</version> <full_commit>40aaf83894b98898895d478f8b7cc4a866b1d62c</full_commit> <abbrev_commit>40aaf83</abbrev_commit> <commit_date>2015-09-05T16:14:16+0000</commit_date> <commit_timestamp>1441469656</commit_timestamp> <author_date>2015-09-05T16:14:16+0000</author_date> <author_timestamp>1441469656</author_timestamp> <deploy_date>2016-06-21T09:32:53+0000</deploy_date> <deploy_timestamp>1466501573</deploy_timestamp> <committer_name>Paul Durand</committer_name> <committer_email>paul.durand@example.com</committer_email> <author_name>Paul Durand</author_name> <author_email>paul.durand@example.com</author_email> <message>new feature</message> <branches>develop</branches> <branches>master</branches> <top_branches>master</top_branches> </infos> </git>
-
初始化
使用默认命名空间
git-app-version -f ini
结果
[app_version] version = v1.1.0-3-g439e52 full_commit = 40aaf83894b98898895d478f8b7cc4a866b1d62c abbrev_commit = 40aaf83 commit_date = 2016-03-01T09:33:33+0000 commit_timestamp = 1456824813 author_date = 2016-03-01T09:33:33+0000 author_timestamp = 1456824813 deploy_date = 2016-03-02T11:33:45+0000 deploy_timestamp = 1456918425 message = new feature author_name = Paul Durand author_email = paul.durand@example.com committer_name = Paul Durand committer_email = paul.durand@example.com top_branches = ['master'] branches = ['master','develop']
带命名空间
git-app-version -f ini -n git.infos
结果
[git.infos] version = v1.1.0-3-g439e52 full_commit = 40aaf83894b98898895d478f8b7cc4a866b1d62c abbrev_commit = 40aaf83 commit_date = 2016-03-01T09:33:33+0000 commit_timestamp = 1456824813 author_date = 2016-03-01T09:33:33+0000 author_timestamp = 1456824813 deploy_date = 2016-03-02T11:33:45+0000 deploy_timestamp = 1456918425 message = new feature author_name = Paul Durand author_email = paul.durand@example.com committer_name = Paul Durand committer_email = paul.durand@example.com top_branches = ['master'] branches = ['master','develop']
-
CSV
您可以使用选项 --csv-delimiter 、 --csv-eol 和 --csv-quote 配置 CSV 格式
git-app-version -f csv --csv-delimiter ',' --csv-eol lf --csv-quote '"'
结果
version,v1.1.0-3-g439e52 full_commit,40aaf83894b98898895d478f8b7cc4a866b1d62c abbrev_commit,40aaf83 commit_date,2016-03-01T09:33:33+0000 commit_timestamp,1456824813 author_date,2016-03-01T09:33:33+0000 author_timestamp,1456824813 deploy_date,2016-03-02T11:33:45+0000 deploy_timestamp,1456918425 message,new feature author_name,Paul Durand author_email,paul.durand@example.com committer_name,Paul Durand committer_email,paul.durand@example.com top_branches,"['master']" branches,"['master','develop']"
-
sh(shell 脚本变量)
git-app-version -f sh
结果
version="v1.1.0-3-g439e52" full_commit="40aaf83894b98898895d478f8b7cc4a866b1d62c" abbrev_commit="40aaf83" commit_date="2016-03-01T09:33:33+0000" commit_timestamp="1456824813" author_date="2016-03-01T09:33:33+0000" author_timestamp="1456824813" deploy_date="2016-03-02T11:33:45+0000" deploy_timestamp="1456918425" message="new feature" author_name="Paul Durand" author_email="paul.durand@example.com" committer_name="Paul Durand" committer_email="paul.durand@example.com" top_branches="['master']" branches="['master','develop']"
许可
GPL v3 许可下的项目
版权所有 (C) 2016 查尔斯·桑克尔