| 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 def _GetIssue(bug_id, issue_tracker): |
| 13 """Returns the issue of the given bug. |
| 14 |
| 15 Traverse if the bug was merged into another.""" |
| 16 issue = issue_tracker.getIssue(bug_id) |
| 17 while issue and issue.merged_into: |
| 18 issue = issue_tracker.getIssue(issue.merged_into) |
| 19 return issue |
| 20 |
| 21 |
| 22 class PostCommentToBugPipeline(BasePipeline): |
| 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 = _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 |