Merge branch 'master' into feature/ructe-static

This commit is contained in:
Valentin Brandl
2022-08-22 12:28:56 +02:00
5 changed files with 31 additions and 12 deletions

View File

@ -24,7 +24,7 @@ use crate::{
error::{Error, Result},
service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut},
statics::{CLIENT, VERSION_INFO},
template::RepoInfo,
template::{RepoGeneratorInfo, RepoInfo},
};
use actix_web::{
dev::Server,
@ -56,6 +56,7 @@ struct GeneratorForm<'a> {
service: FormService,
user: Cow<'a, str>,
repo: Cow<'a, str>,
branch: Option<Cow<'a, str>>,
}
#[derive(Debug)]
@ -438,16 +439,23 @@ async fn generate(
state: web::Data<State>,
repo_count: web::Data<AtomicUsize>,
) -> Result<HttpResponse> {
let repo = format!("{}/{}", params.user, params.repo);
let mut buf = Vec::new();
let repo_info = RepoGeneratorInfo {
service: params.service,
user: &params.user,
repo: &params.repo,
branch: params
.branch
.as_deref()
.filter(|s| !s.is_empty())
.unwrap_or("master"),
};
templates::generate(
&mut buf,
VERSION_INFO,
repo_count.load(Ordering::Relaxed),
&state.settings.base_url,
params.service.url(),
params.service.service(),
&repo,
&repo_info,
)?;
Ok(HttpResponse::Ok().content_type("text/html").body(buf))

View File

@ -28,8 +28,8 @@ pub(crate) trait Service: Sized + 'static {
}
}
#[derive(Deserialize, Serialize)]
pub(crate) enum FormService {
#[derive(Deserialize, Serialize, Clone, Copy)]
pub enum FormService {
#[serde(rename = "github")]
GitHub,
#[serde(rename = "gitlab")]

View File

@ -1,3 +1,5 @@
use crate::service::FormService;
pub struct RepoInfo<'a> {
pub commit_url: &'a str,
pub commits: u64,
@ -9,3 +11,10 @@ pub struct RepoInfo<'a> {
pub url: &'a str,
pub branch: &'a str,
}
pub struct RepoGeneratorInfo<'a> {
pub service: FormService,
pub user: &'a str,
pub repo: &'a str,
pub branch: &'a str,
}