Chromium Code Reviews| Index: appengine/findit/waterfall/post_comment_to_bug_pipeline.py |
| diff --git a/appengine/findit/waterfall/post_comment_to_bug_pipeline.py b/appengine/findit/waterfall/post_comment_to_bug_pipeline.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1b5890d1192353137897c3feffa0f8968b2d517 |
| --- /dev/null |
| +++ b/appengine/findit/waterfall/post_comment_to_bug_pipeline.py |
| @@ -0,0 +1,47 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| + |
| +from issue_tracker import IssueTrackerAPI |
| + |
| +from common.pipeline_wrapper import BasePipeline |
| + |
| + |
| +class PostCommentToBugPipeline(BasePipeline): |
| + |
| + @staticmethod |
| + 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
|
| + """Returns the issue of the given bug. |
| + |
| + Traverse if the bug was merged into another.""" |
| + issue = issue_tracker.getIssue(bug_id) |
| + while issue and issue.merged_into: |
| + issue = issue_tracker.getIssue(issue.merged_into) |
| + return issue |
| + |
| + # Arguments number differs from overridden method - pylint: disable=W0221 |
| + def run(self, bug_id, comment, labels, project_name='chromium'): |
| + """Posts a comment and adds labels to the bug. |
| + |
| + Args: |
| + bug_id (int): The bug id to update. |
| + comment (str): The comment to post. |
| + labels (list): A list labels to add. |
| + project_name (str): The project name for the bug. Default to 'chromium'. |
| + """ |
| + assert bug_id, 'Invalid bug id: %s' % bug_id |
| + |
| + issue_tracker = IssueTrackerAPI(project_name) |
| + issue = self._GetIssue(bug_id, issue_tracker) |
| + if not issue: |
| + logging.warn('Bug %s/%s or the merged-into one seems deleted!', |
| + project_name, bug_id) |
| + return |
| + |
| + for label in labels: |
| + issue.labels.append(label) |
| + |
| + issue_tracker.update(issue, comment, send_email=True) |
| + logging.info('Bug %s/%s was updated.', project_name, bug_id) |