2 # -*- coding: utf-8 -*-
4 ## This is set as callback for `src/ci/docker/x86_64-gnu-tools/repo.sh` by the CI scripts
5 ## when a new commit lands on `master` (i.e., after it passed all checks on `auto`).
17 import urllib.request as urllib2
19 # List of people to ping when the status of a tool or a book changed.
21 'miri': '@oli-obk @RalfJung @eddyb',
22 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk @phansch',
24 'rustfmt': '@topecongiro',
25 'book': '@carols10cents @steveklabnik',
26 'nomicon': '@frewsxcv @Gankro',
27 'reference': '@steveklabnik @Havvy @matthewjasper @ehuss',
28 'rust-by-example': '@steveklabnik @marioidival @projektir',
30 '@adamgreig @andre-richter @jamesmunns @korken89 '
31 '@ryankurte @thejpster @therealprof'
33 'edition-guide': '@ehuss @Centril @steveklabnik',
34 'rustc-guide': '@mark-i-m @spastorino'
38 'miri': 'https://github.com/rust-lang/miri',
39 'clippy-driver': 'https://github.com/rust-lang/rust-clippy',
40 'rls': 'https://github.com/rust-lang/rls',
41 'rustfmt': 'https://github.com/rust-lang/rustfmt',
42 'book': 'https://github.com/rust-lang/book',
43 'nomicon': 'https://github.com/rust-lang-nursery/nomicon',
44 'reference': 'https://github.com/rust-lang-nursery/reference',
45 'rust-by-example': 'https://github.com/rust-lang/rust-by-example',
46 'embedded-book': 'https://github.com/rust-embedded/book',
47 'edition-guide': 'https://github.com/rust-lang-nursery/edition-guide',
48 'rustc-guide': 'https://github.com/rust-lang/rustc-guide',
52 def read_current_status(current_commit, path):
53 '''Reads build status of `current_commit` from content of `history/*.tsv`
55 with open(path, 'rU') as f:
57 (commit, status) = line.split('\t', 1)
58 if commit == current_commit:
59 return json.loads(status)
63 return os.environ['TOOLSTATE_ISSUES_API_URL']
65 def maybe_delink(message):
66 if os.environ.get('TOOLSTATE_SKIP_MENTIONS') is not None:
67 return message.replace("@", "")
78 # Open an issue about the toolstate failure.
79 assignees = [x.strip() for x in maintainers.split('@') if x != '']
80 if status == 'test-fail':
81 status_description = 'has failing tests'
83 status_description = 'no longer builds'
84 request = json.dumps({
85 'body': maybe_delink(textwrap.dedent('''\
86 Hello, this is your friendly neighborhood mergebot.
87 After merging PR {}, I observed that the tool {} {}.
88 A follow-up PR to the repository {} is needed to fix the fallout.
90 cc @{}, do you think you would have time to do the follow-up work?
91 If so, that would be great!
93 cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization.
96 relevant_pr_number, tool, status_description,
97 REPOS.get(tool), relevant_pr_user, pr_reviewer
99 'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number),
100 'assignees': assignees,
101 'labels': ['T-compiler', 'I-nominated'],
103 print("Creating issue:\n{}".format(request))
104 response = urllib2.urlopen(urllib2.Request(
108 'Authorization': 'token ' + github_token,
109 'Content-Type': 'application/json',
122 '''Updates `_data/latest.json` to match build result of the given commit.
124 with open('_data/latest.json', 'rb+') as f:
125 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
128 os: read_current_status(current_commit, 'history/' + os + '.tsv')
129 for os in ['windows', 'linux']
132 slug = 'rust-lang/rust'
133 message = textwrap.dedent('''\
134 📣 Toolstate changed by {}!
136 Tested on commit {}@{}.
137 Direct link to PR: <{}>
139 ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
140 anything_changed = False
141 for status in latest:
142 tool = status['tool']
144 create_issue_for_status = None # set to the status that caused the issue
146 for os, s in current_status.items():
148 new = s.get(tool, old)
150 if new > old: # comparing the strings, but they are ordered appropriately!
151 # things got fixed or at least the status quo improved
153 message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
154 .format(tool, os, old, new, MAINTAINERS.get(tool))
156 # tests or builds are failing and were not failing before
158 title = '💔 {} on {}: {} → {}' \
159 .format(tool, os, old, new)
160 message += '{} (cc {}, @rust-lang/infra).\n' \
161 .format(title, MAINTAINERS.get(tool))
162 # Most tools only create issues for build failures.
163 # Other failures can be spurious.
164 if new == 'build-fail' or (tool == 'miri' and new == 'test-fail'):
165 create_issue_for_status = new
167 if create_issue_for_status is not None:
170 tool, create_issue_for_status, MAINTAINERS.get(tool, ''),
171 relevant_pr_number, relevant_pr_user, pr_reviewer,
173 except urllib2.HTTPError as e:
174 # network errors will simply end up not creating an issue, but that's better
175 # than failing the entire build job
176 print("HTTPError when creating issue for status regression: {0}\n{1}"
177 .format(e, e.read()))
179 print("I/O error when creating issue for status regression: {0}".format(e))
181 print("Unexpected error when creating issue for status regression: {0}"
182 .format(sys.exc_info()[0]))
186 status['commit'] = current_commit
187 status['datetime'] = current_datetime
188 anything_changed = True
190 if not anything_changed:
195 json.dump(latest, f, indent=4, separators=(',', ': '))
199 if __name__ == '__main__':
200 cur_commit = sys.argv[1]
201 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
202 cur_commit_msg = sys.argv[2]
203 save_message_to_path = sys.argv[3]
204 github_token = sys.argv[4]
206 # assume that PR authors are also owners of the repo where the branch lives
207 relevant_pr_match = re.search(
208 r'Auto merge of #([0-9]+) - ([^:]+):[^,]+, r=(\S+)',
211 if relevant_pr_match:
212 number = relevant_pr_match.group(1)
213 relevant_pr_user = relevant_pr_match.group(2)
214 relevant_pr_number = 'rust-lang/rust#' + number
215 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
216 pr_reviewer = relevant_pr_match.group(3)
219 relevant_pr_user = 'ghost'
220 relevant_pr_number = '<unknown PR>'
221 relevant_pr_url = '<unknown>'
222 pr_reviewer = 'ghost'
224 message = update_latest(
233 print('<Nothing changed>')
239 print('Dry run only, not committing anything')
242 with open(save_message_to_path, 'w') as f:
245 # Write the toolstate comment on the PR as well.
246 issue_url = gh_url() + '/{}/comments'.format(number)
247 response = urllib2.urlopen(urllib2.Request(
249 json.dumps({'body': maybe_delink(message)}),
251 'Authorization': 'token ' + github_token,
252 'Content-Type': 'application/json',