2 # -*- coding: utf-8 -*-
14 import urllib.request as urllib2
16 # List of people to ping when the status of a tool or a book changed.
18 'miri': '@oli-obk @RalfJung @eddyb',
19 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk @phansch',
21 'rustfmt': '@topecongiro',
22 'book': '@carols10cents @steveklabnik',
23 'nomicon': '@frewsxcv @Gankro',
24 'reference': '@steveklabnik @Havvy @matthewjasper @ehuss',
25 'rust-by-example': '@steveklabnik @marioidival @projektir',
27 '@adamgreig @andre-richter @jamesmunns @korken89 '
28 '@ryankurte @thejpster @therealprof'
30 'edition-guide': '@ehuss @Centril @steveklabnik',
31 'rustc-guide': '@mark-i-m @spastorino'
35 'miri': 'https://github.com/rust-lang/miri',
36 'clippy-driver': 'https://github.com/rust-lang/rust-clippy',
37 'rls': 'https://github.com/rust-lang/rls',
38 'rustfmt': 'https://github.com/rust-lang/rustfmt',
39 'book': 'https://github.com/rust-lang/book',
40 'nomicon': 'https://github.com/rust-lang-nursery/nomicon',
41 'reference': 'https://github.com/rust-lang-nursery/reference',
42 'rust-by-example': 'https://github.com/rust-lang/rust-by-example',
43 'embedded-book': 'https://github.com/rust-embedded/book',
44 'edition-guide': 'https://github.com/rust-lang-nursery/edition-guide',
45 'rustc-guide': 'https://github.com/rust-lang/rustc-guide',
49 def read_current_status(current_commit, path):
50 '''Reads build status of `current_commit` from content of `history/*.tsv`
52 with open(path, 'rU') as f:
54 (commit, status) = line.split('\t', 1)
55 if commit == current_commit:
56 return json.loads(status)
60 return os.environ['TOOLSTATE_ISSUES_API_URL']
62 def maybe_delink(message):
63 if os.environ.get('TOOLSTATE_SKIP_MENTIONS') is not None:
64 return message.replace("@", "")
75 # Open an issue about the toolstate failure.
76 assignees = [x.strip() for x in maintainers.split('@') if x != '']
77 if status == 'test-fail':
78 status_description = 'has failing tests'
80 status_description = 'no longer builds'
81 request = json.dumps({
82 'body': maybe_delink(textwrap.dedent('''\
83 Hello, this is your friendly neighborhood mergebot.
84 After merging PR {}, I observed that the tool {} {}.
85 A follow-up PR to the repository {} is needed to fix the fallout.
87 cc @{}, do you think you would have time to do the follow-up work?
88 If so, that would be great!
90 cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization.
93 relevant_pr_number, tool, status_description,
94 REPOS.get(tool), relevant_pr_user, pr_reviewer
96 'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number),
97 'assignees': assignees,
98 'labels': ['T-compiler', 'I-nominated'],
100 print("Creating issue:\n{}".format(request))
101 response = urllib2.urlopen(urllib2.Request(
105 'Authorization': 'token ' + github_token,
106 'Content-Type': 'application/json',
119 '''Updates `_data/latest.json` to match build result of the given commit.
121 with open('_data/latest.json', 'rb+') as f:
122 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
125 os: read_current_status(current_commit, 'history/' + os + '.tsv')
126 for os in ['windows', 'linux']
129 slug = 'rust-lang/rust'
130 message = textwrap.dedent('''\
131 📣 Toolstate changed by {}!
133 Tested on commit {}@{}.
134 Direct link to PR: <{}>
136 ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
137 anything_changed = False
138 for status in latest:
139 tool = status['tool']
141 create_issue_for_status = None # set to the status that caused the issue
143 for os, s in current_status.items():
145 new = s.get(tool, old)
147 if new > old: # comparing the strings, but they are ordered appropriately!
148 # things got fixed or at least the status quo improved
150 message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
151 .format(tool, os, old, new, MAINTAINERS.get(tool))
153 # tests or builds are failing and were not failing before
155 title = '💔 {} on {}: {} → {}' \
156 .format(tool, os, old, new)
157 message += '{} (cc {}, @rust-lang/infra).\n' \
158 .format(title, MAINTAINERS.get(tool))
159 # Most tools only create issues for build failures.
160 # Other failures can be spurious.
161 if new == 'build-fail' or (tool == 'miri' and new == 'test-fail'):
162 create_issue_for_status = new
164 if create_issue_for_status is not None:
167 tool, create_issue_for_status, MAINTAINERS.get(tool, ''),
168 relevant_pr_number, relevant_pr_user, pr_reviewer,
170 except urllib2.HTTPError as e:
171 # network errors will simply end up not creating an issue, but that's better
172 # than failing the entire build job
173 print("HTTPError when creating issue for status regression: {0}\n{1}"
174 .format(e, e.read()))
176 print("I/O error when creating issue for status regression: {0}".format(e))
178 print("Unexpected error when creating issue for status regression: {0}"
179 .format(sys.exc_info()[0]))
183 status['commit'] = current_commit
184 status['datetime'] = current_datetime
185 anything_changed = True
187 if not anything_changed:
192 json.dump(latest, f, indent=4, separators=(',', ': '))
196 if __name__ == '__main__':
197 cur_commit = sys.argv[1]
198 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
199 cur_commit_msg = sys.argv[2]
200 save_message_to_path = sys.argv[3]
201 github_token = sys.argv[4]
203 # assume that PR authors are also owners of the repo where the branch lives
204 relevant_pr_match = re.search(
205 r'Auto merge of #([0-9]+) - ([^:]+):[^,]+, r=(\S+)',
208 if relevant_pr_match:
209 number = relevant_pr_match.group(1)
210 relevant_pr_user = relevant_pr_match.group(2)
211 relevant_pr_number = 'rust-lang/rust#' + number
212 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
213 pr_reviewer = relevant_pr_match.group(3)
216 relevant_pr_user = 'ghost'
217 relevant_pr_number = '<unknown PR>'
218 relevant_pr_url = '<unknown>'
219 pr_reviewer = 'ghost'
221 message = update_latest(
230 print('<Nothing changed>')
236 print('Dry run only, not committing anything')
239 with open(save_message_to_path, 'w') as f:
242 # Write the toolstate comment on the PR as well.
243 issue_url = gh_url() + '/{}/comments'.format(number)
244 response = urllib2.urlopen(urllib2.Request(
246 json.dumps({'body': maybe_delink(message)}),
248 'Authorization': 'token ' + github_token,
249 'Content-Type': 'application/json',