Chromium Code Reviews| Index: appengine/findit/waterfall/suspected_cl_util.py |
| diff --git a/appengine/findit/waterfall/suspected_cl_util.py b/appengine/findit/waterfall/suspected_cl_util.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc3358e0f080f7cdd894f0a01ea168ccffd966b6 |
| --- /dev/null |
| +++ b/appengine/findit/waterfall/suspected_cl_util.py |
| @@ -0,0 +1,57 @@ |
| +# 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 google.appengine.ext import ndb |
| + |
| +from model import analysis_approach_type |
| +from model.wf_suspected_cl import WfSuspectedCL |
| + |
| +def _GetsStatusFromSameFailure(builds, failures): |
| + for build in builds.values(): |
| + if build['status'] is not None and build['failures'] == failures: |
| + return build['status'] |
| + return None |
| + |
| + |
| +def _ModifyApproach(current_approach, new_approach): |
|
Sharu Jiang
2016/09/19 23:17:54
Is it possible that new_approach is None? if not t
chanli
2016/09/21 22:04:25
Done.
|
| + if (current_approach == analysis_approach_type.BOTH or |
| + current_approach == new_approach): |
| + return current_approach |
| + |
| + if not current_approach: |
| + return new_approach |
| + |
| + # current_approach and new_approach are different. |
| + return analysis_approach_type.BOTH |
| + |
| + |
| +@ndb.transactional |
| +def UpdateSuspectedCL( |
| + repo_name, revision, commit_position, |
| + approach, master_name, builder_name, build_number, failure_type, |
| + failures, top_score): |
| + |
| + suspected_cl = ( |
| + WfSuspectedCL.Get(repo_name, revision) or |
| + WfSuspectedCL.Create(repo_name, revision, commit_position)) |
| + |
| + # HEURISTIC: 1; TRY_JOB: 2; BOTH: 3. |
| + suspected_cl.approach = _ModifyApproach(suspected_cl.approach, approach) |
| + suspected_cl.failure_type = suspected_cl.failure_type or failure_type |
| + |
| + build_key = '%s/%s/%d' %(master_name, builder_name, build_number) |
| + if build_key not in suspected_cl.builds: |
| + build = { |
| + 'approach': approach, |
| + 'failure_type': failure_type, |
| + 'failures': failures, |
| + 'status': _GetsStatusFromSameFailure(suspected_cl.builds, failures), |
| + 'top_score': top_score |
| + } |
| + suspected_cl.builds[build_key] = build |
| + else: |
| + build = suspected_cl.builds[build_key] |
| + build['approach'] = _ModifyApproach(build['approach'], approach) |
| + |
| + suspected_cl.put() |