Skip to content

Commit

Permalink
Merge pull request #15 from MarathonLabs/fix/output-compatibility
Browse files Browse the repository at this point in the history
feat(download): output folder structure should be similar to cli v0
  • Loading branch information
Malinskiy authored Feb 7, 2024
2 parents 34e2a63 + 5385c3f commit b3b8984
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub trait RapiClient {
jwt_token: &str,
artifact: Artifact,
base_path: PathBuf,
run_id: &str,
) -> Result<()>;
}

Expand Down Expand Up @@ -131,7 +132,7 @@ impl RapiClient for RapiReqwestClient {
.ok_or(InputError::InvalidFileName {
path: test_app.clone(),
})?;
let test_app_total_size = (&file).metadata().await?.len();
let test_app_total_size = file.metadata().await?.len();
let mut test_app_reader = ReaderStream::new(file);
let mut multi_progress: Option<MultiProgress> = if progress {
Some(MultiProgress::new())
Expand Down Expand Up @@ -189,7 +190,7 @@ impl RapiClient for RapiReqwestClient {
.map(|val| val.to_string_lossy().to_string())
.ok_or(InputError::InvalidFileName { path: app.clone() })?;

let app_total_size = (&file).metadata().await?.len();
let app_total_size = file.metadata().await?.len();
let mut app_reader = ReaderStream::new(file);
let app_body;

Expand Down Expand Up @@ -311,13 +312,17 @@ impl RapiClient for RapiReqwestClient {
jwt_token: &str,
artifact: Artifact,
base_path: PathBuf,
run_id: &str,
) -> Result<()> {
let url = format!("{}/artifact", self.base_url);
let params = [("key", artifact.id.to_owned())];
let url = reqwest::Url::parse_with_params(&url, &params)
.map_err(|error| ApiError::InvalidParameters { error })?;

let relative_path = artifact.id.strip_prefix('/').unwrap_or(&artifact.id);
let id = artifact.id.strip_prefix('/').unwrap_or(&artifact.id);
let prefix_with_id = format!("{}/", run_id);
let relative_path = artifact.id.strip_prefix(&prefix_with_id).unwrap_or(id);

let relative_path = Path::new(&relative_path);
let mut absolute_path = base_path.clone();
absolute_path.push(relative_path);
Expand Down Expand Up @@ -388,7 +393,7 @@ pub struct GetTokenResponse {
pub token: String,
}

#[derive(Deserialize, Clone)]
#[derive(Deserialize, Clone, Debug)]
pub struct Artifact {
#[serde(rename = "id")]
pub id: String,
Expand Down
4 changes: 3 additions & 1 deletion src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub async fn fetch_artifact_list(

pub async fn download_artifacts(
client: &RapiReqwestClient,
run_id: &str,
artifacts: Vec<Artifact>,
path: &PathBuf,
token: &str,
Expand All @@ -66,10 +67,11 @@ pub async fn download_artifacts(
let client = client.clone();
let token = token.to_owned();
let base_path = path.clone();
let run_id = run_id.to_owned().clone();
let progress_bar = progress_bar.clone();
tokio::spawn(async move {
client
.download_artifact(&token, artifact, base_path)
.download_artifact(&token, artifact, base_path, &run_id)
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ pub fn default_error_handler(
output: &mut dyn Write,
) {
let red = Style::new().red();
writeln!(output, "{}", red.apply_to(error));
_ = writeln!(output, "{}", red.apply_to(error));
}
4 changes: 2 additions & 2 deletions src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl DownloadArtifactsInteractor {
let token = client.get_token().await?;
let artifacts = fetch_artifact_list(&client, id, &token).await?;
println!("{} Downloading files...", style("[3/4]").bold().dim());
download_artifacts(&client, artifacts, output, &token, true).await?;
download_artifacts(&client, id, artifacts, output, &token, true).await?;
println!(
"{} Patching local relative paths...",
style("[4/4]").bold().dim()
Expand Down Expand Up @@ -174,7 +174,7 @@ impl TriggerTestRunInteractor {
"{} Downloading files...",
style(format!("[4/{}]", steps)).bold().dim()
);
download_artifacts(&client, artifacts, output, &token, true).await?;
download_artifacts(&client, &id, artifacts, output, &token, true).await?;
println!(
"{} Patching local relative paths...",
style(format!("[5/{}]", steps)).bold().dim()
Expand Down

0 comments on commit b3b8984

Please sign in to comment.