2017-12-04 22:31:57 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
import datetime
|
|
|
|
import collections
|
2018-02-21 22:25:12 +08:00
|
|
|
import textwrap
|
2018-02-21 22:58:06 +08:00
|
|
|
try:
|
|
|
|
import urllib2
|
|
|
|
except ImportError:
|
|
|
|
import urllib.request as urllib2
|
2017-12-04 22:31:57 +08:00
|
|
|
|
|
|
|
# List of people to ping when the status of a tool changed.
|
|
|
|
MAINTAINERS = {
|
|
|
|
'miri': '@oli-obk @RalfJung @eddyb',
|
|
|
|
'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk',
|
2018-11-02 10:38:05 +13:00
|
|
|
'rls': '@nrc @Xanewok',
|
2017-12-04 22:31:57 +08:00
|
|
|
'rustfmt': '@nrc',
|
2018-02-22 03:25:23 +08:00
|
|
|
'book': '@carols10cents @steveklabnik',
|
|
|
|
'nomicon': '@frewsxcv @Gankro',
|
|
|
|
'reference': '@steveklabnik @Havvy @matthewjasper @alercah',
|
|
|
|
'rust-by-example': '@steveklabnik @marioidival @projektir',
|
2017-12-04 22:31:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def read_current_status(current_commit, path):
|
|
|
|
'''Reads build status of `current_commit` from content of `history/*.tsv`
|
|
|
|
'''
|
|
|
|
with open(path, 'rU') as f:
|
|
|
|
for line in f:
|
|
|
|
(commit, status) = line.split('\t', 1)
|
|
|
|
if commit == current_commit:
|
|
|
|
return json.loads(status)
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
2018-02-21 22:25:12 +08:00
|
|
|
def update_latest(
|
|
|
|
current_commit,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_url,
|
|
|
|
current_datetime
|
|
|
|
):
|
2017-12-04 22:31:57 +08:00
|
|
|
'''Updates `_data/latest.json` to match build result of the given commit.
|
|
|
|
'''
|
|
|
|
with open('_data/latest.json', 'rb+') as f:
|
|
|
|
latest = json.load(f, object_pairs_hook=collections.OrderedDict)
|
|
|
|
|
|
|
|
current_status = {
|
|
|
|
os: read_current_status(current_commit, 'history/' + os + '.tsv')
|
|
|
|
for os in ['windows', 'linux']
|
|
|
|
}
|
|
|
|
|
|
|
|
slug = 'rust-lang/rust'
|
2018-12-15 14:57:17 +01:00
|
|
|
message = textwrap.dedent('''\
|
|
|
|
📣 Toolstate changed by {}!
|
|
|
|
|
2018-02-21 22:25:12 +08:00
|
|
|
Tested on commit {}@{}.
|
|
|
|
Direct link to PR: <{}>
|
|
|
|
|
2018-12-15 14:57:17 +01:00
|
|
|
''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
|
2017-12-04 22:31:57 +08:00
|
|
|
anything_changed = False
|
|
|
|
for status in latest:
|
|
|
|
tool = status['tool']
|
|
|
|
changed = False
|
|
|
|
|
|
|
|
for os, s in current_status.items():
|
|
|
|
old = status[os]
|
|
|
|
new = s.get(tool, old)
|
|
|
|
status[os] = new
|
|
|
|
if new > old:
|
|
|
|
changed = True
|
2018-12-15 14:57:17 +01:00
|
|
|
message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
|
|
|
|
.format(tool, os, old, new, MAINTAINERS.get(tool))
|
2017-12-04 22:31:57 +08:00
|
|
|
elif new < old:
|
|
|
|
changed = True
|
2018-12-15 14:57:17 +01:00
|
|
|
message += '💔 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
|
2018-02-22 03:25:23 +08:00
|
|
|
.format(tool, os, old, new, MAINTAINERS.get(tool))
|
2017-12-04 22:31:57 +08:00
|
|
|
|
|
|
|
if changed:
|
|
|
|
status['commit'] = current_commit
|
|
|
|
status['datetime'] = current_datetime
|
|
|
|
anything_changed = True
|
|
|
|
|
|
|
|
if not anything_changed:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
f.seek(0)
|
|
|
|
f.truncate(0)
|
|
|
|
json.dump(latest, f, indent=4, separators=(',', ': '))
|
|
|
|
return message
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
cur_commit = sys.argv[1]
|
|
|
|
cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
cur_commit_msg = sys.argv[2]
|
|
|
|
save_message_to_path = sys.argv[3]
|
2018-02-21 22:58:06 +08:00
|
|
|
github_token = sys.argv[4]
|
2017-12-04 22:31:57 +08:00
|
|
|
|
2018-02-21 22:25:12 +08:00
|
|
|
relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
|
2017-12-04 22:31:57 +08:00
|
|
|
if relevant_pr_match:
|
2018-02-21 22:25:12 +08:00
|
|
|
number = relevant_pr_match.group(1)
|
|
|
|
relevant_pr_number = 'rust-lang/rust#' + number
|
|
|
|
relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
|
2017-12-04 22:31:57 +08:00
|
|
|
else:
|
2018-02-21 22:58:06 +08:00
|
|
|
number = '-1'
|
2017-12-04 22:31:57 +08:00
|
|
|
relevant_pr_number = '<unknown PR>'
|
2018-02-21 22:25:12 +08:00
|
|
|
relevant_pr_url = '<unknown>'
|
|
|
|
|
|
|
|
message = update_latest(
|
|
|
|
cur_commit,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_url,
|
|
|
|
cur_datetime
|
|
|
|
)
|
2018-02-21 22:58:06 +08:00
|
|
|
if not message:
|
2017-12-04 22:31:57 +08:00
|
|
|
print('<Nothing changed>')
|
2018-02-21 22:58:06 +08:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
print(message)
|
|
|
|
with open(save_message_to_path, 'w') as f:
|
|
|
|
f.write(message)
|
|
|
|
|
|
|
|
# Write the toolstate comment on the PR as well.
|
|
|
|
gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
|
|
|
|
.format(number)
|
|
|
|
response = urllib2.urlopen(urllib2.Request(
|
|
|
|
gh_url,
|
|
|
|
json.dumps({'body': message}),
|
|
|
|
{
|
|
|
|
'Authorization': 'token ' + github_token,
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}
|
|
|
|
))
|
|
|
|
response.read()
|