Skip to content

Start Peer Review transition #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extra/bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ function _mdk() {
OPTS="--integration --stable --all --list $(_list_instances)"
fi
;;
tracker)
OPTS="--testing --add-labels --remove-labels --comment --start-review --fail-review --start-development --stop-development --list-transitions"
;;
update)
OPTS="--integration --stable --all --upgrade --update-cache"
if [[ "$CUR" != -* ]]; then
Expand Down
174 changes: 173 additions & 1 deletion mdk/commands/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,72 @@ class TrackerCommand(Command):
'help': 'MDL issue number. Guessed from the current branch if not specified.',
'nargs': '?'
}
),
(
['--add-labels'],
{
'action': 'store',
'help': 'Add the specified labels to the issue',
'nargs': '+',
'dest': 'addlabels'
}
),
(
['--remove-labels'],
{
'action': 'store',
'help': 'Remove the specified labels from the issue',
'nargs': '+',
'dest': 'removelabels'
}
),
(
['--start-review'],
{
'action': 'store_true',
'help': 'Change the status to Peer-review in progress and assign self as reviewer',
'dest': 'reviewStart'
}
),
(
['--fail-review'],
{
'action': 'store_true',
'help': 'Change the status to Peer-review in progress and assign self as reviewer',
'dest': 'reviewFail'
}
),
(
['--start-development'],
{
'action': 'store_true',
'help': 'Change the status to Development in progress and assign self as assignee',
'dest': 'developmentStart'
}
),
(
['--stop-development'],
{
'action': 'store_true',
'help': 'Stop development of the issue if you are the reviewer',
'dest': 'developmentStop'
}
),
(
['--list-transitions'],
{
'action': 'store_true',
'help': 'List the available status transitions',
'dest': 'transitions'
}
),
(
['--comment'],
{
'action': 'store_true',
'help': 'Add a comment to the issue',
'dest': 'comment'
}
)
]
_description = 'Retrieve information from the tracker'
Expand All @@ -70,7 +136,97 @@ def run(self, args):

self.Jira = Jira()
self.mdl = 'MDL-' + re.sub(r'(MDL|mdl)(-|_)?', '', issue)
self.info(args)

changesMade = False
labelChanges = {
'added': [],
'removed': [],
'nochange': []
}

newComments = []
transitionChanges = {}

if args.addlabels:
result = self.Jira.addLabels(self.mdl, args.addlabels)
labelChanges['added'].extend(result['added'])
labelChanges['nochange'].extend(result['nochange'])

if len(result['added']):
changesMade = True

if args.removelabels:
result = self.Jira.removeLabels(self.mdl, args.removelabels)
labelChanges['removed'].extend(result['removed'])
labelChanges['nochange'].extend(result['nochange'])

if len(result['removed']):
changesMade = True

if args.developmentStart:
transitionChanges = self.Jira.developmentStart(self.mdl)

elif args.developmentStop:
transitionChanges = self.Jira.developmentStop(self.mdl)

elif args.reviewStart:
transitionChanges = self.Jira.reviewStart(self.mdl)

elif args.reviewFail:
transitionChanges = self.Jira.reviewFail(self.mdl)

if transitionChanges:
changesMade = True
if 'comment' in transitionChanges['data']['update']:
for comment in transitionChanges['data']['update']['comment']:
newComments.append(comment['add'])

if args.comment:
newComment =self.Jira.addComment(self.mdl)
if newComment:
changesMade = True
newComments.append(newComment)

issueInfo = self.info(args)

if changesMade or len(labelChanges['nochange']):
if changesMade:
print u'Changes were made to this issue:'

if len(transitionChanges):
print '* State changed from "%s" to "%s"' % (transitionChanges['original'].get('fields')['status']['name'], issueInfo.get('fields')['status']['name'])

if len(labelChanges['added']):
labels = u'{0}: {1}'.format('Labels added', ', '.join(labelChanges['added']))
for l in textwrap.wrap(labels, 68, initial_indent='* ', subsequent_indent=' '):
print l

if len(labelChanges['removed']):
labels = u'{0}: {1}'.format('Labels removed', ', '.join(labelChanges['removed']))
for l in textwrap.wrap(labels, 68, initial_indent='* ', subsequent_indent=' '):
print l

if len(labelChanges['nochange']):
print u'Some changes were not made to this issue:'
labels = u'{0}: {1}'.format('Labels unchanged', ', '.join(labelChanges['nochange']))
for l in textwrap.wrap(labels, 68, initial_indent='* ', subsequent_indent=' '):
print l

if len(newComments):
print u'* Some comments were added:'
for comment in newComments:
if 'id' in comment:
commenturl = "%s%s/browse/%s?focusedCommentId=%s" % (self.Jira.url, self.Jira.uri, self.mdl, comment['id'])
commentlink = u'- %s ' % commenturl
print '{0:->70}--'.format(commentlink)
else:
print u'-' * 72

# Note: Do not wrap the comment as it's not really meant to be wrapped again. The editor may have
# already wrapped it, or the markdown may just look a bit crap.
print comment['body']

print u'-' * 72

def info(self, args):
"""Display classic information about an issue"""
Expand All @@ -88,6 +244,12 @@ def info(self, args):
print u' {0} - {1} - {2}'.format(issue['fields']['issuetype']['name'], issue['fields']['priority']['name'], u'https://tracker.moodle.org/browse/' + issue['key'])
status = u'{0} {1} {2}'.format(issue['fields']['status']['name'], resolution, resolutiondate).strip()
print u' {0}'.format(status)

if issue['fields']['labels']:
labels = u'{0}: {1}'.format('Labels', ', '.join(issue['fields']['labels']))
for l in textwrap.wrap(labels, 68, initial_indent=' ', subsequent_indent=' '):
print l

vw = u'[ V: %d - W: %d ]' % (issue['fields']['votes']['votes'], issue['fields']['watches']['watchCount'])
print '{0:->70}--'.format(vw)
print u'{0:<20}: {1} ({2}) on {3}'.format('Reporter', issue['fields']['reporter']['displayName'], issue['fields']['reporter']['name'], created)
Expand All @@ -108,3 +270,13 @@ def info(self, args):
print ' ' + l

print u'-' * 72

if args.transitions:
transitions = self.Jira.getTransitions(self.mdl)
print u'The following status transitions are available to this issue:'
for transition in transitions:
print u'* %s' % transition

print u'-' * 72

return issue
Loading