2 # -*- coding: utf-8 -*-
4 # Copyright 2017 The Rust Project Developers. See the COPYRIGHT
5 # file at the top-level directory of this distribution and at
6 # http://rust-lang.org/COPYRIGHT.
8 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
9 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
10 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
11 # option. This file may not be copied, modified, or distributed
12 # except according to those terms.
24 import urllib.request as urllib2
26 # List of people to ping when the status of a tool changed.
28 'miri': '@oli-obk @RalfJung @eddyb',
29 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk',
32 'book': '@carols10cents @steveklabnik',
33 'nomicon': '@frewsxcv @Gankro',
34 'reference': '@steveklabnik @Havvy @matthewjasper @alercah',
35 'rust-by-example': '@steveklabnik @marioidival @projektir',
39 def read_current_status(current_commit, path):
40 '''Reads build status of `current_commit` from content of `history/*.tsv`
42 with open(path, 'rU') as f:
44 (commit, status) = line.split('\t', 1)
45 if commit == current_commit:
46 return json.loads(status)
56 '''Updates `_data/latest.json` to match build result of the given commit.
58 with open('_data/latest.json', 'rb+') as f:
59 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
62 os: read_current_status(current_commit, 'history/' + os + '.tsv')
63 for os in ['windows', 'linux']
66 slug = 'rust-lang/rust'
67 message = textwrap.dedent('''\
68 📣 Toolstate changed by {}!
70 Tested on commit {}@{}.
71 Direct link to PR: <{}>
73 ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
74 anything_changed = False
79 for os, s in current_status.items():
81 new = s.get(tool, old)
85 message += '🎉 {} on {}: {} → {}.\n' \
86 .format(tool, os, old, new)
89 message += '💔 {} on {}: {} → {} (cc {}).\n' \
90 .format(tool, os, old, new, MAINTAINERS.get(tool))
93 status['commit'] = current_commit
94 status['datetime'] = current_datetime
95 anything_changed = True
97 if not anything_changed:
102 json.dump(latest, f, indent=4, separators=(',', ': '))
106 if __name__ == '__main__':
107 cur_commit = sys.argv[1]
108 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
109 cur_commit_msg = sys.argv[2]
110 save_message_to_path = sys.argv[3]
111 github_token = sys.argv[4]
113 relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
114 if relevant_pr_match:
115 number = relevant_pr_match.group(1)
116 relevant_pr_number = 'rust-lang/rust#' + number
117 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
120 relevant_pr_number = '<unknown PR>'
121 relevant_pr_url = '<unknown>'
123 message = update_latest(
130 print('<Nothing changed>')
134 with open(save_message_to_path, 'w') as f:
137 # Write the toolstate comment on the PR as well.
138 gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
140 response = urllib2.urlopen(urllib2.Request(
142 json.dumps({'body': message}),
144 'Authorization': 'token ' + github_token,
145 'Content-Type': 'application/json',