获取git提交信息并将其存储在配置文件中的cli工具

git-app-version的Python项目详细描述


Git应用程序版本

PyPI versiontravis-buildscrutinizer-qualityscrutinizer-coverageGitHub licenseMaintenance

一种用python编写的cli工具,用于获取git提交信息并将其存储在配置文件中。

支持的格式:

  • json
  • 山药
  • XML
  • ini
  • CSV
  • shell脚本变量

典型用例:部署时,运行此命令并导入git版本配置文件。

要求

  • python 2.7或>;=3.4
  • python pip包工具

安装

只需运行:

pip install git-app-version

或者为Linux AMD64下载latest binary release

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 commit散列,

    例如:40aaf83894b98898895d478f8b7cc4a866b1d62c

  • abbrev_commit:git sha1 commit hash abbrev表示法(x有效的第一个字符),

    例如:40aaf83

  • version:命令的结果git describe --tags --always,请参见git-describe,如果找不到版本,则默认情况下将使用abbrev提交

    例如:v1.1.0-3-g439e52

  • 消息:git提交消息

  • 提交日期:git提交日期采用iso8601格式,

    例如:2016-03-01t09:33:33+0000

  • commit_时间戳:时间戳格式的git提交日期,

    例如:1456824813

  • 作者日期:以iso8601格式的git作者日期,

    例如:2016-03-02t11:33:45+0000

  • 作者时间戳:时间戳格式的git作者日期,

    例如:1456918425

  • deploy_date:当前日期(运行该工具时)采用iso8601格式,

    例如:2016-03-02t11:33:45+0000

  • deploy_timestamp:时间戳格式的当前日期(运行工具时),

    例如:1456918425

  • 分支:提交所属的分支,

    例如:['master','development']

  • top_分支:提交是头提交的分支,

    例如:['master']

  • committer\u name:git committer name,

    例如:paul durand

  • committer\u电子邮件:git committer电子邮件,

    例如:paul.durand@example.com

  • 作者姓名:git作者姓名,

    例如:paul durand

  • 作者电子邮件:git作者电子邮件,

    例如:paul.durand@example.com

文件格式

  • 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>
  • ini

    使用默认名称空间

    git-app-version -f ini
    

    结果

    [app_version]version=v1.1.0-3-g439e52full_commit=40aaf83894b98898895d478f8b7cc4a866b1d62cabbrev_commit=40aaf83commit_date=2016-03-01T09:33:33+0000commit_timestamp=1456824813author_date=2016-03-01T09:33:33+0000author_timestamp=1456824813deploy_date=2016-03-02T11:33:45+0000deploy_timestamp=1456918425message=new featureauthor_name=Paul Durandauthor_email=paul.durand@example.comcommitter_name=Paul Durandcommitter_email=paul.durand@example.comtop_branches=['master']branches=['master','develop']

    具有名称空间

    git-app-version -f ini -n git.infos
    

    结果

    [git.infos]version=v1.1.0-3-g439e52full_commit=40aaf83894b98898895d478f8b7cc4a866b1d62cabbrev_commit=40aaf83commit_date=2016-03-01T09:33:33+0000commit_timestamp=1456824813author_date=2016-03-01T09:33:33+0000author_timestamp=1456824813deploy_date=2016-03-02T11:33:45+0000deploy_timestamp=1456918425message=new featureauthor_name=Paul Durandauthor_email=paul.durand@example.comcommitter_name=Paul Durandcommitter_email=paul.durand@example.comtop_branches=['master']branches=['master','develop']
  • csv

    您可以使用选项--csv分隔符、-csv eol和--csv引号配置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']"

许可

GPLv3许可下的项目

版权所有(c)2016 Charles Sanquer

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
即使值等于null,java也会检索行   java如何正确地创建子类的新实例   java集合。shuffle未按预期工作   elasticsearch使用JAVA API从Elastic Search建议搜索响应中提取源数据   mysql HTTP状态500 java。lang.NullPointerException   具有多个前端服务实例和后端工作者的java ZMQ请求/响应   通过短信、电子邮件、twitter、黑莓上的facebook分享java   java根据netbeans中的单选按钮切换组件的“enable”属性   java托管Bean不工作:调用NotingMB文件中的save函数时出现空指针异常   如何在java中对包含两个以上异构对象的列表进行排序?   java我在尝试log4j时遇到以下错误。   java可以在MacOSX上实现这一点吗?   我尝试在java中使用定界符输入制作caesar密码   长时间运行Tomcat进程的类加载器中的java问题   java swing焦点问题,焦点丢失,未调用focusgain   java如何以字符串格式“EEE,MMM d,yyyy”获取整数月、日和年   java JList侦听器找不到符号