-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
pub async fn repo_exists_with_version( | ||
user_or_org_name: &str, | ||
repo_name: &str, | ||
version: &str, | ||
) -> leptos::error::Result<bool> { | ||
let x = reqwasm::http::Request::get(&format!( | ||
"https://github.com/{user_or_org_name}/{repo_name}/releases/tag/{version}" | ||
)) | ||
.send() | ||
.await?; | ||
match x.status() { | ||
200 => Ok(true), | ||
404 => Ok(false), | ||
unexpected_status_code => { | ||
Err(GithubCheckErr::UnexpectedStatusCode(unexpected_status_code).into()) | ||
} | ||
} | ||
} | ||
|
||
pub async fn repo_exists(user_or_org_name: &str, repo_name: &str) -> leptos::error::Result<bool> { | ||
let x = reqwasm::http::Request::get(&format!( | ||
"https://github.com/{user_or_org_name}/{repo_name}/" | ||
)) | ||
.send() | ||
.await?; | ||
match x.status() { | ||
200 => Ok(true), | ||
404 => Ok(false), | ||
unexpected_status_code => { | ||
Err(GithubCheckErr::UnexpectedStatusCode(unexpected_status_code).into()) | ||
} | ||
} | ||
} | ||
|
||
pub async fn user_or_org_exists(user_or_org_name: &str) -> leptos::error::Result<bool> { | ||
let x = reqwasm::http::Request::get(&format!("https://github.com/{user_or_org_name}/")) | ||
.send() | ||
.await?; | ||
match x.status() { | ||
200 => Ok(true), | ||
404 => Ok(false), | ||
unexpected_status_code => { | ||
Err(GithubCheckErr::UnexpectedStatusCode(unexpected_status_code).into()) | ||
} | ||
} | ||
} | ||
|
||
#[derive(thiserror::Error, Clone, Debug)] | ||
pub enum GithubCheckErr { | ||
#[error("unexpected status code ({})", .0)] | ||
UnexpectedStatusCode(u16), | ||
} |