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

Side by Side Diff: appengine/findit/model/base_triaged_model.py

Issue 2416303002: [Findit] Adding support for triaging suspected builds from flake analysis (Closed)
Patch Set: Addressing comments Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(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 from google.appengine.ext import ndb
6 from google.appengine.api import users
7
8 from common import appengine_util
9 from common import time_util
10 from model import triage_status
11
12
13 class TriageResult(ndb.Model):
14 # The user who updated this result.
15 user_name = ndb.StringProperty(default=None, indexed=False)
16
17 # The time this triage result was determined.
18 triaged_time = ndb.DateTimeProperty(indexed=False, auto_now=True)
19
20 # The result of the analysis as correct or not. If not triaged, the value
21 # should be None. Other traige result codes are up to the child class to set.
22 triage_result = ndb.IntegerProperty(default=None, indexed=True)
23
24 # The version of findit that generated this result. Should primarily be
25 # relevant for entities that are not versioned.
26 findit_version = ndb.StringProperty(default=None, indexed=False)
27
28 # The version number of the entity that is being triaged. Should primarily be
29 # relevant for versioned entites.
30 version_number = ndb.IntegerProperty(default=None, indexed=False)
31
32 # Other information about this result. For example, cl_info for suspected CLs
33 # which may contain repo/revision or the suspected range for a flake analysis.
34 suspect_info = ndb.JsonProperty(default={}, indexed=False)
chanli 2016/10/15 01:47:21 I remembered default to {} is problematic. One way
lijeffrey 2016/10/15 02:16:41 Done.
35
36
37 class TriagedModel(ndb.Model):
38 """The parent class for models that can have traige results."""
39
40 def UpdateTriageResult(self, triage_result, suspect_info, user_name,
41 version_number=None):
42 result = TriageResult()
43 result.user_name = user_name
44 result.triage_result = triage_result
45 result.findit_version = appengine_util.GetCurrentVersion()
46 result.version_number = version_number
47 result.suspect_info = suspect_info
48 self.triage_history.append(result)
49
50 @staticmethod
51 def GetTriageHistory(analysis):
52 """Gets the triage history of a triaged model as a list.
53
54 Args:
55 analysis (TriagedModel): An instance of an entity assumed to inherit from
56 TriagedModel.
57
58 Returns:
59 A list of dicts representing the triage history of the analysis.
60 """
61 if (not users.is_current_user_admin() or
62 not analysis.completed or
63 not analysis.triage_history): # pragma: no cover
chanli 2016/10/15 01:47:21 Not sure if we should check if user is admin here.
lijeffrey 2016/10/15 02:16:41 This function was originally only on the handler s
64 return None
65
66 triage_history = []
67 for triage_record in analysis.triage_history:
68 triage_history.append({
69 'triaged_time': time_util.FormatDatetime(triage_record.triaged_time),
70 'user_name': triage_record.user_name,
71 'suspect_info': triage_record.suspect_info,
72 'triage_result': (
73 triage_status.TRIAGE_STATUS_TO_DESCRIPTION.get(
74 triage_record.triage_result)),
75 'findit_version': triage_record.findit_version,
76 'version_number': triage_record.version_number
77 })
78
79 return triage_history
80
81 # Record the triage result history.
82 triage_history = ndb.LocalStructuredProperty(
83 TriageResult, repeated=True, indexed=False, compressed=True)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698