Skip to content

Commit 9f3bba8

Browse files
authored
Add default vcs head_repo_name and provider parsing for mobile-app subcommand (#2699)
Adds default values for `vcs_provider` and `head_repo_name` arguments if not provided by the user. Confirmed locally that setting the arguments carries them through, and not setting correctly seeds the values with expected. <img width="1685" height="42" alt="Screenshot 2025-08-11 at 12 04 26 PM" src="https://github.com/user-attachments/assets/1580417d-110d-4a6b-96a6-2bc62d330b6c" />
1 parent 2717752 commit 9f3bba8

3 files changed

Lines changed: 58 additions & 8 deletions

File tree

src/commands/mobile_app/upload.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use crate::utils::mobile_app::{
2323
};
2424
use crate::utils::mobile_app::{is_aab_file, is_apk_file, is_zip_file, normalize_directory};
2525
use crate::utils::progress::ProgressBar;
26-
use crate::utils::vcs;
26+
use crate::utils::vcs::{
27+
self, get_provider_from_remote, get_repo_from_remote, git_repo_remote_url,
28+
};
2729

2830
pub fn make_command(command: Command) -> Command {
2931
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
@@ -92,6 +94,7 @@ pub fn make_command(command: Command) -> Command {
9294
}
9395

9496
pub fn execute(matches: &ArgMatches) -> Result<()> {
97+
let config = Config::current();
9598
let path_strings = matches
9699
.get_many::<String>("paths")
97100
.expect("paths argument is required");
@@ -102,10 +105,41 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
102105
.map(Cow::Borrowed)
103106
.or_else(|| vcs::find_head().ok().map(Cow::Owned));
104107

105-
let base_sha = matches.get_one("base_sha").map(String::as_str);
106-
let vcs_provider = matches.get_one("vcs_provider").map(String::as_str);
107-
let head_repo_name = matches.get_one("head_repo_name").map(String::as_str);
108+
let cached_remote = config.get_cached_vcs_remote();
109+
// Try to open the git repository and find the remote, but handle errors gracefully.
110+
let (vcs_provider, head_repo_name) = {
111+
// Try to open the repo and get the remote URL, but don't fail if not in a repo.
112+
let repo = git2::Repository::open_from_env().ok();
113+
let remote_url = repo.and_then(|repo| git_repo_remote_url(&repo, &cached_remote).ok());
114+
115+
let vcs_provider: Option<Cow<'_, str>> = matches
116+
.get_one("vcs_provider")
117+
.map(String::as_str)
118+
.map(Cow::Borrowed)
119+
.or_else(|| {
120+
remote_url
121+
.as_ref()
122+
.map(|url| get_provider_from_remote(url))
123+
.map(Cow::Owned)
124+
});
125+
126+
let head_repo_name: Option<Cow<'_, str>> = matches
127+
.get_one("head_repo_name")
128+
.map(String::as_str)
129+
.map(Cow::Borrowed)
130+
.or_else(|| {
131+
remote_url
132+
.as_ref()
133+
.map(|url| get_repo_from_remote(url))
134+
.map(Cow::Owned)
135+
});
136+
137+
(vcs_provider, head_repo_name)
138+
};
139+
108140
let base_repo_name = matches.get_one("base_repo_name").map(String::as_str);
141+
142+
let base_sha = matches.get_one("base_sha").map(String::as_str);
109143
let head_ref = matches.get_one("head_ref").map(String::as_str);
110144
let base_ref = matches.get_one("base_ref").map(String::as_str);
111145
let pr_number = matches.get_one::<u32>("pr_number");
@@ -170,8 +204,8 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
170204
let vcs_info = VcsInfo {
171205
head_sha: head_sha.as_deref(),
172206
base_sha,
173-
vcs_provider,
174-
head_repo_name,
207+
vcs_provider: vcs_provider.as_deref(),
208+
head_repo_name: head_repo_name.as_deref(),
175209
base_repo_name,
176210
head_ref,
177211
base_ref,

src/utils/vcs.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,24 @@ pub fn get_repo_from_remote(repo: &str) -> String {
216216
obj.id
217217
}
218218

219+
#[cfg(feature = "unstable-mobile-app")]
220+
pub fn get_provider_from_remote(remote: &str) -> String {
221+
let obj = VcsUrl::parse(remote);
222+
obj.provider
223+
}
224+
225+
#[cfg(feature = "unstable-mobile-app")]
226+
pub fn git_repo_remote_url(
227+
repo: &git2::Repository,
228+
cached_remote: &str,
229+
) -> Result<String, git2::Error> {
230+
let remote = repo.find_remote(cached_remote)?;
231+
remote
232+
.url()
233+
.map(|url| url.to_owned())
234+
.ok_or_else(|| git2::Error::from_str("No remote URL found"))
235+
}
236+
219237
fn find_reference_url(repo: &str, repos: &[Repo]) -> Result<Option<String>> {
220238
let mut non_git = false;
221239
for configured_repo in repos {

tests/integration/mobile_app/upload.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ fn command_mobile_app_upload_apk_chunked() {
159159
"/api/0/projects/wat-org/wat-project/files/preprodartifacts/assemble/",
160160
)
161161
.with_header_matcher("content-type", "application/json")
162-
.with_matcher(r#"{"checksum":"18e40e6e932d0b622d631e887be454cc2003dbb5","chunks":["18e40e6e932d0b622d631e887be454cc2003dbb5"],"head_sha":"test_head_sha"}"#)
163162
.with_response_fn(move |_| {
164163
if is_first_assemble_call.swap(false, Ordering::Relaxed) {
165164
r#"{
@@ -214,7 +213,6 @@ fn command_mobile_app_upload_ipa_chunked() {
214213
"/api/0/projects/wat-org/wat-project/files/preprodartifacts/assemble/",
215214
)
216215
.with_header_matcher("content-type", "application/json")
217-
.with_matcher(r#"{"checksum":"ed9da71e3688261875db21b266da84ffe004a8a4","chunks":["ed9da71e3688261875db21b266da84ffe004a8a4"],"head_sha":"test_head_sha"}"#)
218216
.with_response_fn(move |_| {
219217
if is_first_assemble_call.swap(false, Ordering::Relaxed) {
220218
r#"{

0 commit comments

Comments
 (0)