Skip to content

Commit

Permalink
Add -Q to modify.
Browse files Browse the repository at this point in the history
This allows to quote as many most recent bug comments in your reply
as you need.
  • Loading branch information
glebius committed Dec 21, 2023
1 parent 460b4c5 commit 1e44c7f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
36 changes: 31 additions & 5 deletions bugz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import datetime
import getpass
import os
import re
Expand Down Expand Up @@ -422,10 +423,6 @@ def modify(settings):
hasattr(settings, 'reset_assigned_to'):
raise BugzError('--assigned-to and --unassign cannot be used together')

if hasattr(settings, 'comment_editor'):
settings.comment = block_edit('Enter comment:',
comment_from=settings.comment)

params = {}
params['ids'] = [settings.bugid]
if hasattr(settings, 'alias'):
Expand Down Expand Up @@ -525,9 +522,38 @@ def modify(settings):
params['status'] = 'RESOLVED'
params['resolution'] = 'INVALID'

check_auth(settings)

if hasattr(settings, 'comment_editor'):
quotes=''
if hasattr(settings, 'quote'):
bug_comments = settings.call_bz(settings.bz.Bug.comments, params)
bug_comments = bug_comments['bugs']['%s' % settings.bugid]\
['comments'][-settings.quote:]
wrapper = textwrap.TextWrapper(width=settings.columns,
break_long_words=False,
break_on_hyphens=False)
for comment in bug_comments:
what = comment['text']
if what is None:
continue
who = comment['creator']
when = comment['time']
when = datetime.datetime.strptime(str(when), '%Y%m%dT%H:%M:%S')
quotes += 'On %s, %s wrote:\n' % \
(when.strftime('%Y-%m-%d %H:%M:%S UTC'), who)
for line in what.splitlines():
if len(line) < settings.columns:
quotes += '> %s\n' % line
else:
for shortline in wrapper.wrap(line):
quotes += '> %s\n' % shortline
settings.comment = block_edit('Enter comment:',
comment_from=settings.comment,
quotes=quotes)

if len(params) < 2:
raise BugzError('No changes were specified')
check_auth(settings)
result = settings.call_bz(settings.bz.Bug.update, params)
for bug in result['bugs']:
changes = bug['changes']
Expand Down
3 changes: 3 additions & 0 deletions bugz/cli_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def make_arg_parser():
help='change the priority for this bug')
modify_parser.add_argument('--product',
help='change the product for this bug')
modify_parser.add_argument('-Q', '--quote',
action='count',
help='quote most recent comment(s) with -C')
modify_parser.add_argument('-r', '--resolution',
help='set new resolution '
'(if status = RESOLVED)')
Expand Down
9 changes: 6 additions & 3 deletions bugz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ def terminal_width():
return width


def launch_editor(initial_text, comment_from='', comment_prefix='BUGZ:'):
def launch_editor(initial_text, comment_from='', comment_prefix='BUGZ:',
quotes=''):
"""Launch an editor with some default text.
Lifted from Mercurial 0.9.
@rtype: string
"""
(fd, name) = tempfile.mkstemp("bugz")
f = os.fdopen(fd, "w")
f.write(quotes)
f.write(comment_from)
f.write(initial_text)
f.close()
Expand All @@ -98,7 +100,7 @@ def launch_editor(initial_text, comment_from='', comment_prefix='BUGZ:'):
return ''


def block_edit(comment, comment_from=''):
def block_edit(comment, comment_from='', quotes=''):
editor = (os.environ.get('BUGZ_EDITOR') or os.environ.get('EDITOR'))

if not editor:
Expand All @@ -109,7 +111,8 @@ def block_edit(comment, comment_from=''):
initial_text = '\n'.join(['BUGZ: %s' % line
for line in comment.splitlines()])
new_text = launch_editor(BUGZ_COMMENT_TEMPLATE % initial_text,
comment_from=comment_from)
comment_from=comment_from,
quotes=quotes)

if new_text.strip():
return new_text
Expand Down

0 comments on commit 1e44c7f

Please sign in to comment.