From 90a1b14f4f310a2e518bc9bc19253d42b4cb6bed Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 9 Mar 2025 00:11:10 +0100 Subject: pkgs/back: Do not store repositories in config Otherwise, back will need to be restarted every time a new repository is added or removed. --- pkgs/by-name/ba/back/src/web/generate/mod.rs | 82 ++++++++++++++-------------- 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'pkgs/by-name/ba/back/src/web/generate') diff --git a/pkgs/by-name/ba/back/src/web/generate/mod.rs b/pkgs/by-name/ba/back/src/web/generate/mod.rs index 10146bb..ae783a3 100644 --- a/pkgs/by-name/ba/back/src/web/generate/mod.rs +++ b/pkgs/by-name/ba/back/src/web/generate/mod.rs @@ -34,9 +34,9 @@ pub fn issues( repo_path: &Path, ) -> error::Result { let repository = config - .repositories + .repositories()? .get(repo_path)? - .open(config.repositories.scan_path())?; + .open(&config.scan_path)?; let mut issue_list = issues_from_repository(&repository.to_thread_local())? .into_iter() @@ -76,9 +76,9 @@ struct IssueTemplate { } pub fn issue(config: &BackConfig, repo_path: &Path, prefix: Prefix) -> error::Result { let repository = config - .repositories + .repositories()? .get(repo_path)? - .open(config.repositories.scan_path())? + .open(&config.scan_path)? .to_thread_local(); let maybe_issue = issues_from_repository(&repository)? @@ -113,39 +113,37 @@ struct RepoValue { } pub fn repos(config: &BackConfig) -> error::Result { let repos: Vec = config - .repositories + .repositories()? .iter() - .filter_map( - |raw_repo| match raw_repo.open(config.repositories.scan_path()) { - Ok(repo) => { - let repo = repo.to_thread_local(); - let git_config = repo.config_snapshot(); - - let path = raw_repo.path().to_string_lossy().to_string(); - - let owner = git_config - .string("cgit.owner") - .map(|v| v.to_string()) - .unwrap_or("".to_owned()); - - let description = fs::read_to_string(repo.git_dir().join("description")) - .unwrap_or("".to_owned()); - - Some(RepoValue { - description, - owner, - path, - }) - } - Err(err) => { - info!( - "Repo '{}' could not be opened: '{err}'", - raw_repo.path().display() - ); - None - } - }, - ) + .filter_map(|raw_repo| match raw_repo.open(&config.scan_path) { + Ok(repo) => { + let repo = repo.to_thread_local(); + let git_config = repo.config_snapshot(); + + let path = raw_repo.path().to_string_lossy().to_string(); + + let owner = git_config + .string("cgit.owner") + .map(|v| v.to_string()) + .unwrap_or("".to_owned()); + + let description = fs::read_to_string(repo.git_dir().join("description")) + .unwrap_or("".to_owned()); + + Some(RepoValue { + description, + owner, + path, + }) + } + Err(err) => { + info!( + "Repo '{}' could not be opened: '{err}'", + raw_repo.path().display() + ); + None + } + }) .collect(); Ok(ReposTemplate { @@ -160,9 +158,9 @@ pub fn feed(config: &BackConfig, repo_path: &Path) -> error::Result { use rss::{ChannelBuilder, Item, ItemBuilder}; let repository = config - .repositories + .repositories()? .get(repo_path)? - .open(config.repositories.scan_path())? + .open(&config.scan_path)? .to_thread_local(); let issues: Vec = issues_from_repository(&repository)? @@ -182,7 +180,7 @@ pub fn feed(config: &BackConfig, repo_path: &Path) -> error::Result { .link(format!( "/{}/{}/issue/{}", repo_path.display(), - &config.root, + &config.root_url, issue.id )) .build() @@ -207,7 +205,7 @@ pub fn feed(config: &BackConfig, repo_path: &Path) -> error::Result { .link(format!( "/{}/{}/issue/{}", repo_path.display(), - &config.root, + &config.root_url, issue.id )) .build() @@ -219,8 +217,8 @@ pub fn feed(config: &BackConfig, repo_path: &Path) -> error::Result { let channel = ChannelBuilder::default() .title("Issues") - .link(config.root.to_string()) - .description(format!("The rss feed for issues on {}.", &config.root)) + .link(config.root_url.to_string()) + .description(format!("The rss feed for issues on {}.", &config.root_url)) .items(items) .build(); Ok(channel.to_string()) -- cgit 1.4.1