From e8b56fbf3ce5ea4a32b592a6b1f9132b4ea3c250 Mon Sep 17 00:00:00 2001 From: Greg Guterman Date: Thu, 11 Mar 2021 23:36:06 +0000 Subject: [PATCH] Fix get_footer None AttributeError R: nodir@chromium.org Change-Id: Ib052dabd7a92b3643f7f2fa3cc7933eb7a60dd9b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2753457 Auto-Submit: Gregory Guterman Reviewed-by: Nodir Turakulov Reviewed-by: Josip Sokcevic Commit-Queue: Josip Sokcevic --- recipes/README.recipes.md | 4 +- recipes/recipe_modules/tryserver/api.py | 6 +- .../full.expected/with_gerrit_patch.json | 64 +++++++++++++++++++ .../with_gerrit_patch_and_target_ref.json | 64 +++++++++++++++++++ .../recipe_modules/tryserver/examples/full.py | 1 + 5 files changed, 136 insertions(+), 3 deletions(-) diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 57a32326a6..1cd7ccb8cc 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -879,9 +879,9 @@ Returns true iff the properties exist to match a Gerrit issue. Returns true iff we have a change to check out. -— **def [normalize\_footer\_name](/recipes/recipe_modules/tryserver/api.py#334)(self, footer):** +— **def [normalize\_footer\_name](/recipes/recipe_modules/tryserver/api.py#338)(self, footer):** -— **def [set\_change](/recipes/recipe_modules/tryserver/api.py#337)(self, change):** +— **def [set\_change](/recipes/recipe_modules/tryserver/api.py#341)(self, change):** Set the gerrit change for this module. diff --git a/recipes/recipe_modules/tryserver/api.py b/recipes/recipe_modules/tryserver/api.py index 03ce8ef650..8ee3deff86 100644 --- a/recipes/recipe_modules/tryserver/api.py +++ b/recipes/recipe_modules/tryserver/api.py @@ -329,7 +329,11 @@ class TryserverApi(recipe_api.RecipeApi): def get_footer(self, tag, patch_text=None): """Gets a specific tag from a CL description""" - return self._get_footers(patch_text).get(tag, []) + footers = self._get_footers(patch_text) + if footers is None: + return [] + + return footers.get(tag, []) def normalize_footer_name(self, footer): return '-'.join([ word.title() for word in footer.strip().split('-') ]) diff --git a/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch.json b/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch.json index 1ebd1734d2..fc51477b22 100644 --- a/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch.json +++ b/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch.json @@ -106,6 +106,70 @@ "@@@STEP_LOG_END@json.output (exception)@@@" ] }, + { + "cmd": [ + "vpython", + "-u", + "RECIPE_REPO[depot_tools]/gerrit_client.py", + "changes", + "--host", + "https://chromium-review.googlesource.com", + "--json_file", + "/path/to/tmp/json", + "--limit", + "1", + "-p", + "change=91827", + "-o", + "ALL_REVISIONS", + "-o", + "ALL_COMMITS" + ], + "env": { + "PATH": ":RECIPE_REPO[depot_tools]" + }, + "infra_step": true, + "name": "gerrit changes (2)", + "~followup_annotations": [ + "@@@STEP_LOG_LINE@json.output@[@@@", + "@@@STEP_LOG_LINE@json.output@ {@@@", + "@@@STEP_LOG_LINE@json.output@ \"_number\": \"91827\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"branch\": \"main\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", + "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"_number\": \"1\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"commit\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"message\": \"Change commit message\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@ }, @@@", + "@@@STEP_LOG_LINE@json.output@ \"status\": \"NEW\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@]@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, + { + "cmd": [ + "python", + "-u", + "RECIPE_REPO[depot_tools]/git_footers.py", + "--json", + "/path/to/tmp/json" + ], + "name": "parse description (2)", + "stdin": "Change commit message", + "~followup_annotations": [ + "@@@STEP_LOG_END@json.output (invalid)@@@", + "@@@STEP_LOG_LINE@json.output (exception)@No JSON object could be decoded@@@", + "@@@STEP_LOG_END@json.output (exception)@@@" + ] + }, { "cmd": [ "git", diff --git a/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch_and_target_ref.json b/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch_and_target_ref.json index c254f4fab0..ec17de2eb6 100644 --- a/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch_and_target_ref.json +++ b/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch_and_target_ref.json @@ -106,6 +106,70 @@ "@@@STEP_LOG_END@json.output (exception)@@@" ] }, + { + "cmd": [ + "vpython", + "-u", + "RECIPE_REPO[depot_tools]/gerrit_client.py", + "changes", + "--host", + "https://chromium-review.googlesource.com", + "--json_file", + "/path/to/tmp/json", + "--limit", + "1", + "-p", + "change=91827", + "-o", + "ALL_REVISIONS", + "-o", + "ALL_COMMITS" + ], + "env": { + "PATH": ":RECIPE_REPO[depot_tools]" + }, + "infra_step": true, + "name": "gerrit changes (2)", + "~followup_annotations": [ + "@@@STEP_LOG_LINE@json.output@[@@@", + "@@@STEP_LOG_LINE@json.output@ {@@@", + "@@@STEP_LOG_LINE@json.output@ \"_number\": \"91827\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"branch\": \"main\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", + "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"_number\": \"1\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"commit\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"message\": \"Change commit message\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@ }, @@@", + "@@@STEP_LOG_LINE@json.output@ \"status\": \"NEW\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@]@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, + { + "cmd": [ + "python", + "-u", + "RECIPE_REPO[depot_tools]/git_footers.py", + "--json", + "/path/to/tmp/json" + ], + "name": "parse description (2)", + "stdin": "Change commit message", + "~followup_annotations": [ + "@@@STEP_LOG_END@json.output (invalid)@@@", + "@@@STEP_LOG_LINE@json.output (exception)@No JSON object could be decoded@@@", + "@@@STEP_LOG_END@json.output (exception)@@@" + ] + }, { "cmd": [ "git", diff --git a/recipes/recipe_modules/tryserver/examples/full.py b/recipes/recipe_modules/tryserver/examples/full.py index 15c237c91f..809c250ba3 100644 --- a/recipes/recipe_modules/tryserver/examples/full.py +++ b/recipes/recipe_modules/tryserver/examples/full.py @@ -38,6 +38,7 @@ def RunSteps(api): if api.tryserver.is_gerrit_issue: api.tryserver.get_footers() + api.tryserver.get_footer('testfooter') api.tryserver.get_files_affected_by_patch( api.properties.get('test_patch_root'), report_files_via_property='affected_files',