Use Forgejo-compatible repository contents API

This commit is contained in:
Georg Bauer
2026-08-03 18:29:10 +02:00
parent d47b21d6a6
commit 7376e6cee3
3 changed files with 59 additions and 15 deletions

View File

@@ -1,4 +1,9 @@
use super::*;
use std::{
io::{Read, Write},
net::TcpListener,
thread,
};
fn commit(sha: &str, parents: &[&str]) -> models::Commit {
models::Commit {
@@ -95,3 +100,41 @@ fn labels_first_commit_of_pull_branch() {
.contains(&"feature".into())
);
}
#[tokio::test]
async fn reads_nested_directory_from_compatible_contents_endpoint() {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let address = listener.local_addr().unwrap();
let server = thread::spawn(move || {
let (mut stream, _) = listener.accept().unwrap();
let mut buffer = [0; 4096];
let length = stream.read(&mut buffer).unwrap();
let request = String::from_utf8_lossy(&buffer[..length]).into_owned();
let body = r#"[{"name":"guide.md","path":"docs/guide.md","type":"file"}]"#;
write!(
stream,
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
body.len()
)
.unwrap();
request
});
let client =
Client::with_provider(&format!("http://{address}"), None, crate::Provider::Forgejo)
.unwrap();
let repository = RepositoryId::new("forgejo", "forgejo").unwrap();
let contents = client
.repository_contents(&repository, "docs/guide")
.await
.unwrap();
assert_eq!(contents.len(), 1);
assert_eq!(contents[0].path.as_deref(), Some("docs/guide.md"));
assert!(
server
.join()
.unwrap()
.starts_with("GET /api/v1/repos/forgejo/forgejo/contents/docs%2Fguide ")
);
}