Skip to content

Commit 2be87b9

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 2be87b9

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

bugz/cli.py

Lines changed: 36 additions & 9 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'):
@@ -456,10 +453,6 @@ def modify(settings):
456453
if 'cc' not in params:
457454
params['cc'] = {}
458455
params['cc']['remove'] = settings.cc_remove
459-
if hasattr(settings, 'comment'):
460-
if 'comment' not in params:
461-
params['comment'] = {}
462-
params['comment']['body'] = settings.comment
463456
if hasattr(settings, 'component'):
464457
params['component'] = settings.component
465458
if hasattr(settings, 'dupe_of'):
@@ -525,9 +518,43 @@ def modify(settings):
525518
params['status'] = 'RESOLVED'
526519
params['resolution'] = 'INVALID'
527520

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