Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P8845
backport-summary script
Active
Public
Actions
Authored by
awight
on Aug 1 2019, 2:01 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
MediaWiki-backport-deployments
Subscribers
Lucas_Werkmeister_WMDE
Niedzielski
Tokens
"Pterodactyl" token, awarded by brennen.
#!/usr/bin/env python3
"""
Given a Gerrit URL, build its scap summary in the backport deployment format.
Usage:
backport-summary <gerrit-url>
backport-summary -h | --help
Examples:
$ backport-summary https://gerrit.wikimedia.org/r/603482
Backport: [[gerrit:603482|Wrap WAN-cached PropertyInfoLookup with an APCu cache (T254536)]]
$ backport-summary https://gerrit.wikimedia.org/r/c/operations/mediawiki-config/+/561355
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_CHANGE_API
=
'https://gerrit.wikimedia.org/r/changes/{gerrit_number}?o=CURRENT_REVISION&o=CURRENT_COMMIT'
GERRIT_RE
=
'https://gerrit.wikimedia.org/r/(?:(?:#/)?c/(?:[-+_/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
=
matches
.
group
(
'gerrit_number'
)
else
:
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
(
kind
=
kind
,
gerrit_number
=
gerrit_number
,
commit_message
=
commit
[
'subject'
],
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
(
r
.
text
.
lstrip
(
")]}'"
))
if
__name__
==
'__main__'
:
arguments
=
docopt
.
docopt
(
__doc__
)
summary
=
build_summary
(
arguments
[
'<gerrit-url>'
])
print
(
summary
)
quoted
=
shlex
.
quote
(
summary
)
if
quoted
!=
summary
and
quoted
!=
"'{}'"
.
format
(
summary
):
# correctly quoting this is not trivial, do it for the user
print
(
quoted
)
Event Timeline
awight
created this paste.
Aug 1 2019, 2:01 PM
Lucas_Werkmeister_WMDE
edited the content of this paste.
(Show Details)
Aug 1 2019, 2:08 PM
Lucas_Werkmeister_WMDE
edited the content of this paste.
(Show Details)
Aug 1 2019, 2:10 PM
awight
edited the content of this paste.
(Show Details)
Aug 2 2019, 10:27 AM
brennen
awarded a token.
Dec 11 2019, 7:52 PM
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
added a subscriber:
Lucas_Werkmeister_WMDE
.
Niedzielski
added a subscriber:
Niedzielski
.
Apr 13 2020, 9:08 PM
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)
Lucas_Werkmeister_WMDE
edited the content of this paste.
(Show Details)
Aug 17 2020, 3:40 PM
Log In to Comment