1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-09 22:36:14 +01:00

Improve 'osc rq show' output

* Add 'Created by' field
* Make formatting more consistent across the sections
This commit is contained in:
Daniel Mach 2022-09-15 20:45:46 +02:00
parent 584fd5e0f4
commit 056e6f1dde
4 changed files with 69 additions and 60 deletions

View File

@ -3031,6 +3031,7 @@ class Request:
if self.state.name == 'review' and self.state.approver:
status += "(approved)"
lines = ['%6s State:%-10s By:%-12s When:%-19s' % (self.reqid, status, self.state.who, self.state.when)]
lines += [f" Created by: {self.creator}"]
tmpl = ' %(type)-16s %(source)-50s %(target)s'
for action in self.actions:
lines.append(tmpl % self.format_action(action))
@ -3049,58 +3050,58 @@ class Request:
def __str__(self):
"""return "detailed" format"""
lines = ['Request: #%s\n' % self.reqid]
lines = [
f"Request: {self.reqid}",
f"Created by: {self.creator}",
]
if self.accept_at and self.state.name in ['new', 'review']:
lines.append(' *** This request will get automatically accepted after ' + self.accept_at + ' ! ***\n')
if self.priority in ['critical', 'important'] and self.state.name in ['new', 'review']:
lines.append(' *** This request has classified as ' + self.priority + ' ! ***\n')
if self.state and self.state.approver and self.state.name == 'review':
lines.append(' *** This request got approved by ' + self.state.approver + '. It will get automatically accepted after last review got accepted! ***\n')
lines += ["", "Actions:"]
for action in self.actions:
tmpl = ' %(type)-13s %(source)s %(target)s'
fmt_action = self.format_action(action, show_srcupdate=True)
if action.type == 'delete':
# remove 1 whitespace because source is empty
tmpl = ' %(type)-12s %(source)s %(target)s'
lines.append(tmpl % self.format_action(action, show_srcupdate=True))
lines.append('\n\nMessage:')
if self.description:
lines.append(self.description)
else:
lines.append('<no message>')
lines += [f" {fmt_action['type']:13} {fmt_action['target']}"]
else:
lines += [f" {fmt_action['type']:13} {fmt_action['source']} {fmt_action['target']}"]
lines += ["", "Message:", textwrap.indent(self.description or "<no message>", prefix=" ")]
if self.state:
lines.append('\nState: %-10s %-12s %s' % (self.state.name, self.state.when, self.state.who))
lines.append('Comment: %s' % (self.state.comment or '<no comment>'))
lines += ["", "State:", f" {self.state.name:61} {self.state.when:12} {self.state.who}"]
if self.state.comment:
lines += [textwrap.indent(self.state.comment, prefix=" | ", predicate=lambda line: True)]
indent = '\n '
tmpl = '%(state)-10s %(by)-50s %(when)-12s %(who)-20s %(comment)s'
reviews = []
for review in reversed(self.reviews):
d = {'state': review.state}
if review.by_user:
d['by'] = "User: " + review.by_user
if review.by_group:
d['by'] = "Group: " + review.by_group
if review.by_package:
d['by'] = "Package: " + review.by_project + "/" + review.by_package
elif review.by_project:
d['by'] = "Project: " + review.by_project
d['when'] = review.when or ''
d['who'] = review.who or ''
d['comment'] = ''
if review.comment:
d['comment'] = '\n ' + review.comment
reviews.append(tmpl % d)
if reviews:
lines.append('\nReview: %s' % indent.join(reviews))
if self.reviews:
lines += [""]
lines += ["Review:"]
for review in reversed(self.reviews):
d = {'state': review.state}
if review.by_user:
d['by'] = "User: " + review.by_user
if review.by_group:
d['by'] = "Group: " + review.by_group
if review.by_package:
d['by'] = "Package: " + review.by_project + "/" + review.by_package
elif review.by_project:
d['by'] = "Project: " + review.by_project
d['when'] = review.when or ''
d['who'] = review.who or ''
lines += [f" {d['state']:10} {d['by']:50} {d['when']:12} {d['who']}"]
if review.comment:
lines += [textwrap.indent(review.comment, prefix=" | ", predicate=lambda line: True)]
tmpl = '%(when)-10s %(who)-12s %(desc)s'
histories = []
for hist in reversed(self.statehistory):
d = {'when': hist.when, 'who': hist.who, 'desc': hist.description}
histories.append(tmpl % d)
if histories:
lines.append('\nHistory: %s' % indent.join(histories))
if self.statehistory:
lines += ["", "History:"]
for hist in reversed(self.statehistory):
lines += [f" {hist.when:10} {hist.who:30} {hist.description}"]
return '\n'.join(lines)

View File

@ -1,5 +1,5 @@
<collection matches="1">
<request id="148023">
<request creator="creator" id="148023">
<action type="submit">
<source project="home:user:branches:some:project" package="common-two" rev="7"/>
<target project="some:project" package="common-two"/>

View File

@ -224,6 +224,7 @@ identical: common-three
differs: common-two
148023 State:new By:user When:2013-01-11T11:04:14
Created by: creator
submit: home:user:branches:some:project/common-two@7 -> some:project
Descr: - Fix it to work - Improve support for something

View File

@ -432,6 +432,7 @@ class TestRequest(OscTestCase):
xml = self._get_fixture('test_request_list_view1.xml')
exp = """\
62 State:new By:Admin When:2010-12-29T14:57:25
Created by: Admin
set_bugowner: buguser foo
add_role: person: xyz as maintainer, group: group1 as reader foobar
add_role: person: abc as reviewer foo/bar
@ -451,6 +452,7 @@ class TestRequest(OscTestCase):
r.read(ET.fromstring(xml))
exp = """\
21 State:accepted By:foobar When:2010-12-29T16:37:45
Created by: foobar
set_bugowner: buguser foo
From: Created Request: user -> Review Approved: foobar
Descr: This is a simple request with a lot of ... ... text and other
@ -466,28 +468,32 @@ class TestRequest(OscTestCase):
r.read(ET.fromstring(xml))
self.assertEqual(r.creator, 'creator')
exp = """\
Request: #123
Request: 123
Created by: creator
Actions:
submit: xyz/abc(cleanup) -> foo ***update link***
add_role: person: bar as maintainer, group: groupxyz as reader home:foo
Message:
just a samll description
in order to describe this
request - blablabla
test.
just a samll description
in order to describe this
request - blablabla
test.
State: review 2010-12-27T01:36:29 abc
Comment: currently in review
State:
review 2010-12-27T01:36:29 abc
| currently in review
Review: accepted Group: group1 2010-12-29T00:11:22 abc
accepted
new Group: group1 2010-12-28T00:11:22 abc
review start
Review:
accepted Group: group1 2010-12-29T00:11:22 abc
| accepted
new Group: group1 2010-12-28T00:11:22 abc
| review start
History: 2010-12-12T00:00:00 creator revoked
2010-12-11T00:00:00 creator new"""
History:
2010-12-12T00:00:00 creator revoked
2010-12-11T00:00:00 creator new"""
self.assertEqual(exp, str(r))
def test_request_str2(self):
@ -507,17 +513,18 @@ History: 2010-12-12T00:00:00 creator revoked
r.read(ET.fromstring(xml))
self.assertEqual(r.creator, 'creator')
exp = """\
Request: #98765
Request: 98765
Created by: creator
Actions:
change_devel: foo/bar developed in devprj/devpkg
delete: deleteme
Message:
<no message>
<no message>
State: new 2010-12-29T00:11:22 creator
Comment: <no comment>"""
State:
new 2010-12-29T00:11:22 creator"""
self.assertEqual(exp, str(r))
def test_legacy_request(self):