diff options
author | Ravi Mistry <rmistry@google.com> | 2017-09-12 13:18:12 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-12 18:06:35 +0000 |
commit | 6f0751e50f61479e435c6c1c5b72139ba7e8b7e6 (patch) | |
tree | 990515615e5bd0fb4c3786ead3ac70a70d05f560 /PRESUBMIT.py | |
parent | a70cb8ae9b8a017852c9dafd65efb44946072679 (diff) |
Fix behavior of automatically adding 'Cq-Include-Trybots' in presubmit
NoTry: true
Bug: skia:7041
Change-Id: I4660db5e9526b29e2135bf4d5f0d134f1f9a5dce
Reviewed-on: https://skia-review.googlesource.com/45880
Commit-Queue: Ravi Mistry <rmistry@google.com>
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Diffstat (limited to 'PRESUBMIT.py')
-rw-r--r-- | PRESUBMIT.py | 62 |
1 files changed, 6 insertions, 56 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 3eb71a53f1..4bea7099dd 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -530,9 +530,9 @@ def PostUploadHook(cl, change, output_api): output_api.PresubmitNotifyResult( 'Branch changes do not run the presubmit checks.')) - # Automatically set CQ_INCLUDE_TRYBOTS if any of the changed files here + # Automatically set Cq-Include-Trybots if any of the changed files here # begin with the paths of interest. - cq_master_to_trybots = collections.defaultdict(set) + bots_to_include = [] for affected_file in change.AffectedFiles(): affected_file_path = affected_file.LocalPath() for path_prefix, extra_bots in PATH_PREFIX_TO_EXTRA_TRYBOTS.iteritems(): @@ -541,10 +541,10 @@ def PostUploadHook(cl, change, output_api): output_api.PresubmitNotifyResult( 'Your CL modifies the path %s.\nAutomatically adding %s to ' 'the CL description.' % (affected_file_path, extra_bots))) - _MergeCQExtraTrybotsMaps( - cq_master_to_trybots, _GetCQExtraTrybotsMap(extra_bots)) - if cq_master_to_trybots: - _AddCQExtraTrybotsToDesc(cq_master_to_trybots, new_description_lines) + bots_to_include.append(extra_bots) + if bots_to_include: + output_api.EnsureCQIncludeTrybotsAreAdded( + cl, bots_to_include, new_description_lines) # If the description has changed update it. if new_description_lines != original_description_lines: @@ -555,56 +555,6 @@ def PostUploadHook(cl, change, output_api): return results -def _AddCQExtraTrybotsToDesc(cq_master_to_trybots, description_lines): - """Adds the specified master and trybots to the CQ_INCLUDE_TRYBOTS keyword. - - If the keyword already exists in the description then it appends to it only - if the specified values do not already exist. - If the keyword does not exist then it creates a new section in the - description. - """ - found = None - foundIdx = -1 - for idx, line in enumerate(description_lines): - if line.startswith('CQ_INCLUDE_TRYBOTS'): - found = line - foundIdx = idx - - if found: - original_trybots_map = _GetCQExtraTrybotsMap(found) - _MergeCQExtraTrybotsMaps(cq_master_to_trybots, original_trybots_map) - new_line = _GetCQExtraTrybotsStr(cq_master_to_trybots) - if new_line != found: - description_lines[foundIdx] = new_line - else: - description_lines.append(_GetCQExtraTrybotsStr(cq_master_to_trybots)) - - -def _MergeCQExtraTrybotsMaps(dest_map, map_to_be_consumed): - """Merges two maps of masters to trybots into one.""" - for master, trybots in map_to_be_consumed.iteritems(): - dest_map[master].update(trybots) - return dest_map - - -def _GetCQExtraTrybotsMap(cq_extra_trybots_str): - """Parses CQ_INCLUDE_TRYBOTS str and returns a map of masters to trybots.""" - cq_master_to_trybots = collections.defaultdict(set) - for section in cq_extra_trybots_str.split(';'): - if section: - master, bots = section.split(':') - cq_master_to_trybots[master].update(bots.split(',')) - return cq_master_to_trybots - - -def _GetCQExtraTrybotsStr(cq_master_to_trybots): - """Constructs the CQ_INCLUDE_TRYBOTS str from a map of masters to trybots.""" - sections = [] - for master, trybots in cq_master_to_trybots.iteritems(): - sections.append('%s:%s' % (master, ','.join(trybots))) - return 'CQ_INCLUDE_TRYBOTS=%s' % ';'.join(sections) - - def CheckChangeOnCommit(input_api, output_api): """Presubmit checks for the change on commit. |