Skip to content

Commit 5d65e66

Browse files
committed
Add new VCS params to mobile-app command
1 parent 3552d53 commit 5d65e66

File tree

4 files changed

+161
-19
lines changed

4 files changed

+161
-19
lines changed

src/api/data_types/chunking/mobile_app.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,24 @@ pub struct ChunkedMobileAppRequest<'a> {
99
pub checksum: Digest,
1010
pub chunks: &'a [Digest],
1111
#[serde(skip_serializing_if = "Option::is_none")]
12-
pub git_sha: Option<&'a str>,
13-
#[serde(skip_serializing_if = "Option::is_none")]
1412
pub build_configuration: Option<&'a str>,
13+
// VCS fields
14+
#[serde(skip_serializing_if = "Option::is_none")]
15+
pub head_sha: Option<&'a str>,
16+
#[serde(skip_serializing_if = "Option::is_none")]
17+
pub base_sha: Option<&'a str>,
18+
#[serde(skip_serializing_if = "Option::is_none")]
19+
pub provider: Option<&'a str>,
20+
#[serde(skip_serializing_if = "Option::is_none")]
21+
pub head_repo_name: Option<&'a str>,
22+
#[serde(skip_serializing_if = "Option::is_none")]
23+
pub base_repo_name: Option<&'a str>,
24+
#[serde(skip_serializing_if = "Option::is_none")]
25+
pub head_ref: Option<&'a str>,
26+
#[serde(skip_serializing_if = "Option::is_none")]
27+
pub base_ref: Option<&'a str>,
28+
#[serde(skip_serializing_if = "Option::is_none")]
29+
pub pr_number: Option<&'a str>,
1530
}
1631

1732
#[derive(Debug, Deserialize)]

src/api/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,15 @@ impl<'a> AuthenticatedApi<'a> {
10311031
project: &str,
10321032
checksum: Digest,
10331033
chunks: &[Digest],
1034-
git_sha: Option<&str>,
10351034
build_configuration: Option<&str>,
1035+
head_sha: Option<&str>,
1036+
base_sha: Option<&str>,
1037+
provider: Option<&str>,
1038+
head_repo_name: Option<&str>,
1039+
base_repo_name: Option<&str>,
1040+
head_ref: Option<&str>,
1041+
base_ref: Option<&str>,
1042+
pr_number: Option<&str>,
10361043
) -> ApiResult<AssembleMobileAppResponse> {
10371044
let url = format!(
10381045
"/projects/{}/{}/files/preprodartifacts/assemble/",
@@ -1044,8 +1051,15 @@ impl<'a> AuthenticatedApi<'a> {
10441051
.with_json_body(&ChunkedMobileAppRequest {
10451052
checksum,
10461053
chunks,
1047-
git_sha,
10481054
build_configuration,
1055+
head_sha,
1056+
base_sha,
1057+
provider,
1058+
head_repo_name,
1059+
base_repo_name,
1060+
head_ref,
1061+
base_ref,
1062+
pr_number,
10491063
})?
10501064
.send()?
10511065
.convert_rnf(ApiErrorKind::ProjectNotFound)

src/commands/mobile_app/upload.rs

Lines changed: 120 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,44 @@ pub fn make_command(command: Command) -> Command {
5151
.required(true),
5252
)
5353
.arg(
54-
Arg::new("sha")
55-
.long("sha")
56-
.help("The git commit sha to use for the upload. If not provided, the current commit sha will be used.")
54+
Arg::new("head_sha")
55+
.long("head-sha")
56+
.help("The VCS commit sha to use for the upload. If not provided, the current commit sha will be used.")
57+
)
58+
.arg(
59+
Arg::new("base_sha")
60+
.long("base-sha")
61+
.help("The VCS commit's base sha to use for the upload. If not provided, the merge-base of the current and remote branch will be used.")
62+
)
63+
.arg(
64+
Arg::new("vcs_provider")
65+
.long("vcs-provider")
66+
.help("The VCS provider to use for the upload. If not provided, the current provider will be used.")
67+
)
68+
.arg(
69+
Arg::new("head_repo_name")
70+
.long("head-repo-name")
71+
.help("The name of the git repository to use for the upload (e.g. organization/repository). If not provided, the current repository will be used.")
72+
)
73+
.arg(
74+
Arg::new("base_repo_name")
75+
.long("base-repo-name")
76+
.help("The name of the git repository to use for the upload (e.g. organization/repository). If not provided, the current repository will be used.")
77+
)
78+
.arg(
79+
Arg::new("head_ref")
80+
.long("head-ref")
81+
.help("The reference (branch) to use for the upload. If not provided, the current reference will be used.")
82+
)
83+
.arg(
84+
Arg::new("base_ref")
85+
.long("base-ref")
86+
.help("The reference (branch) to use for the upload. If not provided, the current reference will be used.")
87+
)
88+
.arg(
89+
Arg::new("pr_number")
90+
.long("pr-number")
91+
.help("The pull request number to use for the upload. If not provided, the current pull request number will be used.")
5792
)
5893
.arg(
5994
Arg::new("build_configuration")
@@ -67,12 +102,21 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
67102
.get_many::<String>("paths")
68103
.expect("paths argument is required");
69104

70-
let sha = matches
71-
.get_one("sha")
105+
let head_sha = matches
106+
.get_one("head_sha")
72107
.map(String::as_str)
73108
.map(Cow::Borrowed)
74109
.or_else(|| vcs::find_head().ok().map(Cow::Owned));
75110

111+
// TODO: Implement default values
112+
let base_sha = matches.get_one("base_sha").map(String::as_str);
113+
let vcs_provider = matches.get_one("vcs_provider").map(String::as_str);
114+
let head_repo_name = matches.get_one("head_repo_name").map(String::as_str);
115+
let base_repo_name = matches.get_one("base_repo_name").map(String::as_str);
116+
let head_ref = matches.get_one("head_ref").map(String::as_str);
117+
let base_ref = matches.get_one("base_ref").map(String::as_str);
118+
let pr_number = matches.get_one("pr_number").map(String::as_str);
119+
76120
let build_configuration = matches.get_one("build_configuration").map(String::as_str);
77121

78122
let api = Api::current();
@@ -140,8 +184,15 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
140184
&bytes,
141185
&org,
142186
&project,
143-
sha.as_deref(),
144187
build_configuration,
188+
head_sha.as_deref(),
189+
base_sha,
190+
vcs_provider,
191+
head_repo_name,
192+
base_repo_name,
193+
head_ref,
194+
base_ref,
195+
pr_number,
145196
) {
146197
Ok(_) => {
147198
info!("Successfully uploaded file: {}", path.display());
@@ -342,17 +393,31 @@ fn upload_file(
342393
bytes: &[u8],
343394
org: &str,
344395
project: &str,
345-
sha: Option<&str>,
346396
build_configuration: Option<&str>,
397+
head_sha: Option<&str>,
398+
base_sha: Option<&str>,
399+
vcs_provider: Option<&str>,
400+
head_repo_name: Option<&str>,
401+
base_repo_name: Option<&str>,
402+
head_ref: Option<&str>,
403+
base_ref: Option<&str>,
404+
pr_number: Option<&str>,
347405
) -> Result<()> {
348406
const SELF_HOSTED_ERROR_HINT: &str = "If you are using a self-hosted Sentry server, \
349407
update to the latest version of Sentry to use the mobile-app upload command.";
350408

351409
debug!(
352-
"Uploading file to organization: {}, project: {}, sha: {}, build_configuration: {}",
410+
"Uploading file to organization: {}, project: {}, head_sha: {}, base_sha: {}, vcs_provider: {}, head_repo_name: {}, base_repo_name: {}, head_ref: {}, base_ref: {}, pr_number: {}, build_configuration: {}",
353411
org,
354412
project,
355-
sha.unwrap_or("unknown"),
413+
head_sha.unwrap_or("unknown"),
414+
base_sha.unwrap_or("unknown"),
415+
vcs_provider.unwrap_or("unknown"),
416+
head_repo_name.unwrap_or("unknown"),
417+
base_repo_name.unwrap_or("unknown"),
418+
head_ref.unwrap_or("unknown"),
419+
base_ref.unwrap_or("unknown"),
420+
pr_number.unwrap_or("unknown"),
356421
build_configuration.unwrap_or("unknown")
357422
);
358423

@@ -386,8 +451,21 @@ fn upload_file(
386451

387452
pb.finish_with_duration("Finishing upload");
388453

389-
let response =
390-
api.assemble_mobile_app(org, project, checksum, &checksums, sha, build_configuration)?;
454+
let response = api.assemble_mobile_app(
455+
org,
456+
project,
457+
checksum,
458+
&checksums,
459+
build_configuration,
460+
head_sha,
461+
base_sha,
462+
vcs_provider,
463+
head_repo_name,
464+
base_repo_name,
465+
head_ref,
466+
base_ref,
467+
pr_number,
468+
)?;
391469
chunks.retain(|Chunk((digest, _))| response.missing_chunks.contains(digest));
392470

393471
if !chunks.is_empty() {
@@ -406,8 +484,15 @@ fn upload_file(
406484
&checksums,
407485
org,
408486
project,
409-
sha,
410487
build_configuration,
488+
head_sha,
489+
base_sha,
490+
vcs_provider,
491+
head_repo_name,
492+
base_repo_name,
493+
head_ref,
494+
base_ref,
495+
pr_number,
411496
)?;
412497
Ok(())
413498
}
@@ -418,8 +503,15 @@ fn poll_assemble(
418503
chunks: &[Digest],
419504
org: &str,
420505
project: &str,
421-
sha: Option<&str>,
422506
build_configuration: Option<&str>,
507+
head_sha: Option<&str>,
508+
base_sha: Option<&str>,
509+
vcs_provider: Option<&str>,
510+
head_repo_name: Option<&str>,
511+
base_repo_name: Option<&str>,
512+
head_ref: Option<&str>,
513+
base_ref: Option<&str>,
514+
pr_number: Option<&str>,
423515
) -> Result<()> {
424516
debug!("Polling assemble for checksum: {}", checksum);
425517

@@ -430,8 +522,21 @@ fn poll_assemble(
430522
pb.set_style(progress_style);
431523

432524
let response = loop {
433-
let response =
434-
api.assemble_mobile_app(org, project, checksum, chunks, sha, build_configuration)?;
525+
let response = api.assemble_mobile_app(
526+
org,
527+
project,
528+
checksum,
529+
chunks,
530+
build_configuration,
531+
head_sha,
532+
base_sha,
533+
vcs_provider,
534+
head_repo_name,
535+
base_repo_name,
536+
head_ref,
537+
base_ref,
538+
pr_number,
539+
)?;
435540

436541
if response.state.is_finished() {
437542
break response;

src/utils/vcs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ fn is_matching_url(a: &str, b: &str) -> bool {
211211
VcsUrl::parse(a) == VcsUrl::parse(b)
212212
}
213213

214+
// TODO: This is not used anywhere.
214215
pub fn get_repo_from_remote(repo: &str) -> String {
215216
let obj = VcsUrl::parse(repo);
216217
obj.id
@@ -398,6 +399,13 @@ pub fn find_head() -> Result<String> {
398399
Ok(head.id().to_string())
399400
}
400401

402+
pub fn find_base_sha(repo: &Repository, branch: &str) -> Result<String> {
403+
let head = repo.revparse_single(branch)?;
404+
Ok(head.id().to_string())
405+
}
406+
407+
408+
401409
/// Given commit specs, repos and remote_name this returns a list of head
402410
/// commits from it.
403411
pub fn find_heads(

0 commit comments

Comments
 (0)