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

Side by Side Diff: appengine/findit/handlers/triage_suspected_cl.py

Issue 2361583002: [Findit] UI change and triage change for cl level trige. (Closed)
Patch Set: rebase 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 """This module is to handle manual triage of a suspected CL.
6
7 This handler will flag the suspected cl as correct or incorrect.
8 """
9
10 from google.appengine.api import users
11 from google.appengine.ext import ndb
12
13 from common import time_util
14 from common.base_handler import BaseHandler
15 from common.base_handler import Permission
16 from model import result_status
17 from model import suspected_cl_status
18 from model.base_build_model import BaseBuildModel
19 from model.wf_analysis import WfAnalysis
20 from model.wf_suspected_cl import WfSuspectedCL
21 from waterfall import buildbot
22 from waterfall.suspected_cl_util import GetCLInfo
23
24 @ndb.transactional
25 def _UpdateSuspectedCL(repo_name, revision, build_key, cl_status):
26 suspected_cl = WfSuspectedCL.Get(repo_name, revision)
27 if (not suspected_cl or not suspected_cl.builds or
28 not suspected_cl.builds.get(build_key)):
29 return False
30
31 suspected_cl.builds[build_key]['status'] = cl_status
32
33 cl_correct = True
34 cl_incorrect = True
35 partial_triaged = False
36 # Checks if all the builds have been triaged and checks the status of the cl
37 # on each build.
38 # If all the builds are correct, the cl is correct;
39 # If all the builds are incorrect, the cl is incorrect;
40 # If some builds are correct while others aren't, the cl is partially correct;
41 # If not all the builds have been triaged, the cl is partially triaged.
42 for build in suspected_cl.builds.values():
43 if build['status'] is None:
44 partial_triaged = True
45 elif build['status'] == suspected_cl_status.CORRECT:
46 cl_incorrect = False
47 else:
48 cl_correct = False
49
50 if partial_triaged:
51 suspected_cl.status = suspected_cl_status.PARTIALLY_TRIAGED
52 elif cl_correct:
53 suspected_cl.status = suspected_cl_status.CORRECT
54 elif cl_incorrect:
55 suspected_cl.status = suspected_cl_status.INCORRECT
56 else:
57 suspected_cl.status = suspected_cl_status.PARTIALLY_CORRECT
58
59 suspected_cl.updated_time = time_util.GetUTCNow()
60
61 suspected_cl.put()
62 return True
63
64
65 @ndb.transactional
66 def _UpdateAnalysis(
67 master_name, builder_name, build_number, repo_name, revision, cl_status):
68 analysis = WfAnalysis.Get(master_name, builder_name, build_number)
69 if not analysis or not analysis.suspected_cls:
70 return False
71
72 num_correct = 0
73 num_incorrect = 0
74 for cl in analysis.suspected_cls:
75 if cl['repo_name'] == repo_name and cl['revision'] == revision:
76 # Updates this cl's status.
77 cl['status'] = cl_status
78
79 # Checks if all the cls have been triaged and checks the status of each cl
80 # on the build.
81 if cl.get('status') == suspected_cl_status.CORRECT:
82 num_correct += 1
83 elif cl.get('status') == suspected_cl_status.INCORRECT:
84 num_incorrect += 1
85
86 if num_correct + num_incorrect == len(analysis.suspected_cls): # All triaged.
87 if num_correct == 0:
88 analysis.result_status = result_status.FOUND_INCORRECT
89 elif num_incorrect == 0:
90 analysis.result_status = result_status.FOUND_CORRECT
91 else:
92 analysis.result_status = result_status.PARTIALLY_CORRECT_FOUND
93
94 analysis.put()
95 return True
96
97
98 def _AppendTriageHistoryRecord(
99 master_name, builder_name, build_number, cl_info, cl_status, user_name):
100
101 analysis = WfAnalysis.Get(master_name, builder_name, build_number)
102 if not analysis: # pragma: no cover
103 return
104
105 triage_record = {
106 'triage_timestamp': time_util.GetUTCNowTimestamp(),
107 'user_name': user_name,
108 'cl_status': cl_status,
109 'version': analysis.version,
110 'triaged_cl': cl_info
111 }
112 if not analysis.triage_history:
113 analysis.triage_history = []
114 analysis.triage_history.append(triage_record)
115
116 analysis.put()
117
118
119 def _UpdateSuspectedCLAndAnalysis(
120 master_name, builder_name, build_number, cl_info, cl_status, user_name):
121 repo_name, revision = GetCLInfo(cl_info)
122 build_key = BaseBuildModel.CreateBuildId(
123 master_name, builder_name, build_number)
124
125 success = (
126 _UpdateSuspectedCL(repo_name, revision, build_key, cl_status) and
127 _UpdateAnalysis(master_name, builder_name, build_number,
128 repo_name, revision, cl_status))
129
130 if success:
131 _AppendTriageHistoryRecord(
132 master_name, builder_name, build_number, cl_info, cl_status, user_name)
133
134 return success
135
136
137 class TriageSuspectedCl(BaseHandler):
138 PERMISSION_LEVEL = Permission.CORP_USER
139
140 def HandleGet(self): # pragma: no cover
141 """Sets the manual triage result for the cl."""
142 url = self.request.get('url').strip()
143 build_info = buildbot.ParseBuildUrl(url)
144 if not build_info:
145 return {'data': {'success': False}}
146 master_name, builder_name, build_number = build_info
147
148 cl_status = int(self.request.get('status'))
149 cl_info = self.request.get('cl_info')
150 # As the permission level is CORP_USER, we could assume the current user
151 # already logged in.
152 user_name = users.get_current_user().email().split('@')[0]
153 success = _UpdateSuspectedCLAndAnalysis(
154 master_name, builder_name, build_number, cl_info, cl_status, user_name)
155
156 return {'data': {'success': success}}
157
158
159 def HandlePost(self): # pragma: no cover
160 return self.HandleGet()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698