Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: appengine/findit/waterfall/post_comment_to_bug_pipeline.py

Issue 2438673004: [Findit] Post analysis results of flakes to bug filed by chromium-try-flakes. (Closed)
Patch Set: Add a config flag to enable/disable updating monorail bug. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3ae5af1cb58eb036eb9dadad19ff5f7fea3250a8
--- /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
+
+
+def _GetIssue(bug_id, issue_tracker):
+ """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
+
+
+class PostCommentToBugPipeline(BasePipeline):
+
+ # 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 = _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)

Powered by Google App Engine
This is Rietveld 408576698