Check buildbucket commit ref if the release_ref property is not set

Bug: https://github.com/flutter/flutter/issues/117157
Change-Id: Ia08d76be7a7f6a20c544919d5feedcfeaa2c605f
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/37360
Commit-Queue: Drew Roen <drewroen@google.com>
Reviewed-by: Godofredo Contreras <godofredoc@google.com>
diff --git a/recipe_modules/adhoc_validation/__init__.py b/recipe_modules/adhoc_validation/__init__.py
index 671efed..bf16104 100644
--- a/recipe_modules/adhoc_validation/__init__.py
+++ b/recipe_modules/adhoc_validation/__init__.py
@@ -8,6 +8,7 @@
     'flutter/osx_sdk',
     'flutter/repo_util',
     'flutter/test_utils',
+    'recipe_engine/buildbucket',
     'recipe_engine/context',
     'recipe_engine/platform',
     'recipe_engine/properties',
diff --git a/recipe_modules/adhoc_validation/api.py b/recipe_modules/adhoc_validation/api.py
index 721f832..0e7d15a 100644
--- a/recipe_modules/adhoc_validation/api.py
+++ b/recipe_modules/adhoc_validation/api.py
@@ -91,8 +91,9 @@
               self.m.flutter_bcid.report_stage(BcidStage.UPLOAD_COMPLETE.value)
             project = self.m.properties.get('firebase_project')
             # Only deploy to firebase directly if this is master or main.
+            git_ref = self.m.properties.get('release_ref') or self.m.buildbucket.gitiles_commit.ref
             if ((self.m.properties.get('git_branch') in ['master', 'main']) or
-                (self.m.properties.get('release_ref') == 'refs/heads/stable')):
+                (git_ref == 'refs/heads/stable')):
               self.m.firebase.deploy_docs(
                   env=env,
                   env_prefixes=env_prefixes,