Update git_ref/url injected to drone

This is a follow up of https://flutter-review.googlesource.com/c/recipes/+/33300.
We should inject git_ref/git_url to drone build only when they exist in the parent build.

Change-Id: I04e59aba980a95519b8757bb130ced59ffd5c523
Bug: https://github.com/flutter/flutter/issues/103542
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/33381
Commit-Queue: Keyong Han <keyonghan@google.com>
Reviewed-by: Casey Hillers <chillers@google.com>
diff --git a/recipe_modules/repo_util/api.py b/recipe_modules/repo_util/api.py
index 7eaf9fc..711a0bf 100644
--- a/recipe_modules/repo_util/api.py
+++ b/recipe_modules/repo_util/api.py
@@ -267,13 +267,6 @@
       return gitiles_commit
     return self.m.properties.get('git_ref', 'led')
 
-  def get_env_url(self, repo):
-    '''Get the url of the current build from env.'''
-    git_url = REPOS[repo]
-    if 'git_url' in self.m.properties:
-      git_url = self.m.properties['git_url']
-    return git_url
-
   def current_commit_branches(self, checkout_path):
     """Gets the list of branches for the current commit."""
     with self.m.step.nest('Identify branches'):
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 2720218..c5a0665 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
@@ -1024,7 +1024,7 @@
       "The recipe has crashed at point 'Uncaught exception'!",
       "",
       "Traceback (most recent call last):",
-      "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/examples/full.py\", line 43, in RunSteps",
+      "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/examples/full.py\", line 42, in RunSteps",
       "    api.repo_util.monorepo_checkout(api.path['start_dir'], {}, {})",
       "  File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/api.py\", line 127, in monorepo_checkout",
       "    raise ValueError(",
diff --git a/recipe_modules/repo_util/examples/full.py b/recipe_modules/repo_util/examples/full.py
index 4241f31..34d31d1 100644
--- a/recipe_modules/repo_util/examples/full.py
+++ b/recipe_modules/repo_util/examples/full.py
@@ -34,7 +34,6 @@
   )
   api.repo_util.run_flutter_doctor()
   api.repo_util.get_env_ref()
-  api.repo_util.get_env_url('flutter')
 
   env, env_paths = api.repo_util.engine_environment(flutter_checkout_path)
   env, env_paths = api.repo_util.flutter_environment(flutter_checkout_path)
diff --git a/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json b/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json
index 3e72b2c..25352e4 100644
--- a/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json
+++ b/recipes/devicelab/devicelab_drone_build_test.expected/artifact does not exist.json
@@ -809,7 +809,7 @@
       }
     },
     "name": "buildbucket.schedule",
-    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/main\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_ref\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"git_url\": \"https://flutter.googlesource.com/mirrors/flutter\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
+    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/main\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"responses\": [@@@",
@@ -853,8 +853,7 @@
       "@@@STEP_LOG_LINE@request@        \"properties\": {@@@",
       "@@@STEP_LOG_LINE@request@          \"artifact\": \"def\", @@@",
       "@@@STEP_LOG_LINE@request@          \"dependencies\": [], @@@",
-      "@@@STEP_LOG_LINE@request@          \"git_ref\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", @@@",
-      "@@@STEP_LOG_LINE@request@          \"git_url\": \"https://flutter.googlesource.com/mirrors/flutter\", @@@",
+      "@@@STEP_LOG_LINE@request@          \"git_branch\": \"master\", @@@",
       "@@@STEP_LOG_LINE@request@          \"task_name\": \"abc\"@@@",
       "@@@STEP_LOG_LINE@request@        }, @@@",
       "@@@STEP_LOG_LINE@request@        \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", @@@",
diff --git a/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json b/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json
index eedfce6..f86c982 100644
--- a/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json
+++ b/recipes/devicelab/devicelab_drone_build_test.expected/artifact exists.json
@@ -34,7 +34,7 @@
     ],
     "infra_step": true,
     "name": "buildbucket.schedule",
-    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"builder\": \"Linux Devicelab Test Drone\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_ref\": \"refs/pull/1/head\", \"git_url\": \"test/repo\", \"task_name\": \"abc\"}, \"requestId\": \"0-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"0\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
+    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"builder\": \"Linux Devicelab Test Drone\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"git_ref\": \"refs/pull/1/head\", \"git_url\": \"test/repo\", \"task_name\": \"abc\"}, \"requestId\": \"0-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"0\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"responses\": [@@@",
@@ -68,6 +68,7 @@
       "@@@STEP_LOG_LINE@request@        \"properties\": {@@@",
       "@@@STEP_LOG_LINE@request@          \"artifact\": \"def\", @@@",
       "@@@STEP_LOG_LINE@request@          \"dependencies\": [], @@@",
+      "@@@STEP_LOG_LINE@request@          \"git_branch\": \"master\", @@@",
       "@@@STEP_LOG_LINE@request@          \"git_ref\": \"refs/pull/1/head\", @@@",
       "@@@STEP_LOG_LINE@request@          \"git_url\": \"test/repo\", @@@",
       "@@@STEP_LOG_LINE@request@          \"task_name\": \"abc\"@@@",
diff --git a/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json b/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json
index 6606796..3245aed 100644
--- a/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json
+++ b/recipes/devicelab/devicelab_drone_build_test.expected/local-engine.json
@@ -980,7 +980,7 @@
       }
     },
     "name": "buildbucket.schedule",
-    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/master\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_ref\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"git_url\": \"https://flutter.googlesource.com/mirrors/flutter\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
+    "stdin": "{\"requests\": [{\"scheduleBuild\": {\"builder\": {\"bucket\": \"ci\", \"builder\": \"Linux Devicelab Test Drone\", \"project\": \"test\"}, \"exe\": {\"cipdVersion\": \"refs/heads/master\"}, \"experimental\": \"NO\", \"experiments\": {\"luci.buildbucket.parent_tracking\": false}, \"fields\": \"builder,createTime,createdBy,critical,endTime,id,infra,input,number,output,startTime,status,updateTime\", \"gitilesCommit\": {\"host\": \"git.example.com\", \"id\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", \"project\": \"test/repo\", \"ref\": \"refs/heads/master\"}, \"priority\": 25, \"properties\": {\"artifact\": \"def\", \"dependencies\": [], \"git_branch\": \"master\", \"task_name\": \"abc\"}, \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", \"swarming\": {\"parentRunId\": \"fake-task-id\"}, \"tags\": [{\"key\": \"parent_buildbucket_id\", \"value\": \"8945511751514863184\"}, {\"key\": \"user_agent\", \"value\": \"recipe\"}]}}]}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"responses\": [@@@",
@@ -1024,8 +1024,7 @@
       "@@@STEP_LOG_LINE@request@        \"properties\": {@@@",
       "@@@STEP_LOG_LINE@request@          \"artifact\": \"def\", @@@",
       "@@@STEP_LOG_LINE@request@          \"dependencies\": [], @@@",
-      "@@@STEP_LOG_LINE@request@          \"git_ref\": \"2d72510e447ab60a9728aeea2362d8be2cbd7789\", @@@",
-      "@@@STEP_LOG_LINE@request@          \"git_url\": \"https://flutter.googlesource.com/mirrors/flutter\", @@@",
+      "@@@STEP_LOG_LINE@request@          \"git_branch\": \"master\", @@@",
       "@@@STEP_LOG_LINE@request@          \"task_name\": \"abc\"@@@",
       "@@@STEP_LOG_LINE@request@        }, @@@",
       "@@@STEP_LOG_LINE@request@        \"requestId\": \"8945511751514863184-00000000-0000-0000-0000-000000001337\", @@@",
diff --git a/recipes/devicelab/devicelab_drone_build_test.py b/recipes/devicelab/devicelab_drone_build_test.py
index 4d64b79..f626c2f 100644
--- a/recipes/devicelab/devicelab_drone_build_test.py
+++ b/recipes/devicelab/devicelab_drone_build_test.py
@@ -99,9 +99,11 @@
       'dependencies': [api.shard_util_v2.unfreeze_dict(dep) for dep in deps],
       'task_name': task_name,
       'artifact': artifact,
-      'git_ref': api.repo_util.get_env_ref(),
-      'git_url': api.repo_util.get_env_url('flutter'),
+      'git_branch': api.properties.get('git_branch'),
   }
+  if 'git_url' in api.properties and 'git_ref' in api.properties:
+    test_props['git_ref'] = api.properties['git_ref']
+    test_props['git_url'] = api.properties['git_url']
 
   req = api.buildbucket.schedule_request(
       swarming_parent_run_id=api.swarming.task_id,