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',
34 'miri': 'https://github.com/rust-lang/miri',
35 'clippy-driver': 'https://github.com/rust-lang/rust-clippy',
36 'rls': 'https://github.com/rust-lang/rls',
37 'rustfmt': 'https://github.com/rust-lang/rustfmt',
38 'book': 'https://github.com/rust-lang/book',
39 'nomicon': 'https://github.com/rust-lang-nursery/nomicon',
40 'reference': 'https://github.com/rust-lang-nursery/reference',
41 'rust-by-example': 'https://github.com/rust-lang/rust-by-example',
42 'embedded-book': 'https://github.com/rust-embedded/book',
43 'edition-guide': 'https://github.com/rust-lang-nursery/edition-guide',
47 def read_current_status(current_commit, path):
48 '''Reads build status of `current_commit` from content of `history/*.tsv`
50 with open(path, 'rU') as f:
52 (commit, status) = line.split('\t', 1)
53 if commit == current_commit:
54 return json.loads(status)
58 return os.environ['TOOLSTATE_ISSUES_API_URL']
60 def maybe_delink(message):
61 if os.environ.get('TOOLSTATE_SKIP_MENTIONS') is not None:
62 return message.replace("@", "")
73 # Open an issue about the toolstate failure.
74 assignees = [x.strip() for x in maintainers.split('@') if x != '']
75 if status == 'test-fail':
76 status_description = 'has failing tests'
78 status_description = 'no longer builds'
79 request = json.dumps({
80 'body': maybe_delink(textwrap.dedent('''\
81 Hello, this is your friendly neighborhood mergebot.
82 After merging PR {}, I observed that the tool {} {}.
83 A follow-up PR to the repository {} is needed to fix the fallout.
85 cc @{}, do you think you would have time to do the follow-up work?
86 If so, that would be great!
88 cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization.
91 relevant_pr_number, tool, status_description,
92 REPOS.get(tool), relevant_pr_user, pr_reviewer
94 'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number),
95 'assignees': assignees,
96 'labels': ['T-compiler', 'I-nominated'],
98 print("Creating issue:\n{}".format(request))
99 response = urllib2.urlopen(urllib2.Request(
103 'Authorization': 'token ' + github_token,
104 'Content-Type': 'application/json',
117 '''Updates `_data/latest.json` to match build result of the given commit.
119 with open('_data/latest.json', 'rb+') as f:
120 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
123 os: read_current_status(current_commit, 'history/' + os + '.tsv')
124 for os in ['windows', 'linux']
127 slug = 'rust-lang/rust'
128 message = textwrap.dedent('''\
129 📣 Toolstate changed by {}!
131 Tested on commit {}@{}.
132 Direct link to PR: <{}>
134 ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
135 anything_changed = False
136 for status in latest:
137 tool = status['tool']
139 create_issue_for_status = None # set to the status that caused the issue
141 for os, s in current_status.items():
143 new = s.get(tool, old)
145 if new > old: # comparing the strings, but they are ordered appropriately!
146 # things got fixed or at least the status quo improved
148 message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
149 .format(tool, os, old, new, MAINTAINERS.get(tool))
151 # tests or builds are failing and were not failing before
153 title = '💔 {} on {}: {} → {}' \
154 .format(tool, os, old, new)
155 message += '{} (cc {}, @rust-lang/infra).\n' \
156 .format(title, MAINTAINERS.get(tool))
157 # Most tools only create issues for build failures.
158 # Other failures can be spurious.
159 if new == 'build-fail' or (tool == 'miri' and new == 'test-fail'):
160 create_issue_for_status = new
162 if create_issue_for_status is not None:
165 tool, create_issue_for_status, MAINTAINERS.get(tool, ''),
166 relevant_pr_number, relevant_pr_user, pr_reviewer,
168 except urllib2.HTTPError as e:
169 # network errors will simply end up not creating an issue, but that's better
170 # than failing the entire build job
171 print("HTTPError when creating issue for status regression: {0}\n{1}"
172 .format(e, e.read()))
174 print("I/O error when creating issue for status regression: {0}".format(e))
176 print("Unexpected error when creating issue for status regression: {0}"
177 .format(sys.exc_info()[0]))
181 status['commit'] = current_commit
182 status['datetime'] = current_datetime
183 anything_changed = True
185 if not anything_changed:
190 json.dump(latest, f, indent=4, separators=(',', ': '))
194 if __name__ == '__main__':
195 cur_commit = sys.argv[1]
196 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
197 cur_commit_msg = sys.argv[2]
198 save_message_to_path = sys.argv[3]
199 github_token = sys.argv[4]
201 # assume that PR authors are also owners of the repo where the branch lives
202 relevant_pr_match = re.search(
203 r'Auto merge of #([0-9]+) - ([^:]+):[^,]+, r=(\S+)',
206 if relevant_pr_match:
207 number = relevant_pr_match.group(1)
208 relevant_pr_user = relevant_pr_match.group(2)
209 relevant_pr_number = 'rust-lang/rust#' + number
210 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
211 pr_reviewer = relevant_pr_match.group(3)
214 relevant_pr_user = 'ghost'
215 relevant_pr_number = '<unknown PR>'
216 relevant_pr_url = '<unknown>'
217 pr_reviewer = 'ghost'
219 message = update_latest(
228 print('<Nothing changed>')
234 print('Dry run only, not committing anything')
237 with open(save_message_to_path, 'w') as f:
240 # Write the toolstate comment on the PR as well.
241 issue_url = gh_url() + '/{}/comments'.format(number)
242 response = urllib2.urlopen(urllib2.Request(
244 json.dumps({'body': maybe_delink(message)}),
246 'Authorization': 'token ' + github_token,
247 'Content-Type': 'application/json',