| #!/usr/bin/env fuchsia-vendored-python |
| # Copyright 2022 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| #### CATEGORY=Code submission and review |
| ### Open in a new browser window the gerrit review URL. |
| |
| ## Usage: fx cl |
| |
| import subprocess |
| import sys |
| import webbrowser |
| |
| def GetChangeId(): |
| """ |
| Attempts to obtain the change ID from the last commit. |
| Returns an empty string if it fails. |
| """ |
| change_id = None |
| try: |
| # Gets the description of the last commit |
| commit_msg = subprocess.check_output(['git', 'log', '-1', '--format="%B"', 'HEAD'], text=True) |
| prefix = "Change-Id:" |
| for l in commit_msg.splitlines(): |
| if l.startswith(prefix): |
| change_id = l[len(prefix):].strip() |
| except: |
| return None |
| return change_id |
| |
| # Opens the current CL in the web browser. |
| change_id = GetChangeId() |
| if change_id is None: |
| print('No change ID found', file=sys.stderr) |
| sys.exit(1) |
| webbrowser.open_new_tab("https://fxrev.dev/" + change_id) |