import copy
import datetime
import collections
+import textwrap
+try:
+ import urllib2
+except ImportError:
+ import urllib.request as urllib2
# List of people to ping when the status of a tool changed.
MAINTAINERS = {
'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk',
'rls': '@nrc',
'rustfmt': '@nrc',
+ 'book': '@carols10cents @steveklabnik',
+ 'nomicon': '@frewsxcv @Gankro',
+ 'reference': '@steveklabnik @Havvy @matthewjasper @alercah',
+ 'rust-by-example': '@steveklabnik @marioidival @projektir',
}
return {}
-def update_latest(current_commit, relevant_pr_number, current_datetime):
+def update_latest(
+ current_commit,
+ relevant_pr_number,
+ relevant_pr_url,
+ current_datetime
+):
'''Updates `_data/latest.json` to match build result of the given commit.
'''
with open('_data/latest.json', 'rb+') as f:
}
slug = 'rust-lang/rust'
- message = '📣 Toolstate changed by {}!\n\nTested on commit {}@{}.\n\n' \
- .format(relevant_pr_number, slug, current_commit)
+ message = textwrap.dedent('''\
+ 📣 Toolstate changed by {}!
+
+ Tested on commit {}@{}.
+ Direct link to PR: <{}>
+
+ ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
anything_changed = False
for status in latest:
tool = status['tool']
.format(tool, os, old, new)
elif new < old:
changed = True
- message += '💔 {} on {}: {} → {} (cc {}).\n' \
- .format(tool, os, old, new, MAINTAINERS[tool])
+ message += '💔 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
+ .format(tool, os, old, new, MAINTAINERS.get(tool))
if changed:
status['commit'] = current_commit
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]
+ github_token = sys.argv[4]
- relevant_pr_match = re.search('#[0-9]+', cur_commit_msg)
+ relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
if relevant_pr_match:
- relevant_pr_number = 'rust-lang/rust' + relevant_pr_match.group(0)
+ number = relevant_pr_match.group(1)
+ relevant_pr_number = 'rust-lang/rust#' + number
+ relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
else:
+ number = '-1'
relevant_pr_number = '<unknown PR>'
-
- message = update_latest(cur_commit, relevant_pr_number, cur_datetime)
- if message:
- print(message)
- with open(save_message_to_path, 'w') as f:
- f.write(message)
- else:
+ relevant_pr_url = '<unknown>'
+
+ message = update_latest(
+ cur_commit,
+ relevant_pr_number,
+ relevant_pr_url,
+ cur_datetime
+ )
+ if not message:
print('<Nothing changed>')
+ 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()