Fetch the in-repo config file from the remote repo.

This commit is contained in:
Tom Alexander
2024-09-28 16:51:27 -04:00
parent c32a8650f5
commit 66228f83f2
6 changed files with 97 additions and 16 deletions

24
src/discovery.rs Normal file
View File

@@ -0,0 +1,24 @@
use crate::gitea_client::GiteaClient;
use crate::gitea_client::TreeFileReference;
use crate::in_repo_config::InRepoConfig;
pub(crate) async fn discover_webhook_bridge_config<O: AsRef<str>, R: AsRef<str>, C: AsRef<str>>(
gitea: &GiteaClient,
owner: O,
repo: R,
commit: C,
) -> Result<InRepoConfig, Box<dyn std::error::Error>> {
let repo_tree = gitea.get_tree(owner, repo, commit).await?;
let in_repo_config_reference = repo_tree
.files
.iter()
.filter(|file_reference| file_reference.path == ".webhook_bridge/webhook_bridge.toml")
.next()
.ok_or("File not found in remote repo: .webhook_bridge/webhook_bridge.toml.")?;
let in_repo_config_contents =
String::from_utf8(gitea.read_file(in_repo_config_reference).await?)?;
let parsed_in_repo_config = InRepoConfig::from_str(in_repo_config_contents)?;
Ok(parsed_in_repo_config)
}