Page MenuHomePhabricator
Paste P8845

backport-summary script

Authored by awight on Aug 1 2019, 2:01 PM.
Referenced Files
F32186651: raw.txt
Aug 17 2020, 3:40 PM
F31858129: raw.txt
Jun 8 2020, 5:25 PM
F31503559: raw.txt
Jan 7 2020, 2:23 PM
F29938090: raw.txt
Aug 2 2019, 10:27 AM
F29930987: raw.txt
Aug 1 2019, 2:10 PM
F29930983: raw.txt
Aug 1 2019, 2:08 PM
F29930970: raw.txt
Aug 1 2019, 2:01 PM
"Pterodactyl" token, awarded by brennen.
#!/usr/bin/env python3
Given a Gerrit URL, build its scap summary in the backport deployment format.
backport-summary <gerrit-url>
backport-summary -h | --help
$ backport-summary
Backport: [[gerrit:603482|Wrap WAN-cached PropertyInfoLookup with an APCu cache (T254536)]]
$ backport-summary
Config: [[gerrit:561355|Modify $wgArticleCount to 'any' for ta.wiktionary (T241684)]]
'Config: [[gerrit:561355|Modify $wgArticleCount to '"'"'any'"'"' for ta.wiktionary (T241684)]]'
If the summary contains shell special characters, it will be printed again,
suitably quoted this time (as in the second example).
Various formats of Gerrit URLs are accepted.
import docopt
import json
import re
import requests
import shlex
GERRIT_RE = '[-+_/a-zA-Z0-9]+/)?)?(?P<gerrit_number>[0-9]+)/?'
PHAB_HEADER_RE = '(?m)^Bug: (?P<phab_task>T[0-9]+)$'
SUMMARY_MSG = '{kind}: [[gerrit:{gerrit_number}|{commit_message} ({phabricator_task})]]'
def build_summary(gerrit_url):
matches = re.match(GERRIT_RE, gerrit_url)
if matches:
gerrit_number ='gerrit_number')
raise RuntimeError("Couldn't extract gerrit change number from string " + gerrit_url)
change = get_gerrit(GERRIT_CHANGE_API, gerrit_number=gerrit_number)
kind = 'Config' if change['project'] == 'operations/mediawiki-config' else 'Backport'
revision_id = change['current_revision']
commit = change['revisions'][revision_id]['commit']
bugs = re.findall(PHAB_HEADER_RE, commit['message'])
return SUMMARY_MSG.format(
phabricator_task=', '.join(bugs))
def get_gerrit(api_format, **params):
url = api_format.format(**params)
r = requests.get(url)
if r.status_code != 200:
raise RuntimeError("Bad HTTP response from " + url)
return json.loads(
if __name__ == '__main__':
arguments = docopt.docopt(__doc__)
summary = build_summary(arguments['<gerrit-url>'])
quoted = shlex.quote(summary)
if quoted != summary and quoted != "'{}'".format(summary):
# correctly quoting this is not trivial, do it for the user

Event Timeline

Lucas_Werkmeister_WMDE changed the title of this paste from Draft of swat-summary script to swat-summary script.Jan 7 2020, 2:22 PM
Lucas_Werkmeister_WMDE edited the content of this paste. (Show Details)
Lucas_Werkmeister_WMDE changed the title of this paste from swat-summary script to backport-summary script.Jun 8 2020, 5:25 PM
Lucas_Werkmeister_WMDE edited the content of this paste. (Show Details)