diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index eae70b3c4..13e73b499 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -332,7 +332,7 @@ Create a new branch from given project and commit Returns: the ref of the branch created -— **def [get\_change\_description](/recipes/recipe_modules/gerrit/api.py#106)(self, host, change, patchset):** +— **def [get\_change\_description](/recipes/recipe_modules/gerrit/api.py#72)(self, host, change, patchset):** Get the description for a given CL and patchset. @@ -344,20 +344,7 @@ Args: Returns: The description corresponding to given CL and patchset. -— **def [get\_change\_destination\_branch](/recipes/recipe_modules/gerrit/api.py#72)(self, host, change, name=None, step_test_data=None):** - -Get the upstream branch for a given CL. - -Result is cached. - -Args: - host: URL of Gerrit host to query. - change: The change number. - -Returns: - the name of the branch - -— **def [get\_changes](/recipes/recipe_modules/gerrit/api.py#151)(self, host, query_params, start=None, limit=None, o_params=None, step_test_data=None, \*\*kwargs):** +— **def [get\_changes](/recipes/recipe_modules/gerrit/api.py#117)(self, host, query_params, start=None, limit=None, o_params=None, step_test_data=None, \*\*kwargs):** Query changes for the given host. @@ -382,7 +369,7 @@ Get a branch from given project and commit Returns: the revision of the branch -— **def [get\_revision\_info](/recipes/recipe_modules/gerrit/api.py#121)(self, host, change, patchset):** +— **def [get\_revision\_info](/recipes/recipe_modules/gerrit/api.py#87)(self, host, change, patchset):** Returns the info for a given patchset of a given change. diff --git a/recipes/recipe_modules/gerrit/api.py b/recipes/recipe_modules/gerrit/api.py index ad7bd84b1..4e1f2dd72 100644 --- a/recipes/recipe_modules/gerrit/api.py +++ b/recipes/recipe_modules/gerrit/api.py @@ -69,40 +69,6 @@ class GerritApi(recipe_api.RecipeApi): revision = step_result.json.output.get('revision') return revision - def get_change_destination_branch( - self, host, change, name=None, step_test_data=None): - """ - Get the upstream branch for a given CL. - - Result is cached. - - Args: - host: URL of Gerrit host to query. - change: The change number. - - Returns: - the name of the branch - """ - assert int(change), change - change = int(change) - branch = self._changes_target_branch_cache.get((host, change)) - if branch is not None: - return branch - changes = self.get_changes( - host, - [('change', change)], - limit=1, - name=name or 'get_change_destination_branch', - step_test_data=step_test_data, - ) - if not changes or 'branch' not in changes[0]: - self.m.step.active_result.presentation.status = self.m.step.EXCEPTION - raise self.m.step.InfraFailure( - 'Error quering for branch of CL %s' % change) - branch = changes[0]['branch'] - self._changes_target_branch_cache[(host, change)] = branch - return branch - def get_change_description(self, host, change, patchset): """ Get the description for a given CL and patchset. diff --git a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json index 6c5e47993..4064849eb 100644 --- a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json +++ b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json @@ -118,41 +118,20 @@ "https://chromium-review.googlesource.com", "--json_file", "/path/to/tmp/json", - "--limit", - "1", "-p", - "change=123", - "-o", - "ALL_REVISIONS", - "-o", - "ALL_COMMITS" + "project=chromium/src", + "-p", + "status=open", + "-p", + "label=Commit-Queue>2" ], "env": { "PATH": ":RECIPE_PACKAGE_REPO[depot_tools]" }, "infra_step": true, - "name": "gerrit changes (2)", + "name": "gerrit changes empty query", "~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\": \"master\", @@@", - "@@@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_LINE@json.output@[]@@@", "@@@STEP_LOG_END@json.output@@@" ] }, @@ -169,13 +148,17 @@ "--limit", "1", "-p", - "change=123" + "change=123", + "-o", + "ALL_REVISIONS", + "-o", + "ALL_COMMITS" ], "env": { "PATH": ":RECIPE_PACKAGE_REPO[depot_tools]" }, "infra_step": true, - "name": "gerrit get_change_destination_branch", + "name": "gerrit changes (2)", "~followup_annotations": [ "@@@STEP_LOG_LINE@json.output@[@@@", "@@@STEP_LOG_LINE@json.output@ {@@@", @@ -200,32 +183,6 @@ "@@@STEP_LOG_END@json.output@@@" ] }, - { - "cmd": [ - "python", - "-u", - "RECIPE_PACKAGE_REPO[depot_tools]/gerrit_client.py", - "changes", - "--host", - "https://chromium-review.googlesource.com", - "--json_file", - "/path/to/tmp/json", - "--limit", - "1", - "-p", - "change=122" - ], - "env": { - "PATH": ":RECIPE_PACKAGE_REPO[depot_tools]" - }, - "infra_step": true, - "name": "gerrit missing_cl", - "~followup_annotations": [ - "@@@STEP_LOG_LINE@json.output@[]@@@", - "@@@STEP_LOG_END@json.output@@@", - "@@@STEP_EXCEPTION@@@" - ] - }, { "cmd": [ "python", @@ -279,7 +236,7 @@ "failure": { "step": "Aggregate step failure." }, - "humanReason": "2 out of 2 aggregated steps failed. Failures: Error quering for branch of CL 122, Error querying for CL description: host:'https://chromium-review.googlesource.com' change:122; patchset:3" + "humanReason": "1 out of 1 aggregated steps failed. Failures: Error querying for CL description: host:'https://chromium-review.googlesource.com' change:122; patchset:3" }, "name": "$result" } diff --git a/recipes/recipe_modules/gerrit/examples/full.py b/recipes/recipe_modules/gerrit/examples/full.py index 09dbf2f0c..094c3cc8e 100644 --- a/recipes/recipe_modules/gerrit/examples/full.py +++ b/recipes/recipe_modules/gerrit/examples/full.py @@ -33,18 +33,22 @@ def RunSteps(api): limit=1, ) + # Query which returns no changes is still successful query. + empty_list = api.gerrit.get_changes( + host, + query_params=[ + ('project', 'chromium/src'), + ('status', 'open'), + ('label', 'Commit-Queue>2'), + ], + name='changes empty query', + ) + assert len(empty_list) == 0 + api.gerrit.get_change_description( host, change=123, patchset=1) - first = api.gerrit.get_change_destination_branch(host, change=123) - # Second call returns cached data. - second = api.gerrit.get_change_destination_branch(host, change=123) - assert first == second - with api.step.defer_results(): - api.gerrit.get_change_destination_branch( - host, change=122, name='missing_cl') - api.gerrit.get_change_description( host, change=122, patchset=3) @@ -61,7 +65,7 @@ def GenTests(api): api.gerrit.make_gerrit_get_branch_response_data() ) + api.step_data( - 'gerrit missing_cl', - api.gerrit.get_empty_changes_response_data() + 'gerrit changes empty query', + api.gerrit.get_empty_changes_response_data() ) )