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

Unified Diff: appengine/findit/handlers/try_job_dashboard.py

Issue 2259513003: [Findit] Display last build bucket response to try job dashboard (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 4 months 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/handlers/try_job_dashboard.py
diff --git a/appengine/findit/handlers/try_job_dashboard.py b/appengine/findit/handlers/try_job_dashboard.py
index 25757482a82f063028028a84fa3e69678db3b1ff..5cee96aeeeecc13c1708a0a9c66e1f7e00c53046 100644
--- a/appengine/findit/handlers/try_job_dashboard.py
+++ b/appengine/findit/handlers/try_job_dashboard.py
@@ -1,9 +1,11 @@
# 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.
+
from datetime import datetime
from datetime import time
from datetime import timedelta
+import json
from common import time_util
from common.base_handler import BaseHandler
@@ -20,6 +22,34 @@ def _FormatDuration(start_time, end_time):
return time_util.FormatTimedelta(end_time - start_time)
+def _PrepareBuildbucketResponseForDisplay(buildbucket_response):
+ """Prepares a buildbucket response for display in the template.
+
+ buildbucket_response contains json inside json, which causes problems when
+ pretty printing in the corresponding template file. This function reformats
+ internal json as a dict.
+
+ Args:
+ buildbucket_response: A raw buildbucket response json object.
+
+ Returns:
+ A copy of the original buildbucket response dict, with json fields replaced
+ by dicts.
+ """
+ if buildbucket_response is None:
+ return None
+
+ new_response = {}
+
+ for key, value in buildbucket_response.iteritems():
+ if 'json' in key:
+ value = json.loads(value)
+
+ new_response[key] = value
+
+ return new_response
+
+
class TryJobDashboard(BaseHandler):
PERMISSION_LEVEL = Permission.ANYONE
@@ -65,7 +95,10 @@ class TryJobDashboard(BaseHandler):
'pending_time': _FormatDuration(
try_job_data.request_time, try_job_data.start_time),
'request_time': time_util.FormatDatetime(try_job_data.request_time),
- 'try_job_url': try_job_data.try_job_url
+ 'try_job_url': try_job_data.try_job_url,
+ 'last_buildbucket_response': json.dumps(
+ _PrepareBuildbucketResponseForDisplay(
+ try_job_data.last_buildbucket_response), sort_keys=True)
}
if not try_job_data.end_time and not try_job_data.error:
« no previous file with comments | « appengine/findit/handlers/test/try_job_dashboard_test.py ('k') | appengine/findit/templates/try_job_dashboard.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698