Move Comment fetching into click callback
Instead of calling the get_comment() we now have a callback for click, that's called to validate and transform the given comment id into a Comment object from JIRA.
This commit is contained in:
parent
f0b455326e
commit
ead0cf51de
|
@ -490,7 +490,12 @@ def comment_create(client, issue):
|
||||||
client.add_comment(issue.key, text)
|
client.add_comment(issue.key, text)
|
||||||
|
|
||||||
|
|
||||||
def get_comment(client, issue, comment_id):
|
def get_comment(ctx, param, comment_id):
|
||||||
|
"""click callback returning a Comment for the comment_id value given by the user"""
|
||||||
|
from jira.exceptions import JIRAError
|
||||||
|
|
||||||
|
issue = ctx.obj['issue']
|
||||||
|
|
||||||
if not comment_id:
|
if not comment_id:
|
||||||
from clintermission import cli_select_item
|
from clintermission import cli_select_item
|
||||||
options = []
|
options = []
|
||||||
|
@ -501,18 +506,21 @@ def get_comment(client, issue, comment_id):
|
||||||
options.append((f"{comment.created} - {comment.author} - {body}", comment.id))
|
options.append((f"{comment.created} - {comment.author} - {body}", comment.id))
|
||||||
_, comment_id = cli_select_item(options)
|
_, comment_id = cli_select_item(options)
|
||||||
|
|
||||||
return client.comment(issue.key, comment_id, expand=['body'])
|
client = ctx.obj['client']
|
||||||
|
try:
|
||||||
|
return client.comment(issue.key, comment_id, expand=['body'])
|
||||||
|
except JIRAError as e:
|
||||||
|
raise click.ClickException(f"Problem retrieving {comment_id} for issue {issue.key}: {e.text}")
|
||||||
|
|
||||||
|
|
||||||
@comment.command('edit')
|
@comment.command('edit')
|
||||||
@click.argument('comment_id', required=False)
|
@click.argument('comment', required=False, callback=get_comment)
|
||||||
@pass_issue
|
@pass_issue
|
||||||
@pass_client
|
@pass_client
|
||||||
def comment_edit(client, issue, comment_id):
|
def comment_edit(client, issue, comment):
|
||||||
"""Edit the text of an issues comment"""
|
"""Edit the text of an issues comment"""
|
||||||
comment = get_comment(client, issue, comment_id)
|
|
||||||
|
|
||||||
text = prompt(f"Comment text to set as new body for comment {comment_id} on {issue.key}",
|
text = prompt(f"Comment text to set as new body for comment {comment.id} on {issue.key}",
|
||||||
initial_content=comment.body)
|
initial_content=comment.body)
|
||||||
if text == comment.body:
|
if text == comment.body:
|
||||||
print("No changes. Aborting.")
|
print("No changes. Aborting.")
|
||||||
|
@ -522,12 +530,10 @@ def comment_edit(client, issue, comment_id):
|
||||||
|
|
||||||
|
|
||||||
@comment.command('delete')
|
@comment.command('delete')
|
||||||
@click.argument('comment_id', required=False)
|
@click.argument('comment', required=False, callback=get_comment)
|
||||||
@pass_issue
|
@pass_issue
|
||||||
@pass_client
|
@pass_client
|
||||||
def comment_delete(client, issue, comment_id):
|
def comment_delete(client, issue, comment):
|
||||||
comment = get_comment(client, issue, comment_id)
|
|
||||||
|
|
||||||
# TODO print formatted comment for verification
|
# TODO print formatted comment for verification
|
||||||
click.confirm("Do you really want to delete this ^ ?", abort=True)
|
click.confirm("Do you really want to delete this ^ ?", abort=True)
|
||||||
comment.delete()
|
comment.delete()
|
||||||
|
|
Loading…
Reference in New Issue