Fetch the in-repo config file from the remote repo.
This commit is contained in:
24
src/discovery.rs
Normal file
24
src/discovery.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user