Skip to content

Commit 2aeec8a

Browse files
Merge branch 'master' into manishrawat/retry_524
2 parents cf2243a + 9f3bba8 commit 2aeec8a

5 files changed

Lines changed: 93 additions & 38 deletions

File tree

src/commands/debug_files/find.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn find_ids_for_dsym(
224224
if dirent.path().extension() != Some(OsStr::new("class"));
225225
if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Dsym));
226226
then {
227-
return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Dsym))
227+
return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Dsym))
228228
}
229229
}
230230
None
@@ -237,7 +237,7 @@ fn find_ids_for_elf(
237237
if_chain! {
238238
if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Elf));
239239
then {
240-
return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Elf))
240+
return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Elf))
241241
}
242242
}
243243
None
@@ -252,7 +252,7 @@ fn find_ids_for_pe(
252252
dirent.path().extension() == Some(OsStr::new("dll"));
253253
if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Pe));
254254
then {
255-
return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Pe))
255+
return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Pe))
256256
}
257257
}
258258
None
@@ -266,7 +266,7 @@ fn find_ids_for_pdb(
266266
if dirent.path().extension() == Some(OsStr::new("pdb"));
267267
if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Pdb));
268268
then {
269-
return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Pdb))
269+
return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Pdb))
270270
}
271271
}
272272
None
@@ -280,7 +280,7 @@ fn find_ids_for_portablepdb(
280280
if dirent.path().extension() == Some(OsStr::new("pdb"));
281281
if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::PortablePdb));
282282
then {
283-
return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::PortablePdb))
283+
return Some(extract_remaining_ids(dif.ids(), remaining, DifType::PortablePdb))
284284
}
285285
}
286286
None
@@ -294,7 +294,7 @@ fn find_ids_for_sourcebundle(
294294
if dirent.path().extension() == Some(OsStr::new("zip"));
295295
if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::SourceBundle));
296296
then {
297-
return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::SourceBundle))
297+
return Some(extract_remaining_ids(dif.ids(), remaining, DifType::SourceBundle))
298298
}
299299
}
300300
None
@@ -308,25 +308,27 @@ fn find_ids_for_breakpad(
308308
if dirent.path().extension() == Some(OsStr::new("sym"));
309309
if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Breakpad));
310310
then {
311-
return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Breakpad))
311+
return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Breakpad))
312312
}
313313
}
314314
None
315315
}
316316

317-
fn extract_remaining_ids(
318-
ids: &[DebugId],
317+
fn extract_remaining_ids<I>(
318+
ids: I,
319319
remaining: &HashSet<DebugId>,
320320
t: DifType,
321-
) -> Vec<(DebugId, DifType)> {
322-
ids.iter()
323-
.filter_map(|id| {
324-
if remaining.contains(id) {
325-
return Some((id.to_owned(), t));
326-
}
327-
None
328-
})
329-
.collect()
321+
) -> Vec<(DebugId, DifType)>
322+
where
323+
I: Iterator<Item = DebugId>,
324+
{
325+
ids.filter_map(|id| {
326+
if remaining.contains(&id) {
327+
return Some((id.to_owned(), t));
328+
}
329+
None
330+
})
331+
.collect()
330332
}
331333

332334
pub fn execute(matches: &ArgMatches) -> Result<()> {

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/dif.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::fmt;
21
use std::path::Path;
32
use std::str;
3+
use std::{fmt, iter};
44

55
use anyhow::{bail, Context as _, Error, Result};
66
use proguard::ProguardMapping;
@@ -327,16 +327,19 @@ impl<'a> DifFile<'a> {
327327
}
328328
}
329329

330-
pub fn ids(&self) -> Vec<DebugId> {
331-
match self {
332-
DifFile::Archive(archive) => archive
333-
.get()
334-
.objects()
335-
.filter_map(Result::ok)
336-
.map(|object| object.debug_id())
337-
.collect(),
338-
DifFile::Proguard(pg) => vec![pg.get().uuid().into()],
339-
}
330+
pub fn ids(&self) -> impl Iterator<Item = DebugId> + '_ {
331+
let rv: Box<dyn Iterator<Item = _>> = match self {
332+
DifFile::Archive(archive) => Box::new(
333+
archive
334+
.get()
335+
.objects()
336+
.filter_map(Result::ok)
337+
.map(|object| object.debug_id()),
338+
),
339+
DifFile::Proguard(pg) => Box::new(iter::once(pg.get().uuid().into())),
340+
};
341+
342+
rv
340343
}
341344

342345
pub fn features(&self) -> ObjectDifFeatures {
@@ -407,7 +410,7 @@ impl<'a> DifFile<'a> {
407410
}
408411

409412
fn has_ids(&self) -> bool {
410-
self.ids().iter().any(|id| !id.is_nil())
413+
self.ids().any(|id| !id.is_nil())
411414
}
412415
}
413416

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)