summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-07-21 16:04:12 +0000
committerGerrit Code Review <review@openstack.org>2017-07-21 16:04:12 +0000
commitb3e0cac1aa5444662086dee1a776bfa352203ab4 (patch)
treec390d887f0e5429eb4dda5158361713bc51cded4
parent54221b107552b5a5d15a38f48196afcb31376682 (diff)
parentef4711d695d48ee729bce3e5935445d189274953 (diff)
downloadgit-review-b3e0cac1aa5444662086dee1a776bfa352203ab4.tar.gz
Merge "Added topic field to the list output"
-rwxr-xr-xgit_review/cmd.py32
-rw-r--r--git_review/tests/test_unit.py19
2 files changed, 40 insertions, 11 deletions
diff --git a/git_review/cmd.py b/git_review/cmd.py
index eaa4f28..0980bff 100755
--- a/git_review/cmd.py
+++ b/git_review/cmd.py
@@ -79,6 +79,7 @@ class colors(object):
yellow = '\033[33m'
green = '\033[92m'
reset = '\033[0m'
+ blue = '\033[36m'
class GitReviewException(Exception):
@@ -989,7 +990,7 @@ class CannotParseOpenChangesets(ChangeSetException):
EXIT_CODE = 33
-def list_reviews(remote):
+def list_reviews(remote, with_topic=False):
remote_url = get_remote_url(remote)
reviews = query_reviews(remote_url,
exception=CannotQueryOpenChangesets,
@@ -999,18 +1000,27 @@ def list_reviews(remote):
print("No pending reviews")
return
- REVIEW_FIELDS = ('number', 'branch', 'subject')
+ if with_topic is True:
+ REVIEW_FIELDS = ('number', 'branch', 'topic', 'subject')
+ # > is right justify, < is left, field indices for py26
+ review_field_format = ["{0:>{1}}", "{2:>{3}}", "{4:>{5}}", "{6:<{7}}"]
+ else:
+ REVIEW_FIELDS = ('number', 'branch', 'subject')
+ # > is right justify, < is left, field indices for py26
+ review_field_format = ["{0:>{1}}", "{2:>{3}}", "{4:<{5}}"]
+
FIELDS = range(len(REVIEW_FIELDS))
if check_use_color_output():
- review_field_color = (colors.yellow, colors.green, "")
+ if with_topic is True:
+ review_field_color = (colors.yellow, colors.green, colors.blue, "")
+ else:
+ review_field_color = (colors.yellow, colors.green, "")
color_reset = colors.reset
else:
- review_field_color = ("", "", "")
+ review_field_color = ("",) * len(REVIEW_FIELDS)
color_reset = ""
- # > is right justify, < is left, field indices for py26
- review_field_format = ["{0:>{1}}", "{2:>{3}}", "{4:<{5}}"]
- review_list = [[r[f] for f in REVIEW_FIELDS] for r in reviews]
+ review_list = [[r.get(f, '-') for f in REVIEW_FIELDS] for r in reviews]
review_field_width = dict()
# assume last field is longest and may exceed the console width in which
# case using the maximum value will result in extra blank lines appearing
@@ -1407,8 +1417,9 @@ def _main():
parser.add_argument("-f", "--finish", dest="finish", action="store_true",
help="Close down this branch and switch back to "
"master on successful submission")
- parser.add_argument("-l", "--list", dest="list", action="store_true",
- help="List available reviews for the current project")
+ parser.add_argument("-l", "--list", dest="list", action="count",
+ help="List available reviews for the current project, "
+ "if passed more than once, will show more information")
parser.add_argument("-y", "--yes", dest="yes", action="store_true",
help="Indicate that you do, in fact, understand if "
"you are submitting more than one patch")
@@ -1511,7 +1522,8 @@ def _main():
cherrypick_review("-x")
return
elif options.list:
- list_reviews(remote)
+ with_topic = options.list > 1
+ list_reviews(remote, with_topic=with_topic)
return
if options.custom_script:
diff --git a/git_review/tests/test_unit.py b/git_review/tests/test_unit.py
index 4a7570f..5f77994 100644
--- a/git_review/tests/test_unit.py
+++ b/git_review/tests/test_unit.py
@@ -63,7 +63,8 @@ class GitReviewConsole(testtools.TestCase, fixtures.TestWithFixtures):
{
'number': '1010101',
'branch': 'master',
- 'subject': 'A simple short subject'
+ 'subject': 'A simple short subject',
+ 'topic': 'simple-topic'
}, {
'number': '9877',
'branch': 'stable/codeword',
@@ -121,6 +122,22 @@ class GitReviewConsole(testtools.TestCase, fixtures.TestWithFixtures):
@mock.patch('git_review.cmd.query_reviews')
@mock.patch('git_review.cmd.get_remote_url', mock.MagicMock)
@mock.patch('git_review.cmd._has_color', False)
+ def test_list_reviews_output_with_topic(self, mock_query):
+
+ mock_query.return_value = self.reviews
+ with mock.patch('sys.stdout', new_callable=io.StringIO) as output:
+ cmd.list_reviews(None, with_topic=True)
+ console_output = output.getvalue().split('\n')
+
+ self.assertEqual(
+ ['1010101 master simple-topic A simple short subject',
+ ' 9877 stable/codeword - A longer and slightly '
+ 'more wordy subject'],
+ console_output[:2])
+
+ @mock.patch('git_review.cmd.query_reviews')
+ @mock.patch('git_review.cmd.get_remote_url', mock.MagicMock)
+ @mock.patch('git_review.cmd._has_color', False)
def test_list_reviews_no_blanks(self, mock_query):
mock_query.return_value = self.reviews