2 # -*- coding: utf-8 -*-
13 import urllib.request as urllib2
15 # List of people to ping when the status of a tool or a book changed.
17 'miri': '@oli-obk @RalfJung @eddyb',
18 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk @phansch',
20 'rustfmt': '@topecongiro',
21 'book': '@carols10cents @steveklabnik',
22 'nomicon': '@frewsxcv @Gankro',
23 'reference': '@steveklabnik @Havvy @matthewjasper @ehuss',
24 'rust-by-example': '@steveklabnik @marioidival @projektir',
26 '@adamgreig @andre-richter @jamesmunns @korken89 '
27 '@ryankurte @thejpster @therealprof'
29 'edition-guide': '@ehuss @Centril @steveklabnik',
33 'miri': 'https://github.com/rust-lang/miri',
34 'clippy-driver': 'https://github.com/rust-lang/rust-clippy',
35 'rls': 'https://github.com/rust-lang/rls',
36 'rustfmt': 'https://github.com/rust-lang/rustfmt',
37 'book': 'https://github.com/rust-lang/book',
38 'nomicon': 'https://github.com/rust-lang-nursery/nomicon',
39 'reference': 'https://github.com/rust-lang-nursery/reference',
40 'rust-by-example': 'https://github.com/rust-lang/rust-by-example',
41 'embedded-book': 'https://github.com/rust-embedded/book',
42 'edition-guide': 'https://github.com/rust-lang-nursery/edition-guide',
46 def read_current_status(current_commit, path):
47 '''Reads build status of `current_commit` from content of `history/*.tsv`
49 with open(path, 'rU') as f:
51 (commit, status) = line.split('\t', 1)
52 if commit == current_commit:
53 return json.loads(status)
63 # Open an issue about the toolstate failure.
64 gh_url = 'https://api.github.com/repos/rust-lang/rust/issues'
65 assignees = [x.strip() for x in maintainers.split('@') if x != '']
66 assignees.append(relevant_pr_user)
67 response = urllib2.urlopen(urllib2.Request(
70 'body': textwrap.dedent('''\
71 Hello, this is your friendly neighborhood mergebot.
72 After merging PR {}, I observed that the tool {} no longer builds.
73 A follow-up PR to the repository {} is needed to fix the fallout.
75 cc @{}, do you think you would have time to do the follow-up work?
76 If so, that would be great!
78 cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization.
80 ''').format(relevant_pr_number, tool, REPOS.get(tool), relevant_pr_user, pr_reviewer),
81 'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number),
82 'assignees': assignees,
83 'labels': ['T-compiler', 'I-nominated'],
86 'Authorization': 'token ' + github_token,
87 'Content-Type': 'application/json',
100 '''Updates `_data/latest.json` to match build result of the given commit.
102 with open('_data/latest.json', 'rb+') as f:
103 latest = json.load(f, object_pairs_hook=collections.OrderedDict)
106 os: read_current_status(current_commit, 'history/' + os + '.tsv')
107 for os in ['windows', 'linux']
110 slug = 'rust-lang/rust'
111 message = textwrap.dedent('''\
112 📣 Toolstate changed by {}!
114 Tested on commit {}@{}.
115 Direct link to PR: <{}>
117 ''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
118 anything_changed = False
119 for status in latest:
120 tool = status['tool']
124 for os, s in current_status.items():
126 new = s.get(tool, old)
129 # things got fixed or at least the status quo improved
131 message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
132 .format(tool, os, old, new, MAINTAINERS.get(tool))
134 # tests or builds are failing and were not failing before
136 title = '💔 {} on {}: {} → {}' \
137 .format(tool, os, old, new)
138 message += '{} (cc {}, @rust-lang/infra).\n' \
139 .format(title, MAINTAINERS.get(tool))
140 # only create issues for build failures. Other failures can be spurious
141 if new == 'build-fail':
147 tool, MAINTAINERS.get(tool, ''),
148 relevant_pr_number, relevant_pr_user, pr_reviewer,
151 # network errors will simply end up not creating an issue, but that's better
152 # than failing the entire build job
153 print("I/O error: {0}".format(e))
155 print("Unexpected error: {0}".format(sys.exc_info()[0]))
159 status['commit'] = current_commit
160 status['datetime'] = current_datetime
161 anything_changed = True
163 if not anything_changed:
168 json.dump(latest, f, indent=4, separators=(',', ': '))
172 if __name__ == '__main__':
173 cur_commit = sys.argv[1]
174 cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
175 cur_commit_msg = sys.argv[2]
176 save_message_to_path = sys.argv[3]
177 github_token = sys.argv[4]
179 # assume that PR authors are also owners of the repo where the branch lives
180 relevant_pr_match = re.search(
181 r'Auto merge of #([0-9]+) - ([^:]+):[^,]+, r=(\S+)',
184 if relevant_pr_match:
185 number = relevant_pr_match.group(1)
186 relevant_pr_user = relevant_pr_match.group(2)
187 relevant_pr_number = 'rust-lang/rust#' + number
188 relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
189 pr_reviewer = relevant_pr_match.group(3)
192 relevant_pr_user = 'ghost'
193 relevant_pr_number = '<unknown PR>'
194 relevant_pr_url = '<unknown>'
195 pr_reviewer = 'ghost'
197 message = update_latest(
206 print('<Nothing changed>')
212 print('Dry run only, not committing anything')
215 with open(save_message_to_path, 'w') as f:
218 # Write the toolstate comment on the PR as well.
219 gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
221 response = urllib2.urlopen(urllib2.Request(
223 json.dumps({'body': message}),
225 'Authorization': 'token ' + github_token,
226 'Content-Type': 'application/json',