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.
23 import urllib.request as urllib2
25 # List of people to ping when the status of a tool changed.
27 'miri': '@oli-obk @RalfJung @eddyb',
28 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk',
29 'rls': '@nrc @Xanewok',
31 'book': '@carols10cents @steveklabnik',
32 'nomicon': '@frewsxcv @Gankro',
33 'reference': '@steveklabnik @Havvy @matthewjasper @alercah',
34 'rust-by-example': '@steveklabnik @marioidival @projektir',
45 'rust-by-example': '👩🏫',
48 def read_current_status(current_commit, path):
49 '''Reads build status of `current_commit` from content of `history/*.tsv`
51 with open(path, 'rU') as f:
53 (commit, status) = line.split('\t', 1)
54 if commit == current_commit:
55 return json.loads(status)
65 '''Updates `_data/latest.json` to match build result of the given commit.
67 with open('_data/latest.json', 'rb+') as f:
68 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
71 os: read_current_status(current_commit, 'history/' + os + '.tsv')
72 for os in ['windows', 'linux']
75 slug = 'rust-lang/rust'
76 long_message = textwrap.dedent('''\
77 Tested on commit {}@{}.
78 Direct link to PR: <{}>
80 ''').format(slug, current_commit, relevant_pr_url)
82 anything_changed = False
87 for os, s in current_status.items():
89 new = s.get(tool, old)
93 long_message += '🎉 {} on {}: {} → {}.\n' \
94 .format(tool, os, old, new)
95 emoji = "{}🎉".format(EMOJI.get(tool))
96 if msg not in emoji_status:
100 long_message += '💔 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
101 .format(tool, os, old, new, MAINTAINERS.get(tool))
102 emoji = "{}💔".format(EMOJI.get(tool))
103 if msg not in emoji_status:
104 emoji_status += [msg]
107 status['commit'] = current_commit
108 status['datetime'] = current_datetime
109 anything_changed = True
111 if not anything_changed:
114 short_message = "📣 Toolstate changed by {}! ({})"
115 .format(relevant_pr_number, '/'.join(emoji_status))
116 message = short_message + "\n\n" + long_message
119 json.dump(latest, f, indent=4, separators=(',', ': '))
123 if __name__ == '__main__':
124 cur_commit = sys.argv[1]
125 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
126 cur_commit_msg = sys.argv[2]
127 save_message_to_path = sys.argv[3]
128 github_token = sys.argv[4]
130 relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
131 if relevant_pr_match:
132 number = relevant_pr_match.group(1)
133 relevant_pr_number = 'rust-lang/rust#' + number
134 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
137 relevant_pr_number = '<unknown PR>'
138 relevant_pr_url = '<unknown>'
140 message = update_latest(
147 print('<Nothing changed>')
151 with open(save_message_to_path, 'w') as f:
154 # Write the toolstate comment on the PR as well.
155 gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
157 response = urllib2.urlopen(urllib2.Request(
159 json.dumps({'body': message}),
161 'Authorization': 'token ' + github_token,
162 'Content-Type': 'application/json',