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 'miri': 'https://github.com/solson/miri',
29 'clippy-driver': 'https://github.com/rust-lang/rust-clippy',
30 'rls': 'https://github.com/rust-lang/rls',
31 'rustfmt': 'https://github.com/rust-lang/rustfmt',
32 'book': 'https://github.com/rust-lang/book',
33 'nomicon': 'https://github.com/rust-lang-nursery/nomicon',
34 'reference': 'https://github.com/rust-lang-nursery/reference',
35 'rust-by-example': 'https://github.com/rust-lang/rust-by-example',
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 # Open an issue about the toolstate failure.
57 gh_url = 'https://api.github.com/repos/rust-lang/rust/issues'
58 assignees = [x.strip() for x in maintainers.split('@') if x != '']
59 assignees.append(relevant_pr_user)
60 response = urllib2.urlopen(urllib2.Request(
63 'body': textwrap.dedent('''\
64 Hello, this is your friendly neighborhood mergebot.
65 After merging PR {}, I observed that the tool {} no longer builds.
66 A follow-up PR to the repository {} is needed to fix the fallout.
68 cc @{}, do you think you would have time to do the follow-up work?
69 If so, that would be great!
71 cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization.
73 ''').format(relevant_pr_number, tool, REPOS[tool], relevant_pr_user, pr_reviewer),
74 'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number),
75 'assignees': assignees,
76 'labels': ['T-compiler', 'I-nominated'],
79 'Authorization': 'token ' + github_token,
80 'Content-Type': 'application/json',
93 '''Updates `_data/latest.json` to match build result of the given commit.
95 with open('_data/latest.json', 'rb+') as f:
96 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
99 os: read_current_status(current_commit, 'history/' + os + '.tsv')
100 for os in ['windows', 'linux']
103 slug = 'rust-lang/rust'
104 message = textwrap.dedent('''\
105 📣 Toolstate changed by {}!
107 Tested on commit {}@{}.
108 Direct link to PR: <{}>
110 ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
111 anything_changed = False
112 for status in latest:
113 tool = status['tool']
117 for os, s in current_status.items():
119 new = s.get(tool, old)
122 # things got fixed or at least the status quo improved
124 message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
125 .format(tool, os, old, new, MAINTAINERS.get(tool))
127 # tests or builds are failing and were not failing before
129 title = '💔 {} on {}: {} → {}' \
130 .format(tool, os, old, new)
131 message += '{} (cc {}, @rust-lang/infra).\n' \
132 .format(title, MAINTAINERS.get(tool))
133 # only create issues for build failures. Other failures can be spurious
134 if new == 'build-fail':
140 tool, MAINTAINERS.get(tool),
141 relevant_pr_number, relevant_pr_user, pr_reviewer,
143 except IOError as (errno, strerror):
144 # network errors will simply end up not creating an issue, but that's better
145 # than failing the entire build job
146 print "I/O error({0}): {1}".format(errno, strerror)
148 print "Unexpected error:", sys.exc_info()[0]
152 status['commit'] = current_commit
153 status['datetime'] = current_datetime
154 anything_changed = True
156 if not anything_changed:
161 json.dump(latest, f, indent=4, separators=(',', ': '))
165 if __name__ == '__main__':
166 cur_commit = sys.argv[1]
167 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
168 cur_commit_msg = sys.argv[2]
169 save_message_to_path = sys.argv[3]
170 github_token = sys.argv[4]
172 # assume that PR authors are also owners of the repo where the branch lives
173 relevant_pr_match = re.search(
174 'Auto merge of #([0-9]+) - ([^:]+):[^,]+ r=([^\s]+)',
177 if relevant_pr_match:
178 number = relevant_pr_match.group(1)
179 relevant_pr_user = relevant_pr_match.group(2)
180 relevant_pr_number = 'rust-lang/rust#' + number
181 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
182 pr_reviewer = relevant_pr_match.group(3)
185 relevant_pr_user = '<unknown user>'
186 relevant_pr_number = '<unknown PR>'
187 relevant_pr_url = '<unknown>'
188 pr_reviewer = '<unknown reviewer>'
190 message = update_latest(
199 print('<Nothing changed>')
205 print('Dry run only, not committing anything')
208 with open(save_message_to_path, 'w') as f:
211 # Write the toolstate comment on the PR as well.
212 gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
214 response = urllib2.urlopen(urllib2.Request(
216 json.dumps({'body': message}),
218 'Authorization': 'token ' + github_token,
219 'Content-Type': 'application/json',