mirror of
https://github.com/nix-community/nurl.git
synced 2024-09-11 18:39:19 +03:00
support fetching the latest revision for gitea
This commit is contained in:
parent
33c92eb6eb
commit
07f23a7970
@ -1,3 +1,6 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
impl_fetcher,
|
||||
simple::{SimpleFetcher, SimpleUrlFetcher},
|
||||
@ -6,6 +9,11 @@ use crate::{
|
||||
pub struct FetchFromGitea<'a>(pub &'a str);
|
||||
impl_fetcher!(FetchFromGitea<'a>);
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Commit {
|
||||
sha: String,
|
||||
}
|
||||
|
||||
impl<'a> SimpleFetcher<'a, 2> for FetchFromGitea<'a> {
|
||||
const KEYS: [&'static str; 2] = ["owner", "repo"];
|
||||
const NAME: &'static str = "fetchFromGitea";
|
||||
@ -13,6 +21,17 @@ impl<'a> SimpleFetcher<'a, 2> for FetchFromGitea<'a> {
|
||||
fn host(&'a self) -> Option<&'a str> {
|
||||
Some(self.0)
|
||||
}
|
||||
|
||||
fn fetch_rev(&self, [owner, repo]: &[&str; 2]) -> Result<String> {
|
||||
let url = format!("https://{}/api/v1/repos/{owner}/{repo}/commits", self.0);
|
||||
Ok(ureq::get(&url)
|
||||
.call()?
|
||||
.into_json::<Vec<Commit>>()?
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or_else(|| anyhow!("no commits found for https://{}/{owner}/{repo}", self.0))?
|
||||
.sha)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SimpleUrlFetcher<'a, 2> for FetchFromGitea<'a> {
|
||||
|
Loading…
Reference in New Issue
Block a user