chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
getTemplate reads the template from the mirror, as getFile does
crates/knotless-serve/src/web/opening.rs+16−4
| @@ -4,7 +4,7 @@ | ||
//! account logged in, through the same code as `knotless template`, | ||
//! `issue` and `pull`, with the labels and reviewers chosen beside them. | ||
| ||
use super::repo::found; | ||
use super::repo::{found, invalid}; | ||
use super::threads::{Written, acting, blobs, labelled, refused, reindex}; | ||
use super::*; | ||
use crate::viewer::Viewer; | ||
| @@ -48,10 +48,22 @@ pub async fn get_template( | ||
State(app): State<Arc<App>>, | ||
Query(p): Query<TemplateParams>, | ||
) -> Result<Response> { | ||
if p.kind != "pull" && p.kind != "issue" { | ||
let kind = &p.kind; | ||
return Err(invalid(format!( | ||
"a template is for a pull or an issue, not {kind}" | ||
))); | ||
} | ||
let repo = found(&app, &p.repo).await?; | ||
let url = url_of(&repo); | ||
let asked = forge::template(&repo.reader, &url, &p.kind, p.base.as_deref()); | ||
let template = asked.await.map_err(refused)?; | ||
// Read from the mirror, as a file is: a branch that is not there, or a | ||
// repository with no commits yet, has no template. | ||
let rev = p | ||
.base | ||
.as_ref() | ||
.map_or(repo.head.clone(), |b| format!("refs/heads/{b}")); | ||
let path = format!(".knotless/{}.md", p.kind); | ||
let bytes = repo.objects()?.blob(&rev, &path).ok(); | ||
let template = bytes.map(|b| String::from_utf8_lossy(&b).into_owned()); | ||
Ok(answer(Template { template })) | ||
} | ||
| ||
crates/knotless-serve/tests/pages.rs+5−2
| @@ -771,8 +771,11 @@ fn delegation_tokens_read_a_private_repository() { | ||
issues.2 | ||
); | ||
| ||
// What it reads again as them, such as the template a new issue is | ||
// asked to follow, finds the credential it got. | ||
// What it reads again as them from their PDS, such as the workflows | ||
// a ref has, finds the credential it got. | ||
let asked = ask("listWorkflows", "", Some(&token(&member, &space))); | ||
assert_eq!(asked.0, 200, "{}", asked.2); | ||
// The template a new issue is asked to follow, read from the mirror. | ||
let asked = ask("getTemplate", "&kind=issue", Some(&token(&member, &space))); | ||
assert_eq!(asked.0, 200, "{}", asked.2); | ||