jira和gerrit的集成和脚本
flow_tools的Python项目详细描述
一些自动化gerrit、jira等的工具。
当我的工作组将问题跟踪转移到jira时,这对项目来说是个福音。 但也带来了一些重大的发展摩擦。吉拉是 强大,但不快。完成任何事情大约需要12次点击 而且似乎每个ui交互都涉及到大量的数据库更新。
flow-tools作为两个脚本启动,以自动化常见的耗时 与吉拉的互动。其中包括两个Gerrit->;Jira 集成也一样。
用法
usage: flow-tools [-h] [-c CONFIG] [-v] <command> ... Command line client to automate parts of our agile workflow. positional arguments: <command> close-issues-merged Walk the list of merges on master for the given user. Look for tags in the commit message indicating that the commit closes/resolves an issue. Then login to jira and close those issues if they are not already closed. set-issues-fixed-in-release For each issue closed in a release, set the "Fixed Release" field of jira add-mentions-to-watchers Get a list of all mentioned users in the issue comments and description, and add any to the watcher list that are not already watchers. print-releases Parse tags on the gerrit remote and print a sorted list of version strings, using the pattern and sort functions from the config file. release-notes Show a list of commit message summaries for each commit in the series between one version and another. issues-in-release Show a list of issues that were closed in a release. In particular, lookup all commits that went into a release (since the common ancestor with the previous release). For each commit, get the list of issues closed or resolved through commit message meta data. These are the issues considered "in" the release. increment-jira-from-gerrit Monitor changes on gerrit for tags indicating associated issues that are resolved by those changes. As a change moves through the gerrit workflow, move the associated issue through the jira workflow. Same as update-jira-from-gerrit but in this case the start of the period to search will the last successful time we ran this command, and the end time will be right now. update-jira-from-gerrit Monitor changes on gerrit for tags indicating associated issues that are resolved by those changes. As a change moves through the gerrit workflow, move the associated issue through the jira workflow. optional arguments: -h, --help show this help message and exit -c CONFIG, --config CONFIG -v, --version show program's version number and exit Subcommands have their own options. Use <command> -h or <command> --help to see specific help for each subcommand.
示例
在提到时移动到观察者
查找票证评论中提到的@-proj-1234 让他们看那张票:
flow-tools add-mentions-to-watchers PROJ-1234
简单gerrit/jira集成
要利用jira/gerrit集成,请在提交消息中添加如下标记:
Closes: bug-1234, bug-1235, bug-1236 Resolves: bug-1237, bug-1238
集成脚本将读取提交消息并为这些标记解析它们。 对于提到的任何问题,该问题将在jira中移动到 “在审查中”。然后,一旦合并了更改,任何相关联的票据 在“关闭”中,将移动到“关闭”,并且“解决”中提到的任何票据 将移至“已解决”。
要扫描过去10天更新的gerrit更改,请使用:
flow-tools update-jira-from-gerrit --project my_project \ --start-time "$(date '+%Y-%m-%d %H:%M:%S' -d '-10 days')" \ --end-time "$(date '+%Y-%m-%d %H:%M:%S' -d '-10 days')"
以增量方式扫描gerrit更改(自上次运行 命令或1周(如果这是您第一次运行):
flow-tools increment-jira-from-gerrit --project my_project
对于gerrit/jira集成,您可以设置一个cron作业来批处理高级问题 基于他们的gerrit状态:
crontab -e
下面是一个简单的cron作业,它将在每个 小时:
PYTHONPATH=/path/to/flow-tools # Minute Hour Day of Month Month Day of Week Command # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) 12 * * * * flow-tools increment-jira-from-gerrit --project my_project >> /path/to/flow_tools.log
配置
配置由存储在以下位置的python文件管理:
~/.flowtools/config.py
下面是一个示例。
# URL for the database that sqlalchemy should use. The database is used to # cache certain objects fetched from either the gerrit or jira REST APIs # and to store some state for doing incremental jobs. db_url = "sqlite:////home/user/.flowtools/db.sqlite", # Jira rest configuration. These are passed directly as kwargs to the # jira rest client constructor. jira = { "auth" : { "url" : "https://company.atlassian.net", "username" : "user+robo", "password" : "abc123!@#", }, # The nominal flow of a jira ticket from the perspective of gerrit/jira # integration. This is used to prevent any "backwards" movement of a # ticket in the event that a human being changes the status of a ticket # before the integration script does. "nominal-flow" : { "PROJA": { "New": [ "Open", "In Progress", "In Review", "Verify (QA)", "Closed" ], "Open": [ "In Progress", "In Review", "Verify (QA)", "Closed" ], "In Progress": [ "In Review", "Verify (QA)", "Closed" ], "In Review": [ "Verify (QA)", "Closed" ], "Verify (QA)": [ "Closed" ] } }, gerrit = { # Gerrit rest configuration. The password is the http password added to # gerrit for the account. You can add an http password to an account # through either the web UI or command line tools. "rest" : { "url" : "https://gerrit.company.com", "username" : "user+robo", "password" : "ABDCEFGHIJKLMNOPQRSTUVWXYZXabcdefghjijklmnopqurst" }, # Gerrit ssh connection information. "ssh" : { "host" : "gerrit.company.com", "port" : 29418 } }, gerrit_jira = { # Maps commit change message tags to jira ticket status that a ticket # should be transitioned to in the event that a gerrit change is # merged. "tag-map": { "Closes": "Closed", "Resolves": "QA (Resolved)" } }