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 <guterman@google.com>
Reviewed-by: Nodir Turakulov <nodir@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md
index 57a3232..1cd7ccb 100644
--- a/recipes/README.recipes.md
+++ b/recipes/README.recipes.md
@@ -879,9 +879,9 @@
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 03ce8ef..8ee3def 100644
--- a/recipes/recipe_modules/tryserver/api.py
+++ b/recipes/recipe_modules/tryserver/api.py
@@ -329,7 +329,11 @@
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 1ebd173..fc51477 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
@@ -108,6 +108,70 @@
},
{
"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": "<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",
"-c",
"core.quotePath=false",
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 c254f4f..ec17de2 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
@@ -108,6 +108,70 @@
},
{
"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": "<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",
"-c",
"core.quotePath=false",
diff --git a/recipes/recipe_modules/tryserver/examples/full.py b/recipes/recipe_modules/tryserver/examples/full.py
index 15c237c..809c250 100644
--- a/recipes/recipe_modules/tryserver/examples/full.py
+++ b/recipes/recipe_modules/tryserver/examples/full.py
@@ -38,6 +38,7 @@
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',