From 489aac856ddbc4916c4d98566e2946f6c78e6460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Peccatte?= Date: Thu, 16 Jun 2016 16:46:59 +0200 Subject: [PATCH] Fixes #8550: rudder-dev wip should add a comment on the bugtracker --- scripts/rudder-dev/redmine.py | 44 ++++++++++++++++++++++++++++++- scripts/rudder-dev/rudder-dev-src | 11 ++++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/scripts/rudder-dev/redmine.py b/scripts/rudder-dev/redmine.py index cf7c8250..1f18b6cf 100644 --- a/scripts/rudder-dev/redmine.py +++ b/scripts/rudder-dev/redmine.py @@ -151,12 +151,54 @@ def branch_name(self): id = 'i' + str(self.id) else: id = str(self.id) - if info['private']: + if self['private']: branch_name = Config.TRACKER_NAME_MAPPING[self['type']] + "_" + id + "/_" else: branch_name = Config.TRACKER_NAME_MAPPING[self['type']] + "_" + id + "/" + branchified_name return branch_name + # Change ticket state and comment it + def update(self, user_id=None, pr_url=None, message=None, status=None): + # Create note content + note = None + if pr_url is not None: + note = "PR " + pr_url + if message is not None: + if note is None: + note = message + else: + note += "\n" + message + + ticket_info = { 'issue': {} } + if can_modify_issues(self['project_id']): + # fill ticket data with developer available content + if status is not None: + ticket_info['issue']['status_id'] = status + if user_id is not None: + ticket_info['issue']['assigned_to_id'] = user_id + if note is not None: + ticket_info['issue']['notes'] = note + if pr_url is not None: + ticket_info['issue']['custom_fields'] = [ { 'id': Config.CUSTOM_FIELD_PR, 'value': pr_url } ] + + else: + # just append the note to ticket, if any + if note is None: + return + else: + ticket_info['issue']['notes'] = note + + # call the api + url = Config.REDMINE_API_URL + "/issues/" + str(self.id) + ".json" + ticket_json = json.dumps(ticket_info) + ret = requests.put(url, headers = {'X-Redmine-API-Key': Config.REDMINE_TOKEN, 'Content-Type': 'application/json' }, data=ticket_json ) + if ret.status_code != 200: + logfail("Ticket Update error: " + ret.reason) + print(ret.text) + if not Config.force: + exit(3) + + def issue_from_branch(branch): """Create issue object from given branch""" match = re.match(r'[A-Za-z]+_(i?\d+)/.*', branch) diff --git a/scripts/rudder-dev/rudder-dev-src b/scripts/rudder-dev/rudder-dev-src index 1155e8f8..346366a1 100755 --- a/scripts/rudder-dev/rudder-dev-src +++ b/scripts/rudder-dev/rudder-dev-src @@ -413,6 +413,7 @@ def update_ticket_version(info, version): # Change ticket state to technical review +# Deprecated, use Issue.update() def ticket_to_TR(info, user_id=None, pr_url=None, message=None): # Create note content note = None @@ -1117,16 +1118,16 @@ def subtask(next_version, new_title, base=None, bug=False): # commit, push def wip(): # must be on a working branch - match = re.match(r'[A-Za-z]+_(i?)(\d+)/.*', current_branch) - if not match: - logfail("***** ERROR: This is not a ticket branch: " + branch) - exit(4) + issue = issue_from_branch(current_branch) commit_push(current_branch, "Work in progress") url = "https://github.com/{user}/{repo}/commit/{commit}" user = get_github_user() repo = remote_repo() commit = shell("git rev-parse HEAD", keep_output=True).strip() - print("You can find the commit here: " + url.format(user=user, repo=repo, commit=commit)) + # add a wip comment on the issue to find it later + commit_url = url.format(user=user, repo=repo, commit=commit) + issue.update(message="Work in progess here: " + commit_url) + print("You can find the commit here: " + commit_url) # Commit, push, create pull-request, update ticket