Determine the checkout parameters using buildbucket API.

Rather than using a property we will be getting the project from the
buildbucket apis. This will remove some issues with the proto files from
subbuilds having to have the new property.

Bug: https://github.com/flutter/flutter/issues/115489
Change-Id: I4b7890675441dddb920a39a20646917d9f7b5faa
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/36800
Commit-Queue: Godofredo Contreras <godofredoc@google.com>
Reviewed-by: Jesse Seales <jseales@google.com>
diff --git a/recipe_modules/repo_util/api.py b/recipe_modules/repo_util/api.py
index feeceaf..775c164 100644
--- a/recipe_modules/repo_util/api.py
+++ b/recipe_modules/repo_util/api.py
@@ -3,14 +3,16 @@
 # found in the LICENSE file.
 
 REPOS = {
-    'flutter': 'https://flutter.googlesource.com/mirrors/flutter',
-    'engine': 'https://flutter.googlesource.com/mirrors/engine',
     'cocoon': 'https://flutter.googlesource.com/mirrors/cocoon',
+    'engine': 'https://flutter.googlesource.com/mirrors/engine',
+    'flutter': 'https://flutter.googlesource.com/mirrors/flutter',
     'infra': 'https://flutter.googlesource.com/infra',
+    'mirrors/engine': 'https://flutter.googlesource.com/mirrors/engine',
+    'mirrors/flutter': 'https://flutter.googlesource.com/mirrors/flutter',
     'monorepo': 'https://dart.googlesource.com/monorepo',
+    'openpay': 'https://dash-internal.googlesource.com/openpay',
     'packages': 'https://flutter.googlesource.com/mirrors/packages',
     'plugins': 'https://flutter.googlesource.com/mirrors/plugins',
-    'openpay': 'https://dash-internal.googlesource.com/openpay',
 }
 
 # TODO(keyonghan): deprecate when all repos are migrated to main.
diff --git a/recipe_modules/repo_util/examples/full.expected/monorepo_wrong_host.json b/recipe_modules/repo_util/examples/full.expected/monorepo_wrong_host.json
index b7d221f..6d38e6d 100644
--- a/recipe_modules/repo_util/examples/full.expected/monorepo_wrong_host.json
+++ b/recipe_modules/repo_util/examples/full.expected/monorepo_wrong_host.json
@@ -1165,7 +1165,7 @@
       "Traceback (most recent call last):",
       "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/examples/full.py\", line 47, in RunSteps",
       "    api.repo_util.monorepo_checkout(checkout_path, {}, {})",
-      "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/api.py\", line 144, in monorepo_checkout",
+      "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/api.py\", line 146, in monorepo_checkout",
       "    raise ValueError(",
       "ValueError('Input reference is not on dart.googlesource.com/monorepo')"
     ]
diff --git a/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json b/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json
index 6e6dae7..013eefd 100644
--- a/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json
+++ b/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json
@@ -9,7 +9,7 @@
       "Traceback (most recent call last):",
       "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/examples/unsupported.py\", line 13, in RunSteps",
       "    api.repo_util.checkout('unsupported_repo', repo_dir)",
-      "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/api.py\", line 219, in checkout",
+      "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/api.py\", line 221, in checkout",
       "    raise ValueError('Unsupported repo: %s' % name)",
       "ValueError('Unsupported repo: unsupported_repo')"
     ]
diff --git a/recipes/engine/release_builder.expected/basic_linux.json b/recipes/engine/release_builder.expected/basic_linux.json
index fdc3ab4..26709ed 100644
--- a/recipes/engine/release_builder.expected/basic_linux.json
+++ b/recipes/engine/release_builder.expected/basic_linux.json
@@ -1,7 +1,7 @@
 [
   {
     "cmd": [],
-    "name": "Checkout flutter/engine"
+    "name": "Checkout flutter/mirrors/engine"
   },
   {
     "cmd": [
@@ -9,7 +9,7 @@
       "-u",
       "RECIPE_MODULE[depot_tools::git]/resources/git_setup.py",
       "--path",
-      "[START_DIR]/engine",
+      "[START_DIR]/mirrors/engine",
       "--url",
       "https://flutter.googlesource.com/mirrors/engine"
     ],
@@ -25,7 +25,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git setup",
+    "name": "Checkout flutter/mirrors/engine.git setup",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -35,11 +35,12 @@
       "git",
       "fetch",
       "origin",
+      "main",
       "--recurse-submodules",
       "--progress",
       "--tags"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "env": {
       "PATH": "RECIPE_REPO[depot_tools]:<PATH>"
     },
@@ -56,7 +57,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git fetch",
+    "name": "Checkout flutter/mirrors/engine.git fetch",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -66,9 +67,9 @@
       "git",
       "checkout",
       "-f",
-      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+      "FETCH_HEAD"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -82,7 +83,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git checkout",
+    "name": "Checkout flutter/mirrors/engine.git checkout",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -93,7 +94,7 @@
       "rev-parse",
       "HEAD"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -107,7 +108,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.read revision",
+    "name": "Checkout flutter/mirrors/engine.read revision",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@",
       "@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@",
@@ -122,7 +123,7 @@
       "-d",
       "-x"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -136,7 +137,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git clean",
+    "name": "Checkout flutter/mirrors/engine.git clean",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -147,7 +148,7 @@
       "submodule",
       "sync"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -161,7 +162,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.submodule sync",
+    "name": "Checkout flutter/mirrors/engine.submodule sync",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -174,7 +175,7 @@
       "--init",
       "--recursive"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -188,7 +189,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.submodule update",
+    "name": "Checkout flutter/mirrors/engine.submodule update",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -209,7 +210,7 @@
       "--json-output",
       "/path/to/tmp/json",
       "copy",
-      "[START_DIR]/engine/.ci.yaml",
+      "[START_DIR]/mirrors/engine/.ci.yaml",
       "/path/to/tmp/"
     ],
     "infra_step": true,
@@ -236,7 +237,7 @@
       "vpython",
       "RECIPE_MODULE[flutter::yaml]/resources/parse_yaml.py",
       "--yaml_file",
-      "[START_DIR]/engine/.ci.yaml",
+      "[START_DIR]/mirrors/engine/.ci.yaml",
       "--json_file",
       "/path/to/tmp/json"
     ],
@@ -296,7 +297,7 @@
       }
     },
     "name": "launch builds.schedule",
-    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"try\", \"builder\": \"Linux Engine Drone\", \"project\": \"proj\"}, \"exe\": {\"cipdVersion\": \"refs/heads/main\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gerritChanges\": [{\"change\": \"123456\", \"host\": \"flutter-review.googlesource.com\", \"patchset\": \"7\", \"project\": \"mirrors/engine\"}], \"gitilesCommit\": {\"host\": \"flutter.googlesource.com\", \"id\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"project\": \"mirrors/engine\", \"ref\": \"refs/heads/main\"}, \"priority\": 25, \"properties\": {\"$flutter/osx_sdk\": {\"sdk_version\": \"14a5294e\"}, \"build\": {\"name\": \"linux one\", \"properties\": {\"$flutter/osx_sdk\": {\"sdk_version\": \"14a5294e\"}}, \"recipe\": \"engine/something\"}, \"environment\": \"Staging\", \"recipe\": \"engine/something\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"cq_experimental\", \"value\": \"false\"}, {\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
+    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"try\", \"builder\": \"Linux Engine Drone\", \"project\": \"proj\"}, \"exe\": {\"cipdVersion\": \"refs/heads/main\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gerritChanges\": [{\"change\": \"123456\", \"host\": \"flutter-review.googlesource.com\", \"patchset\": \"7\", \"project\": \"mirrors/engine\"}], \"gitilesCommit\": {\"host\": \"flutter.googlesource.com\", \"id\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"project\": \"mirrors/engine\", \"ref\": \"refs/heads/main\"}, \"priority\": 25, \"properties\": {\"$flutter/osx_sdk\": {\"sdk_version\": \"14a5294e\"}, \"build\": {\"name\": \"linux one\", \"properties\": {\"$flutter/osx_sdk\": {\"sdk_version\": \"14a5294e\"}}, \"recipe\": \"engine/something\"}, \"environment\": \"Staging\", \"recipe\": \"engine/something\", \"repository\": \"engine\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"cq_experimental\", \"value\": \"false\"}, {\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@",
       "@@@STEP_LOG_LINE@json.output@{@@@",
@@ -360,7 +361,8 @@
       "@@@STEP_LOG_LINE@request@            \"recipe\": \"engine/something\"@@@",
       "@@@STEP_LOG_LINE@request@          }, @@@",
       "@@@STEP_LOG_LINE@request@          \"environment\": \"Staging\", @@@",
-      "@@@STEP_LOG_LINE@request@          \"recipe\": \"engine/something\"@@@",
+      "@@@STEP_LOG_LINE@request@          \"recipe\": \"engine/something\", @@@",
+      "@@@STEP_LOG_LINE@request@          \"repository\": \"engine\"@@@",
       "@@@STEP_LOG_LINE@request@        }, @@@",
       "@@@STEP_LOG_LINE@request@        \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", @@@",
       "@@@STEP_LOG_LINE@request@        \"swarming\": {@@@",
diff --git a/recipes/engine/release_builder.py b/recipes/engine/release_builder.py
index ec8866b..5686e25 100644
--- a/recipes/engine/release_builder.py
+++ b/recipes/engine/release_builder.py
@@ -14,6 +14,8 @@
 from PB.recipes.flutter.engine.engine import InputProperties
 from PB.recipes.flutter.engine.engine import EnvProperties
 
+from RECIPE_MODULES.flutter.repo_util.api import REPOS
+
 from google.protobuf import struct_pb2
 
 DEPS = [
@@ -38,13 +40,15 @@
 
 
 def RunSteps(api, properties, env_properties):
-  repository = 'engine'
+  repository = api.buildbucket.gitiles_commit.project
   checkout_path = api.path['start_dir'].join(repository)
+  git_ref = api.properties.get('git_ref') or api.buildbucket.gitiles_commit.ref
+  git_url = api.properties.get('git_url') or REPOS[repository]
   api.repo_util.checkout(
     repository,
     checkout_path=checkout_path,
-    url=api.properties.get('git_url'),
-    ref=api.properties.get('git_ref')
+    url=git_url,
+    ref=git_ref
   )
 
   ci_yaml_path = checkout_path.join('.ci.yaml')
@@ -86,7 +90,7 @@
   yield api.test(
     'basic_linux',
     api.platform.name('linux'),
-    api.properties(environment='Staging'),
+    api.properties(environment='Staging', repository='engine'),
     api.buildbucket.try_build(
       project='proj',
       builder='try-builder',
diff --git a/recipes/release/release_builder.expected/basic_linux.json b/recipes/release/release_builder.expected/basic_linux.json
index 723345f..26709ed 100644
--- a/recipes/release/release_builder.expected/basic_linux.json
+++ b/recipes/release/release_builder.expected/basic_linux.json
@@ -1,7 +1,7 @@
 [
   {
     "cmd": [],
-    "name": "Checkout flutter/engine"
+    "name": "Checkout flutter/mirrors/engine"
   },
   {
     "cmd": [
@@ -9,7 +9,7 @@
       "-u",
       "RECIPE_MODULE[depot_tools::git]/resources/git_setup.py",
       "--path",
-      "[START_DIR]/engine",
+      "[START_DIR]/mirrors/engine",
       "--url",
       "https://flutter.googlesource.com/mirrors/engine"
     ],
@@ -25,7 +25,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git setup",
+    "name": "Checkout flutter/mirrors/engine.git setup",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -35,11 +35,12 @@
       "git",
       "fetch",
       "origin",
+      "main",
       "--recurse-submodules",
       "--progress",
       "--tags"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "env": {
       "PATH": "RECIPE_REPO[depot_tools]:<PATH>"
     },
@@ -56,7 +57,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git fetch",
+    "name": "Checkout flutter/mirrors/engine.git fetch",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -66,9 +67,9 @@
       "git",
       "checkout",
       "-f",
-      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+      "FETCH_HEAD"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -82,7 +83,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git checkout",
+    "name": "Checkout flutter/mirrors/engine.git checkout",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -93,7 +94,7 @@
       "rev-parse",
       "HEAD"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -107,7 +108,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.read revision",
+    "name": "Checkout flutter/mirrors/engine.read revision",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@",
       "@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@",
@@ -122,7 +123,7 @@
       "-d",
       "-x"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -136,7 +137,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.git clean",
+    "name": "Checkout flutter/mirrors/engine.git clean",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -147,7 +148,7 @@
       "submodule",
       "sync"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -161,7 +162,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.submodule sync",
+    "name": "Checkout flutter/mirrors/engine.submodule sync",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -174,7 +175,7 @@
       "--init",
       "--recursive"
     ],
-    "cwd": "[START_DIR]/engine",
+    "cwd": "[START_DIR]/mirrors/engine",
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -188,7 +189,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "Checkout flutter/engine.submodule update",
+    "name": "Checkout flutter/mirrors/engine.submodule update",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -209,7 +210,7 @@
       "--json-output",
       "/path/to/tmp/json",
       "copy",
-      "[START_DIR]/engine/.ci.yaml",
+      "[START_DIR]/mirrors/engine/.ci.yaml",
       "/path/to/tmp/"
     ],
     "infra_step": true,
@@ -236,7 +237,7 @@
       "vpython",
       "RECIPE_MODULE[flutter::yaml]/resources/parse_yaml.py",
       "--yaml_file",
-      "[START_DIR]/engine/.ci.yaml",
+      "[START_DIR]/mirrors/engine/.ci.yaml",
       "--json_file",
       "/path/to/tmp/json"
     ],
diff --git a/recipes/release/release_builder.py b/recipes/release/release_builder.py
index b5c9736..a4dfb55 100644
--- a/recipes/release/release_builder.py
+++ b/recipes/release/release_builder.py
@@ -14,6 +14,8 @@
 from PB.recipes.flutter.release.release import InputProperties
 from PB.recipes.flutter.release.release import EnvProperties
 
+from RECIPE_MODULES.flutter.repo_util.api import REPOS
+
 from google.protobuf import struct_pb2
 
 DEPS = [
@@ -38,11 +40,15 @@
 
 
 def RunSteps(api, properties, env_properties):
-  repository=api.properties.get('repository')
+  repository = api.buildbucket.gitiles_commit.project
   checkout_path = api.path['start_dir'].join(repository)
+  git_ref = api.properties.get('git_ref') or api.buildbucket.gitiles_commit.ref
+  git_url = api.properties.get('git_url') or REPOS[repository]
   api.repo_util.checkout(
     repository,
-    checkout_path=checkout_path
+    checkout_path=checkout_path,
+    url=git_url,
+    ref=git_ref
   )
 
   ci_yaml_path = checkout_path.join('.ci.yaml')
@@ -84,8 +90,7 @@
   yield api.test(
     'basic_linux',
     api.platform.name('linux'),
-    api.properties(environment='Staging'),
-    api.properties(repository='engine'),
+    api.properties(environment='Staging', repository='engine'),
     api.buildbucket.try_build(
       project='proj',
       builder='try-builder',