Commit 143872d1 authored by Joey Scarr's avatar Joey Scarr Committed by Commit Bot

Update git recipes to use buildbucket API.

Bug: 902400
Change-Id: I816dc06bfaabffac549d25ced60ddc61499fc38d
Reviewed-on: https://chromium-review.googlesource.com/c/1343628
Commit-Queue: Joey Scarr <jsca@chromium.org>
Reviewed-by: 's avatarNodir Turakulov <nodir@chromium.org>
parent 3d7ef65e
...@@ -383,7 +383,7 @@ Returns: ...@@ -383,7 +383,7 @@ Returns:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
### *recipe_modules* / [git](/recipes/recipe_modules/git) ### *recipe_modules* / [git](/recipes/recipe_modules/git)
[DEPS](/recipes/recipe_modules/git/__init__.py#1): [infra\_paths](#recipe_modules-infra_paths), [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime], [recipe\_engine/step][recipe_engine/recipe_modules/step] [DEPS](/recipes/recipe_modules/git/__init__.py#1): [infra\_paths](#recipe_modules-infra_paths), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime], [recipe\_engine/step][recipe_engine/recipe_modules/step]
#### **class [GitApi](/recipes/recipe_modules/git/api.py#10)([RecipeApi][recipe_engine/wkt/RecipeApi]):** #### **class [GitApi](/recipes/recipe_modules/git/api.py#10)([RecipeApi][recipe_engine/wkt/RecipeApi]):**
...@@ -391,7 +391,7 @@ Returns: ...@@ -391,7 +391,7 @@ Returns:
Return a git command step. Return a git command step.
&mdash; **def [bundle\_create](/recipes/recipe_modules/git/api.py#383)(self, bundle_path, rev_list_args=None, \*\*kwargs):** &mdash; **def [bundle\_create](/recipes/recipe_modules/git/api.py#382)(self, bundle_path, rev_list_args=None, \*\*kwargs):**
Run 'git bundle create' on a Git repository. Run 'git bundle create' on a Git repository.
...@@ -444,7 +444,7 @@ Args: ...@@ -444,7 +444,7 @@ Args:
Returns: If the checkout was successful, this returns the commit hash of Returns: If the checkout was successful, this returns the commit hash of
the checked-out-repo. Otherwise this returns None. the checked-out-repo. Otherwise this returns None.
&mdash; **def [config\_get](/recipes/recipe_modules/git/api.py#356)(self, prop_name, \*\*kwargs):** &mdash; **def [config\_get](/recipes/recipe_modules/git/api.py#355)(self, prop_name, \*\*kwargs):**
Returns: (str) The Git config output, or None if no output was generated. Returns: (str) The Git config output, or None if no output was generated.
...@@ -469,7 +469,7 @@ Returns: ...@@ -469,7 +469,7 @@ Returns:
Fetches all tags from the remote. Fetches all tags from the remote.
&mdash; **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#373)(self, remote_name=None, \*\*kwargs):** &mdash; **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#372)(self, remote_name=None, \*\*kwargs):**
Returns: (str) The URL of the remote Git repository, or None. Returns: (str) The URL of the remote Git repository, or None.
...@@ -477,11 +477,11 @@ Args: ...@@ -477,11 +477,11 @@ Args:
remote_name: (str) The name of the remote to query, defaults to 'origin'. remote_name: (str) The name of the remote to query, defaults to 'origin'.
kwargs: Forwarded to '__call__'. kwargs: Forwarded to '__call__'.
&mdash; **def [get\_timestamp](/recipes/recipe_modules/git/api.py#328)(self, commit='HEAD', test_data=None, \*\*kwargs):** &mdash; **def [get\_timestamp](/recipes/recipe_modules/git/api.py#327)(self, commit='HEAD', test_data=None, \*\*kwargs):**
Find and return the timestamp of the given commit. Find and return the timestamp of the given commit.
&mdash; **def [new\_branch](/recipes/recipe_modules/git/api.py#396)(self, branch, name=None, upstream=None, \*\*kwargs):** &mdash; **def [new\_branch](/recipes/recipe_modules/git/api.py#395)(self, branch, name=None, upstream=None, \*\*kwargs):**
Runs git new-branch on a Git repository, to be used before git cl upload. Runs git new-branch on a Git repository, to be used before git cl upload.
...@@ -491,7 +491,7 @@ Args: ...@@ -491,7 +491,7 @@ Args:
upstream (str): to origin/master. upstream (str): to origin/master.
kwargs: Forwarded to '__call__'. kwargs: Forwarded to '__call__'.
&mdash; **def [rebase](/recipes/recipe_modules/git/api.py#337)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):** &mdash; **def [rebase](/recipes/recipe_modules/git/api.py#336)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):**
Run rebase HEAD onto branch Run rebase HEAD onto branch
Args: Args:
...@@ -924,9 +924,9 @@ Raises: ...@@ -924,9 +924,9 @@ Raises:
&mdash; **def [RunSteps](/recipes/recipe_modules/gerrit/examples/full.py#11)(api):** &mdash; **def [RunSteps](/recipes/recipe_modules/gerrit/examples/full.py#11)(api):**
### *recipes* / [git:examples/full](/recipes/recipe_modules/git/examples/full.py) ### *recipes* / [git:examples/full](/recipes/recipe_modules/git/examples/full.py)
[DEPS](/recipes/recipe_modules/git/examples/full.py#5): [git](#recipe_modules-git), [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime], [recipe\_engine/step][recipe_engine/recipe_modules/step] [DEPS](/recipes/recipe_modules/git/examples/full.py#5): [git](#recipe_modules-git), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime], [recipe\_engine/step][recipe_engine/recipe_modules/step]
&mdash; **def [RunSteps](/recipes/recipe_modules/git/examples/full.py#18)(api):** &mdash; **def [RunSteps](/recipes/recipe_modules/git/examples/full.py#19)(api):**
### *recipes* / [git\_cl:examples/full](/recipes/recipe_modules/git_cl/examples/full.py) ### *recipes* / [git\_cl:examples/full](/recipes/recipe_modules/git_cl/examples/full.py)
[DEPS](/recipes/recipe_modules/git_cl/examples/full.py#9): [git\_cl](#recipe_modules-git_cl), [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step] [DEPS](/recipes/recipe_modules/git_cl/examples/full.py#9): [git\_cl](#recipe_modules-git_cl), [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
......
DEPS = [ DEPS = [
'recipe_engine/buildbucket',
'recipe_engine/context', 'recipe_engine/context',
'recipe_engine/runtime', 'recipe_engine/runtime',
'recipe_engine/path', 'recipe_engine/path',
......
...@@ -217,29 +217,28 @@ class GitApi(recipe_api.RecipeApi): ...@@ -217,29 +217,28 @@ class GitApi(recipe_api.RecipeApi):
can_fail_build=can_fail_build) can_fail_build=can_fail_build)
# There are five kinds of refs we can be handed: # There are five kinds of refs we can be handed:
# 0) None. In this case, we default to properties['branch']. # 0) None. In this case, we default to api.buildbucket.gitiles_commit.ref.
# 1) A 40-character SHA1 hash. # 1) A fully qualified branch name, e.g. 'refs/heads/master'.
# 2) A fully-qualifed arbitrary ref, e.g. 'refs/foo/bar/baz'. # Chop off 'refs/heads/' and now it matches case (4).
# 3) A fully qualified branch name, e.g. 'refs/heads/master'. # 2) A 40-character SHA1 hash.
# Chop off 'refs/heads' and now it matches case (4). # 3) A fully-qualifed arbitrary ref, e.g. 'refs/foo/bar/baz'.
# 4) A branch name, e.g. 'master'. # 4) A branch name, e.g. 'master'.
# Note that 'FETCH_HEAD' can be many things (and therefore not a valid # Note that 'FETCH_HEAD' can be many things (and therefore not a valid
# checkout target) if many refs are fetched, but we only explicitly fetch # checkout target) if many refs are fetched, but we only explicitly fetch
# one ref here, so this is safe. # one ref here, so this is safe.
if not ref: # Case 0.
ref = self.m.buildbucket.gitiles_commit.ref or 'master'
# If it's a fully-qualified branch name, trim the 'refs/heads/' prefix.
if ref.startswith('refs/heads/'): # Case 1.
ref = ref[len('refs/heads/'):]
fetch_args = [] fetch_args = []
if not ref: # Case 0 if self._GIT_HASH_RE.match(ref): # Case 2.
fetch_remote = remote_name
fetch_ref = self.m.properties.get('branch') or 'master'
checkout_ref = 'FETCH_HEAD'
elif self._GIT_HASH_RE.match(ref): # Case 1.
fetch_remote = remote_name fetch_remote = remote_name
fetch_ref = '' fetch_ref = ''
checkout_ref = ref checkout_ref = ref
elif ref.startswith('refs/heads/'): # Case 3. else: # Cases 3 and 4.
fetch_remote = remote_name
fetch_ref = ref[len('refs/heads/'):]
checkout_ref = 'FETCH_HEAD'
else: # Cases 2 and 4.
fetch_remote = remote_name fetch_remote = remote_name
fetch_ref = ref fetch_ref = ref
checkout_ref = 'FETCH_HEAD' checkout_ref = 'FETCH_HEAD'
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
DEPS = [ DEPS = [
'recipe_engine/buildbucket',
'recipe_engine/context', 'recipe_engine/context',
'recipe_engine/path', 'recipe_engine/path',
'recipe_engine/platform', 'recipe_engine/platform',
...@@ -29,9 +30,11 @@ def RunSteps(api): ...@@ -29,9 +30,11 @@ def RunSteps(api):
True) True)
# You can use api.git.checkout to perform all the steps of a safe checkout. # You can use api.git.checkout to perform all the steps of a safe checkout.
revision = (api.buildbucket.gitiles_commit.ref or
api.buildbucket.gitiles_commit.id)
retVal = api.git.checkout( retVal = api.git.checkout(
url, url,
ref=api.properties.get('revision'), ref=revision,
recursive=True, recursive=True,
submodule_update_force=submodule_update_force, submodule_update_force=submodule_update_force,
set_got_revision=api.properties.get('set_got_revision'), set_got_revision=api.properties.get('set_got_revision'),
...@@ -84,7 +87,7 @@ def RunSteps(api): ...@@ -84,7 +87,7 @@ def RunSteps(api):
if api.properties.get('cat_file', None): if api.properties.get('cat_file', None):
step_result = api.git.cat_file_at_commit(api.properties['cat_file'], step_result = api.git.cat_file_at_commit(api.properties['cat_file'],
api.properties['revision'], revision,
stdout=api.raw_io.output()) stdout=api.raw_io.output())
if 'TestOutput' in step_result.stdout: if 'TestOutput' in step_result.stdout:
pass # Success! pass # Success!
...@@ -101,18 +104,22 @@ def GenTests(api): ...@@ -101,18 +104,22 @@ def GenTests(api):
api.runtime(is_luci=True, is_experimental=False) api.runtime(is_luci=True, is_experimental=False)
) )
yield api.test('basic_tags') + api.properties(tags=True) yield api.test('basic_tags') + api.properties(tags=True)
yield api.test('basic_ref') + api.properties(revision='refs/foo/bar') yield api.test('basic_ref') + api.buildbucket.ci_build(git_ref='refs/foo/bar')
yield api.test('basic_branch') + api.properties(revision='refs/heads/testing') yield api.test('basic_branch') + api.buildbucket.ci_build(
yield api.test('basic_hash') + api.properties( git_ref='refs/heads/testing')
revision='abcdef0123456789abcdef0123456789abcdef01') yield api.test('basic_hash') + api.buildbucket.ci_build(
revision='abcdef0123456789abcdef0123456789abcdef01', git_ref=None)
yield api.test('basic_file_name') + api.properties(checkout_file_name='DEPS') yield api.test('basic_file_name') + api.properties(checkout_file_name='DEPS')
yield api.test('basic_submodule_update_force') + api.properties( yield api.test('basic_submodule_update_force') + api.properties(
submodule_update_force=True) submodule_update_force=True)
yield api.test('platform_win') + api.platform.name('win') yield api.test('platform_win') + api.platform.name('win')
yield api.test('curl_trace_file') + api.properties( yield (
revision='refs/foo/bar', use_curl_trace=True) api.test('curl_trace_file') +
api.properties(use_curl_trace=True) +
api.buildbucket.ci_build(git_ref='refs/foo/bar')
)
yield ( yield (
api.test('can_fail_build') + api.test('can_fail_build') +
...@@ -160,7 +167,8 @@ def GenTests(api): ...@@ -160,7 +167,8 @@ def GenTests(api):
api.test('cat-file_test') + api.test('cat-file_test') +
api.step_data('git cat-file abcdef12345:TestFile', api.step_data('git cat-file abcdef12345:TestFile',
stdout=api.raw_io.output('TestOutput')) + stdout=api.raw_io.output('TestOutput')) +
api.properties(revision='abcdef12345', cat_file='TestFile')) api.buildbucket.ci_build(revision='abcdef12345', git_ref=None) +
api.properties(cat_file='TestFile'))
yield ( yield (
api.test('git-cache-checkout') + api.test('git-cache-checkout') +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment