diff options
author | George Burgess IV <gbiv@google.com> | 2021-12-09 00:28:14 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-13 18:41:52 +0000 |
commit | e8d03f7ea49a9ee46d672ed9ad3582ab591fd9f1 (patch) | |
tree | f61cae9ea699b3c17ee4a9ac5570e09ec3a88d99 /rust_tools/rust_watch.py | |
parent | 443e0b362f02045134713114bb34a4afad8090da (diff) | |
download | toolchain-utils-e8d03f7ea49a9ee46d672ed9ad3582ab591fd9f1.tar.gz |
rust_watch: report bugs for new minor or major versions of rustc
Now that we have new bug reporting bits, using them seems cool. File
bugs for uprevving to each new (non-patch) version, so we no longer have
to.
BUG=None
TEST=Unittests
Change-Id: I2b458cfd92bcdfda2f4bd8fbac319c1d05c44b47
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3324374
Reviewed-by: Bob Haarman <inglorion@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'rust_tools/rust_watch.py')
-rwxr-xr-x | rust_tools/rust_watch.py | 110 |
1 files changed, 70 insertions, 40 deletions
diff --git a/rust_tools/rust_watch.py b/rust_tools/rust_watch.py index b2c94acd..db6ae71b 100755 --- a/rust_tools/rust_watch.py +++ b/rust_tools/rust_watch.py @@ -19,10 +19,9 @@ import shutil import subprocess import sys import time -from typing import Any, Dict, Iterable, List, Optional, Tuple, NamedTuple +from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple -from cros_utils import email_sender -from cros_utils import tiny_render +from cros_utils import bugs, email_sender, tiny_render def gentoo_sha_to_link(sha: str) -> str: @@ -223,43 +222,63 @@ def atomically_write_state(state_file: pathlib.Path, state: State) -> None: temp_file.rename(state_file) -def maybe_compose_email(old_state: State, newest_release: RustReleaseVersion, - new_gentoo_commits: List[GitCommit] - ) -> Optional[Tuple[str, List[tiny_render.Piece]]]: +def file_bug(title: str, body: str) -> None: + """Files a bug against gbiv@ with the given title/body.""" + bugs.CreateNewBug( + bugs.WellKnownComponents.CrOSToolchainPublic, + title, + body, + # To either take or reassign depending on the rotation. + assignee='gbiv@google.com', + ) + + +def maybe_compose_bug( + old_state: State, + newest_release: RustReleaseVersion, +) -> Optional[Tuple[str, str]]: + """Creates a bug to file about the new release, if doing is desired.""" + if newest_release == old_state.last_seen_release: + return None + + title = f'New rustc release detected: v{newest_release}' + body = ('A new release has been detected; we should probably roll to it. ' + "Please see go/crostc-rust-rotation for who's turn it is.") + return title, body + + +def maybe_compose_email( + new_gentoo_commits: List[GitCommit] +) -> Optional[Tuple[str, List[tiny_render.Piece]]]: """Creates an email given our new state, if doing so is appropriate.""" + if not new_gentoo_commits: + return None + subject_pieces = [] body_pieces = [] - if newest_release > old_state.last_seen_release: - subject_pieces.append('new rustc release detected') - body_pieces.append(f'Rustc tag for v{newest_release} was found.') + # Separate the sections a bit for prettier output. + if body_pieces: + body_pieces += [tiny_render.line_break, tiny_render.line_break] - if new_gentoo_commits: - # Separate the sections a bit for prettier output. - if body_pieces: - body_pieces += [tiny_render.line_break, tiny_render.line_break] + if len(new_gentoo_commits) == 1: + subject_pieces.append('new rust ebuild commit detected') + body_pieces.append('commit:') + else: + subject_pieces.append('new rust ebuild commits detected') + body_pieces.append('commits (newest first):') + + commit_lines = [] + for commit in new_gentoo_commits: + commit_lines.append([ + tiny_render.Link( + gentoo_sha_to_link(commit.sha), + commit.sha[:12], + ), + f': {commit.subject}', + ]) - if len(new_gentoo_commits) == 1: - subject_pieces.append('new rust ebuild commit detected') - body_pieces.append('commit:') - else: - subject_pieces.append('new rust ebuild commits detected') - body_pieces.append('commits (newest first):') - - commit_lines = [] - for commit in new_gentoo_commits: - commit_lines.append([ - tiny_render.Link( - gentoo_sha_to_link(commit.sha), - commit.sha[:12], - ), - f': {commit.subject}', - ]) - - body_pieces.append(tiny_render.UnorderedList(commit_lines)) - - if not subject_pieces: - return None + body_pieces.append(tiny_render.UnorderedList(commit_lines)) subject = '[rust-watch] ' + '; '.join(subject_pieces) return subject, body_pieces @@ -274,9 +293,9 @@ def main(argv: List[str]) -> None: parser.add_argument('--state_dir', required=True, help='Directory to store state in.') - parser.add_argument('--skip_email', + parser.add_argument('--skip_side_effects', action='store_true', - help="Don't send an email.") + help="Don't send an email or file a bug.") parser.add_argument( '--skip_state_update', action='store_true', @@ -319,14 +338,25 @@ def main(argv: List[str]) -> None: prior_state.last_gentoo_sha) logging.info('New commits: %r', new_commits) - maybe_email = maybe_compose_email(prior_state, most_recent_release, - new_commits) + maybe_bug = maybe_compose_bug(prior_state, most_recent_release) + maybe_email = maybe_compose_email(new_commits) + + if maybe_bug is None: + logging.info('No bug to file') + else: + title, body = maybe_bug + if opts.skip_side_effects: + logging.info('Skipping sending bug with title %r and contents\n%s', + title, body) + else: + logging.info('Writing new bug') + file_bug(title, body) if maybe_email is None: - logging.info('No updates to send') + logging.info('No email to send') else: title, body = maybe_email - if opts.skip_email: + if opts.skip_side_effects: logging.info('Skipping sending email with title %r and contents\n%s', title, tiny_render.render_html_pieces(body)) else: |