Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import logging | |
| 6 | |
| 7 from issue_tracker import IssueTrackerAPI | |
| 8 | |
| 9 from common.pipeline_wrapper import BasePipeline | |
| 10 | |
| 11 | |
| 12 class PostCommentToBugPipeline(BasePipeline): | |
| 13 | |
| 14 @staticmethod | |
| 15 def _GetIssue(bug_id, issue_tracker): | |
|
chanli
2016/10/21 23:23:09
Any particular reason you want to make it static?
stgao
2016/10/22 00:15:09
No. Moved out of the class into the module instead
| |
| 16 """Returns the issue of the given bug. | |
| 17 | |
| 18 Traverse if the bug was merged into another.""" | |
| 19 issue = issue_tracker.getIssue(bug_id) | |
| 20 while issue and issue.merged_into: | |
| 21 issue = issue_tracker.getIssue(issue.merged_into) | |
| 22 return issue | |
| 23 | |
| 24 # Arguments number differs from overridden method - pylint: disable=W0221 | |
| 25 def run(self, bug_id, comment, labels, project_name='chromium'): | |
| 26 """Posts a comment and adds labels to the bug. | |
| 27 | |
| 28 Args: | |
| 29 bug_id (int): The bug id to update. | |
| 30 comment (str): The comment to post. | |
| 31 labels (list): A list labels to add. | |
| 32 project_name (str): The project name for the bug. Default to 'chromium'. | |
| 33 """ | |
| 34 assert bug_id, 'Invalid bug id: %s' % bug_id | |
| 35 | |
| 36 issue_tracker = IssueTrackerAPI(project_name) | |
| 37 issue = self._GetIssue(bug_id, issue_tracker) | |
| 38 if not issue: | |
| 39 logging.warn('Bug %s/%s or the merged-into one seems deleted!', | |
| 40 project_name, bug_id) | |
| 41 return | |
| 42 | |
| 43 for label in labels: | |
| 44 issue.labels.append(label) | |
| 45 | |
| 46 issue_tracker.update(issue, comment, send_email=True) | |
| 47 logging.info('Bug %s/%s was updated.', project_name, bug_id) | |
| OLD | NEW |