Commit 1ee78cda authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by LUCI CQ

git cl: use short URLs in `git cl status`.

This also applies to git map-branches.

R=ehmaldonado

Change-Id: Ica9bc92660716c15cbdd6bfd77b93f08bd0d8f9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2099329
Commit-Queue: Andrii Shyshkalov <tandrii@google.com>
Auto-Submit: Andrii Shyshkalov <tandrii@google.com>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
parent 4c7c4b4b
......@@ -129,6 +129,12 @@ settings = None
_IS_BEING_TESTED = False
_KNOWN_GERRIT_TO_SHORT_URLS = {
'https://chrome-internal-review.googlesource.com': 'https://crrev.com/i',
'https://chromium-review.googlesource.com': 'https://crrev.com/c',
}
def DieWithError(message, change_desc=None):
if change_desc:
SaveDescriptionBackup(change_desc)
......@@ -1257,12 +1263,15 @@ class Changelist(object):
self.lookedup_issue = True
return self.issue
def GetIssueURL(self):
def GetIssueURL(self, short=False):
"""Get the URL for a particular issue."""
issue = self.GetIssue()
if not issue:
return None
return '%s/%s' % (self.GetCodereviewServer(), issue)
server = self.GetCodereviewServer()
if short:
server = _KNOWN_GERRIT_TO_SHORT_URLS.get(server, server)
return '%s/%s' % (server, issue)
def FetchDescription(self, pretty=False):
assert self.GetIssue(), 'issue is required to query Gerrit'
......@@ -3783,7 +3792,7 @@ def CMDstatus(parser, args):
c, status = next(output)
branch_statuses[c.GetBranch()] = status
status = branch_statuses.pop(branch)
url = cl.GetIssueURL()
url = cl.GetIssueURL(short=True)
if url and (not status or status == 'error'):
# The issue probably doesn't exist anymore.
url += ' (broken)'
......
......@@ -140,9 +140,8 @@ class BranchMapper(object):
# This is a blocking get which waits for the remote CL status to be
# retrieved.
for cl, status in status_info:
self.__status_info[cl.GetBranch()] = (cl.GetIssueURL(),
color_for_status(status),
status)
self.__status_info[cl.GetBranch()] = (cl.GetIssueURL(short=True),
color_for_status(status), status)
roots = set()
......
......@@ -249,6 +249,18 @@ class TestGitClBasic(unittest.TestCase):
self.assertEqual(
set([(changes[0], 'waiting'), (changes[1], 'error')]), actual)
def test_get_issue_url(self):
cl = git_cl.Changelist(issue=123)
cl._gerrit_server = 'https://example.com'
self.assertEqual(cl.GetIssueURL(), 'https://example.com/123')
self.assertEqual(cl.GetIssueURL(short=True), 'https://example.com/123')
cl = git_cl.Changelist(issue=123)
cl._gerrit_server = 'https://chromium-review.googlesource.com'
self.assertEqual(cl.GetIssueURL(),
'https://chromium-review.googlesource.com/123')
self.assertEqual(cl.GetIssueURL(short=True), 'https://crrev.com/c/123')
def test_set_preserve_tryjobs(self):
d = git_cl.ChangeDescription('Simple.')
d.set_preserve_tryjobs()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment