From 59d4199b23b10f09a48d518e7fcd478c862544ca Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 26 Dec 2014 15:05:26 +0800 Subject: [PATCH] MDK Tracker commenting --- extra/bash_completion | 2 +- mdk/commands/tracker.py | 13 ++++++++++++- mdk/jira.py | 13 +++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/extra/bash_completion b/extra/bash_completion index d4e96df..0a2220c 100644 --- a/extra/bash_completion +++ b/extra/bash_completion @@ -219,7 +219,7 @@ function _mdk() { fi ;; tracker) - OPTS="--testing --add-labels --remove-labels" + OPTS="--testing --add-labels --remove-labels --comment" ;; update) OPTS="--integration --stable --all --upgrade --update-cache" diff --git a/mdk/commands/tracker.py b/mdk/commands/tracker.py index 6ed449a..3ba7f1b 100644 --- a/mdk/commands/tracker.py +++ b/mdk/commands/tracker.py @@ -27,7 +27,7 @@ import textwrap import re from ..command import Command from ..jira import Jira -from ..tools import parseBranch +from ..tools import parseBranch, getText class TrackerCommand(Command): @@ -66,6 +66,13 @@ class TrackerCommand(Command): 'metavar': 'labels', 'nargs': '+', } + ), + ( + ['--comment'], + { + 'action': 'store_true', + 'help': 'add a comment to the issue', + } ) ] _description = 'Interact with Moodle tracker' @@ -105,6 +112,10 @@ class TrackerCommand(Command): self.argumentError('The label \'triaging_in_progress\' cannot be removed using MDK') self.Jira.removeLabels(self.mdl, args.removelabels) + if args.comment: + comment = getText() + self.Jira.addComment(self.mdl, comment) + self.info(args) def info(self, args): diff --git a/mdk/jira.py b/mdk/jira.py index 1108453..a119b17 100644 --- a/mdk/jira.py +++ b/mdk/jira.py @@ -68,6 +68,19 @@ class Jira(object): self._load() + def addComment(self, key, comment): + """Add a comment to an issue""" + + assert isinstance(comment, str), "Expected a string" + + data = [ + {'add': {'body': comment}} + ] + + self.updateIssue(key, {'update': {'comment': data}}) + + return True + def addLabels(self, key, labels): """Add labels to an issue""" -- 2.11.0