Skip to content

Commit 86a3d0a

Browse files
Use URL from backend (#2698)
Co-authored-by: Nico Hinderling <NicoHinderling@users.noreply.github.com>
1 parent 75920e8 commit 86a3d0a

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

src/api/data_types/chunking/mobile_app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ pub struct AssembleMobileAppResponse {
3535
pub state: ChunkedFileState,
3636
pub missing_chunks: Vec<Digest>,
3737
pub detail: Option<String>,
38-
pub artifact_id: Option<String>,
38+
pub artifact_url: Option<String>,
3939
}

src/commands/mobile_app/upload.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
161161

162162
let config = Config::current();
163163
let (org, project) = config.get_org_and_project(matches)?;
164-
let base_url = config.get_base_url()?;
165164

166-
let mut uploaded_paths_and_ids = vec![];
165+
let mut uploaded_paths_and_urls = vec![];
167166
let mut errored_paths_and_reasons = vec![];
168167
for (path, zip) in normalized_zips {
169168
info!("Uploading file: {}", path.display());
@@ -186,9 +185,9 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
186185
build_configuration,
187186
&vcs_info,
188187
) {
189-
Ok(artifact_id) => {
188+
Ok(artifact_url) => {
190189
info!("Successfully uploaded file: {}", path.display());
191-
uploaded_paths_and_ids.push((path.to_path_buf(), artifact_id));
190+
uploaded_paths_and_urls.push((path.to_path_buf(), artifact_url));
192191
}
193192
Err(e) => {
194193
debug!("Failed to upload file at path {}: {}", path.display(), e);
@@ -212,22 +211,21 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
212211
}
213212
}
214213

215-
if uploaded_paths_and_ids.is_empty() {
214+
if uploaded_paths_and_urls.is_empty() {
216215
bail!("Failed to upload any files");
217216
} else {
218217
println!(
219218
"Successfully uploaded {} file{} to Sentry",
220-
uploaded_paths_and_ids.len(),
221-
if uploaded_paths_and_ids.len() == 1 {
219+
uploaded_paths_and_urls.len(),
220+
if uploaded_paths_and_urls.len() == 1 {
222221
""
223222
} else {
224223
"s"
225224
}
226225
);
227-
if uploaded_paths_and_ids.len() < 3 {
228-
for (path, artifact_id) in &uploaded_paths_and_ids {
229-
let url = format!("{base_url}/{org}/preprod/{project}/{artifact_id}");
230-
println!(" - {} ({url})", path.display());
226+
if uploaded_paths_and_urls.len() < 3 {
227+
for (path, artifact_url) in &uploaded_paths_and_urls {
228+
println!(" - {} ({artifact_url})", path.display());
231229
}
232230
}
233231
}
@@ -337,7 +335,7 @@ fn handle_directory(path: &Path) -> Result<TempFile> {
337335
normalize_directory(path, temp_dir.path())
338336
}
339337

340-
/// Returns artifact id if upload was successful.
338+
/// Returns artifact url if upload was successful.
341339
fn upload_file(
342340
api: &AuthenticatedApi,
343341
bytes: &[u8],
@@ -390,15 +388,16 @@ fn upload_file(
390388
// In the normal case we go through this loop exactly twice:
391389
// 1. state=not_found
392390
// server tells us the we need to send every chunk and we do so
393-
// 2. artifact_id set so we're done (likely state=created)
391+
// 2. artifact_url set so we're done (likely state=created)
394392
//
395393
// In the case where all the chunks are already on the server we go
396394
// through only once:
397-
// 1. state=ok, artifact_id set
395+
// 1. state=created, artifact_url set
398396
//
399397
// In the case where something went wrong (which could be on either
400398
// iteration of the loop) we get:
401-
// n. state=err, artifact_id unset
399+
// n. state=error, artifact_url unset
400+
402401
let result = loop {
403402
let response = api.assemble_mobile_app(
404403
org,
@@ -425,14 +424,12 @@ fn upload_file(
425424
bail!("Failed to process uploaded files: {}", message);
426425
}
427426

428-
if let Some(artifact_id) = response.artifact_id {
429-
break Ok(artifact_id);
427+
if let Some(artifact_url) = response.artifact_url {
428+
break Ok(artifact_url);
430429
}
431430

432431
if response.state.is_finished() {
433-
bail!(
434-
"File upload is_finished() but did not succeeded (returning artifact_id) or error"
435-
);
432+
bail!("File upload is_finished() but did not succeeded or error");
436433
}
437434
};
438435

tests/integration/mobile_app/upload.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn command_mobile_app_upload_apk_all_uploaded() {
8686
"POST",
8787
"/api/0/projects/wat-org/wat-project/files/preprodartifacts/assemble/",
8888
)
89-
.with_response_body(r#"{"state":"ok","missingChunks":[],"artifactId":"42"}"#),
89+
.with_response_body(r#"{"state":"ok","missingChunks":[],"artifactUrl":"https://sentry.io/wat-org/preprod/wat-project/42"}"#),
9090
)
9191
.register_trycmd_test("mobile_app/mobile_app-upload-apk-all-uploaded.trycmd")
9292
.with_default_token();
@@ -170,7 +170,7 @@ fn command_mobile_app_upload_apk_chunked() {
170170
r#"{
171171
"state": "ok",
172172
"missingChunks": [],
173-
"artifactId": "42"
173+
"artifactUrl": "http://sentry.io/wat-org/preprod/wat-project/42"
174174
}"#
175175
}
176176
.into()
@@ -225,7 +225,7 @@ fn command_mobile_app_upload_ipa_chunked() {
225225
r#"{
226226
"state": "ok",
227227
"missingChunks": [],
228-
"artifactId": "some-text-id"
228+
"artifactUrl": "http://sentry.io/wat-org/preprod/wat-project/some-text-id"
229229
}"#
230230
}
231231
.into()

0 commit comments

Comments
 (0)