Skip to content

Commit 1e44c7f

Browse files
committed
Add -Q to modify.
This allows to quote as many most recent bug comments in your reply as you need.
1 parent 460b4c5 commit 1e44c7f

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

bugz/cli.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1818
"""
1919

20+
import datetime
2021
import getpass
2122
import os
2223
import re
@@ -422,10 +423,6 @@ def modify(settings):
422423
hasattr(settings, 'reset_assigned_to'):
423424
raise BugzError('--assigned-to and --unassign cannot be used together')
424425

425-
if hasattr(settings, 'comment_editor'):
426-
settings.comment = block_edit('Enter comment:',
427-
comment_from=settings.comment)
428-
429426
params = {}
430427
params['ids'] = [settings.bugid]
431428
if hasattr(settings, 'alias'):
@@ -525,9 +522,38 @@ def modify(settings):
525522
params['status'] = 'RESOLVED'
526523
params['resolution'] = 'INVALID'
527524

525+
check_auth(settings)
526+
527+
if hasattr(settings, 'comment_editor'):
528+
quotes=''
529+
if hasattr(settings, 'quote'):
530+
bug_comments = settings.call_bz(settings.bz.Bug.comments, params)
531+
bug_comments = bug_comments['bugs']['%s' % settings.bugid]\
532+
['comments'][-settings.quote:]
533+
wrapper = textwrap.TextWrapper(width=settings.columns,
534+
break_long_words=False,
535+
break_on_hyphens=False)
536+
for comment in bug_comments:
537+
what = comment['text']
538+
if what is None:
539+
continue
540+
who = comment['creator']
541+
when = comment['time']
542+
when = datetime.datetime.strptime(str(when), '%Y%m%dT%H:%M:%S')
543+
quotes += 'On %s, %s wrote:\n' % \
544+
(when.strftime('%Y-%m-%d %H:%M:%S UTC'), who)
545+
for line in what.splitlines():
546+
if len(line) < settings.columns:
547+
quotes += '> %s\n' % line
548+
else:
549+
for shortline in wrapper.wrap(line):
550+
quotes += '> %s\n' % shortline
551+
settings.comment = block_edit('Enter comment:',
552+
comment_from=settings.comment,
553+
quotes=quotes)
554+
528555
if len(params) < 2:
529556
raise BugzError('No changes were specified')
530-
check_auth(settings)
531557
result = settings.call_bz(settings.bz.Bug.update, params)
532558
for bug in result['bugs']:
533559
changes = bug['changes']

bugz/cli_argparser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def make_arg_parser():
190190
help='change the priority for this bug')
191191
modify_parser.add_argument('--product',
192192
help='change the product for this bug')
193+
modify_parser.add_argument('-Q', '--quote',
194+
action='count',
195+
help='quote most recent comment(s) with -C')
193196
modify_parser.add_argument('-r', '--resolution',
194197
help='set new resolution '
195198
'(if status = RESOLVED)')

bugz/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ def terminal_width():
7272
return width
7373

7474

75-
def launch_editor(initial_text, comment_from='', comment_prefix='BUGZ:'):
75+
def launch_editor(initial_text, comment_from='', comment_prefix='BUGZ:',
76+
quotes=''):
7677
"""Launch an editor with some default text.
7778
7879
Lifted from Mercurial 0.9.
7980
@rtype: string
8081
"""
8182
(fd, name) = tempfile.mkstemp("bugz")
8283
f = os.fdopen(fd, "w")
84+
f.write(quotes)
8385
f.write(comment_from)
8486
f.write(initial_text)
8587
f.close()
@@ -98,7 +100,7 @@ def launch_editor(initial_text, comment_from='', comment_prefix='BUGZ:'):
98100
return ''
99101

100102

101-
def block_edit(comment, comment_from=''):
103+
def block_edit(comment, comment_from='', quotes=''):
102104
editor = (os.environ.get('BUGZ_EDITOR') or os.environ.get('EDITOR'))
103105

104106
if not editor:
@@ -109,7 +111,8 @@ def block_edit(comment, comment_from=''):
109111
initial_text = '\n'.join(['BUGZ: %s' % line
110112
for line in comment.splitlines()])
111113
new_text = launch_editor(BUGZ_COMMENT_TEMPLATE % initial_text,
112-
comment_from=comment_from)
114+
comment_from=comment_from,
115+
quotes=quotes)
113116

114117
if new_text.strip():
115118
return new_text

0 commit comments

Comments
 (0)