Allow specifying remote branch at listing changes

Signed-off-by: You-Sheng Yang (vicamo) <vicamo@gmail.com>
Change-Id: I9267598fcf2eb9316023c453d29bb1ffe4f94404
This commit is contained in:
You-Sheng Yang (vicamo)
2023-02-08 00:11:02 +08:00
parent 52752c85d3
commit 7951e9a0a9
2 changed files with 16 additions and 6 deletions

View File

@@ -46,6 +46,7 @@
.Op Ar branch
.Nm
.Fl l
.Op Ar branch
.Nm
.Fl \-version
.Sh DESCRIPTION

View File

@@ -623,7 +623,7 @@ def parse_gerrit_ssh_params_from_git_url(git_url):
return (hostname, username, port, project_name)
def query_reviews(remote_url, project=None, change=None,
def query_reviews(remote_url, project=None, branch=None, change=None,
current_patch_set=True, exception=CommandFailed,
parse_exc=Exception):
if remote_url.startswith('http://') or remote_url.startswith('https://'):
@@ -632,13 +632,14 @@ def query_reviews(remote_url, project=None, change=None,
query = query_reviews_over_ssh
return query(remote_url,
project=project,
branch=branch,
change=change,
current_patch_set=current_patch_set,
exception=exception,
parse_exc=parse_exc)
def query_reviews_over_http(remote_url, project=None, change=None,
def query_reviews_over_http(remote_url, project=None, branch=None, change=None,
current_patch_set=True, exception=CommandFailed,
parse_exc=Exception):
if project:
@@ -666,7 +667,10 @@ def query_reviews_over_http(remote_url, project=None, change=None,
else:
project_name = re.sub(r"^/|(\.git$)", "",
urlparse(remote_url).path)
params = urlencode({'q': 'project:%s status:open' % project_name})
query = 'project:%s status:open' % project_name
if branch:
query += ' branch:%s' % branch
params = urlencode({'q': query})
url += '?' + params
if VERBOSE:
@@ -696,7 +700,7 @@ def query_reviews_over_http(remote_url, project=None, change=None,
return reviews
def query_reviews_over_ssh(remote_url, project=None, change=None,
def query_reviews_over_ssh(remote_url, project=None, branch=None, change=None,
current_patch_set=True, exception=CommandFailed,
parse_exc=Exception):
(hostname, username, port, project_name) = \
@@ -709,6 +713,8 @@ def query_reviews_over_ssh(remote_url, project=None, change=None,
query = "--patch-sets change:%s" % change
else:
query = "project:%s status:open" % project_name
if branch:
query += ' branch:%s' % branch
port_data = "p%s" % port if port is not None else ""
if username is None:
@@ -1150,12 +1156,13 @@ class ReviewsPrinter(object):
print("Found %d items for review" % total_reviews)
def list_reviews(remote, project, with_topic=False):
def list_reviews(remote, project, branch=None, with_topic=False):
remote_url = get_remote_url(remote)
reviews = []
for r in query_reviews(remote_url,
project=project,
branch=branch,
exception=CannotQueryOpenChangesets,
parse_exc=CannotParseOpenChangesets):
reviews.append(Review(r))
@@ -1752,7 +1759,9 @@ additional information:
return
elif options.list:
with_topic = options.list > 1
list_reviews(remote, config['project'], with_topic=with_topic)
list_reviews(remote, config['project'],
branch if options.branch or options.track else None,
with_topic=with_topic)
return
if options.custom_script: