From 6fb12489cb07fdb7afa143029ce413d3631c1dbd Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Mon, 8 May 2023 15:45:13 +0200 Subject: refactor: Only pass commit sha for installing launcher CI build (#313) * refactor: Only pass commit sha for installing launcher CI build This allows for easier usage later when installing a launcher build based on commit sha only, e.g. for installing newest build of a branch. * docs: Update comments to match current code --- src-tauri/src/github/pull_requests.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs index 20c19ed9..6c605424 100644 --- a/src-tauri/src/github/pull_requests.rs +++ b/src-tauri/src/github/pull_requests.rs @@ -158,11 +158,9 @@ fn get_mods_download_link(pull_request: PullsApiResponseElement) -> Result Result { +pub async fn get_launcher_download_link(commit_sha: String) -> Result { // Iterate over the first 10 pages of for i in 1..=10 { // Crossreference with runs API @@ -176,10 +174,10 @@ pub async fn get_launcher_download_link( Err(err) => return Err(format!("{}", err)), }; - // Cross-reference PR head commit sha against workflow runs + // Cross-reference commit sha against workflow runs for workflow_run in &runs_response.workflow_runs { - // If head commit sha of run and PR match, grab CI output - if workflow_run.head_sha == pull_request.head.sha { + // If head commit sha of CI run matches the one passed to this function, grab CI output + if workflow_run.head_sha == commit_sha { // Check artifacts let api_url = format!("https://api.github.com/repos/R2Northstar/NorthstarLauncher/actions/runs/{}/artifacts", workflow_run.id); let artifacts_response: ArtifactsResponse = serde_json::from_value( @@ -189,7 +187,7 @@ pub async fn get_launcher_download_link( // Iterate over artifacts for artifact in artifacts_response.artifacts { - // Make sure run is from PR head commit + // Make sure artifact and CI run commit head sha match if artifact.workflow_run.head_sha == workflow_run.head_sha { dbg!(artifact.id); @@ -202,8 +200,8 @@ pub async fn get_launcher_download_link( } Err(format!( - "Couldn't grab download link for PR \"{}\". PR might be too old and therefore no CI build has been detected. Maybe ask author to update?", - pull_request.number + "Couldn't grab download link for \"{}\". Corresponding PR might be too old and therefore no CI build has been detected. Maybe ask author to update?", + commit_sha )) } @@ -239,7 +237,15 @@ pub async fn apply_launcher_pr( check_is_valid_game_path(game_install_path)?; // get download link - let download_url = get_launcher_download_link(pull_request.clone()).await?; + let download_url = match get_launcher_download_link(pull_request.head.sha.clone()).await { + Ok(res) => res, + Err(err) => { + return Err(format!( + "Couldn't grab download link for PR \"{}\". {}", + pull_request.number, err + )) + } + }; let archive = match download_zip_into_memory(download_url).await { Ok(archive) => archive, -- cgit v1.2.3