From e022abbdcb21f3b093727b68bd832807d7bfc720 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 7 Aug 2025 16:30:46 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20add=20the=20github=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/github.rs | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/github.rs (limited to 'src/github.rs') diff --git a/src/github.rs b/src/github.rs new file mode 100644 index 0000000..50812d1 --- /dev/null +++ b/src/github.rs @@ -0,0 +1,69 @@ +use dialoguer::FuzzySelect; +use octocrab::models::repos::Asset; + +use crate::{AppImage, Error, Result}; + +pub async fn get_github_release_url(appimage: &AppImage) -> Result { + let octocrab = octocrab::instance(); + + let (owner, repo) = appimage + .source + .meta + .url + .split_once('/') + .ok_or_else(|| Error::InvalidSlug(appimage.source.meta.url.to_string()))?; + + let page = octocrab + .repos(owner, repo) + .releases() + .list() + .per_page(100) + .send() + .await?; + + let mut tags: Vec = vec![]; + + for releases in &page { + for asset in &releases.assets { + if asset.name.to_lowercase().ends_with(".appimage") { + tags.push(releases.tag_name.to_string()); + break; + } + } + } + + let tag_selection = FuzzySelect::new() + .with_prompt("Choose a release") + .items(&tags) + .interact()?; + + let mut assets: Vec = vec![]; + + for releases in page { + if releases.tag_name == tags[tag_selection] { + for asset in releases.assets { + if asset.name.to_lowercase().ends_with(".appimage") { + assets.push(asset); + } + } + } + } + + let mut asset_selection: usize = 0; + + if assets.len() > 1 { + asset_selection = FuzzySelect::new() + .with_prompt("Choose an asset") + .items( + &assets + .iter() + .map(|x| x.name.to_string()) + .collect::>(), + ) + .interact()?; + } + + let url = assets[asset_selection].browser_download_url.to_string(); + + Ok(url) +} -- cgit v1.2.3 From 9fd13a4ee0a189f6cf81658370df339a1d4e1868 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 7 Aug 2025 16:57:49 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20improve=20fuzzy=20select=20UX=20with?= =?UTF-8?q?=20length=20limit=20and=20vim=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/github.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/github.rs') diff --git a/src/github.rs b/src/github.rs index 50812d1..a37e7b1 100644 --- a/src/github.rs +++ b/src/github.rs @@ -35,6 +35,8 @@ pub async fn get_github_release_url(appimage: &AppImage) -> Result { let tag_selection = FuzzySelect::new() .with_prompt("Choose a release") .items(&tags) + .max_length(7) + .vim_mode(true) .interact()?; let mut assets: Vec = vec![]; @@ -60,6 +62,8 @@ pub async fn get_github_release_url(appimage: &AppImage) -> Result { .map(|x| x.name.to_string()) .collect::>(), ) + .max_length(7) + .vim_mode(true) .interact()?; } -- cgit v1.2.3