2 # -*- coding: utf-8 -*-
13 import urllib.request as urllib2
15 # List of people to ping when the status of a tool changed.
17 'miri': '@oli-obk @RalfJung @eddyb',
18 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk',
19 'rls': '@nrc @Xanewok',
21 'book': '@carols10cents @steveklabnik',
22 'nomicon': '@frewsxcv @Gankro',
23 'reference': '@steveklabnik @Havvy @matthewjasper @alercah',
24 'rust-by-example': '@steveklabnik @marioidival @projektir',
28 def read_current_status(current_commit, path):
29 '''Reads build status of `current_commit` from content of `history/*.tsv`
31 with open(path, 'rU') as f:
33 (commit, status) = line.split('\t', 1)
34 if commit == current_commit:
35 return json.loads(status)
45 '''Updates `_data/latest.json` to match build result of the given commit.
47 with open('_data/latest.json', 'rb+') as f:
48 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
51 os: read_current_status(current_commit, 'history/' + os + '.tsv')
52 for os in ['windows', 'linux']
55 slug = 'rust-lang/rust'
56 message = textwrap.dedent('''\
57 📣 Toolstate changed by {}!
59 Tested on commit {}@{}.
60 Direct link to PR: <{}>
62 ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
63 anything_changed = False
68 for os, s in current_status.items():
70 new = s.get(tool, old)
74 message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
75 .format(tool, os, old, new, MAINTAINERS.get(tool))
78 message += '💔 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
79 .format(tool, os, old, new, MAINTAINERS.get(tool))
82 status['commit'] = current_commit
83 status['datetime'] = current_datetime
84 anything_changed = True
86 if not anything_changed:
91 json.dump(latest, f, indent=4, separators=(',', ': '))
95 if __name__ == '__main__':
96 cur_commit = sys.argv[1]
97 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
98 cur_commit_msg = sys.argv[2]
99 save_message_to_path = sys.argv[3]
100 github_token = sys.argv[4]
102 relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
103 if relevant_pr_match:
104 number = relevant_pr_match.group(1)
105 relevant_pr_number = 'rust-lang/rust#' + number
106 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
109 relevant_pr_number = '<unknown PR>'
110 relevant_pr_url = '<unknown>'
112 message = update_latest(
119 print('<Nothing changed>')
125 print('Dry run only, not committing anything')
128 with open(save_message_to_path, 'w') as f:
131 # Write the toolstate comment on the PR as well.
132 gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
134 response = urllib2.urlopen(urllib2.Request(
136 json.dumps({'body': message}),
138 'Authorization': 'token ' + github_token,
139 'Content-Type': 'application/json',