diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-26 10:00:45 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-26 10:01:56 +0100 |
commit | a3111a5d214db66b7d676940b8f8bfda5074bd45 (patch) | |
tree | a68cc1458386052a7c97a07b69bd161866ad7046 /pkgs/by-name/ba/back/src/web | |
parent | fix(hosts/server2): Use correct path to `vhack.eu/nixos-server` repo (diff) | |
download | nixos-server-a3111a5d214db66b7d676940b8f8bfda5074bd45.zip |
fix(pkgs/back): Use rocket to manage the configuration values
This reduces the amount of needed `unwraps`/`expects` and allows us to streamline the parsing processes.
Diffstat (limited to '')
-rw-r--r-- | pkgs/by-name/ba/back/src/web/format/mod.rs (renamed from pkgs/by-name/ba/back/src/issues/format/mod.rs) | 0 | ||||
-rw-r--r-- | pkgs/by-name/ba/back/src/web/issue/mod.rs (renamed from pkgs/by-name/ba/back/src/issues/issue/mod.rs) | 15 | ||||
-rw-r--r-- | pkgs/by-name/ba/back/src/web/issue/raw.rs (renamed from pkgs/by-name/ba/back/src/issues/issue/raw.rs) | 2 | ||||
-rw-r--r-- | pkgs/by-name/ba/back/src/web/issue_show.rs (renamed from pkgs/by-name/ba/back/src/issues/issue_show.rs) | 0 | ||||
-rw-r--r-- | pkgs/by-name/ba/back/src/web/mod.rs (renamed from pkgs/by-name/ba/back/src/issues/mod.rs) | 35 |
5 files changed, 28 insertions, 24 deletions
diff --git a/pkgs/by-name/ba/back/src/issues/format/mod.rs b/pkgs/by-name/ba/back/src/web/format/mod.rs index f78d3b3..f78d3b3 100644 --- a/pkgs/by-name/ba/back/src/issues/format/mod.rs +++ b/pkgs/by-name/ba/back/src/web/format/mod.rs diff --git a/pkgs/by-name/ba/back/src/issues/issue/mod.rs b/pkgs/by-name/ba/back/src/web/issue/mod.rs index b78f473..79ef70f 100644 --- a/pkgs/by-name/ba/back/src/issues/issue/mod.rs +++ b/pkgs/by-name/ba/back/src/web/issue/mod.rs @@ -16,7 +16,7 @@ use gix::{bstr::ByteSlice, Commit, Id, ObjectId, Repository}; use raw::{Operation, RawIssue}; use rocket::response::content::RawHtml; -use crate::SOURCE_CODE_REPOSITORY; +use crate::config::BackConfig; use super::format::{BackString, Markdown}; @@ -114,12 +114,17 @@ impl<'a> Issue<'a> { pub fn from_commit_id(repo: &'a Repository, commit_id: ObjectId) -> Self { fn unwrap_id<'b>(repo: &Repository, id: &Commit<'b>) -> (RawIssue, Id<'b>) { let tree_obj = repo - .find_object(id.tree_id().unwrap()) + .find_object( + id.tree_id() + .expect("All of git-bug's commits should have trees attached to them'"), + ) .expect("The object with this id should exist.") .try_into_tree() .expect("The git-bug's data model enforces this."); - let ops_ref = tree_obj.find_entry("ops").unwrap(); + let ops_ref = tree_obj + .find_entry("ops") + .expect("All of git-bug's trees should contain a 'ops' json file"); let issue_data = repo .find_object(ops_ref.object_id()) @@ -237,7 +242,7 @@ impl<'a> Issue<'a> { )) } - pub fn to_html(&self) -> RawHtml<String> { + pub fn to_html(&self, config: &BackConfig) -> RawHtml<String> { let fmt_comments: String = self .comments .iter() @@ -325,7 +330,7 @@ impl<'a> Issue<'a> { </body> </html> "#, - SOURCE_CODE_REPOSITORY.get().expect("This should be set") + config.source_code_repository_url )) } } diff --git a/pkgs/by-name/ba/back/src/issues/issue/raw.rs b/pkgs/by-name/ba/back/src/web/issue/raw.rs index 48d2a9f..bb447ec 100644 --- a/pkgs/by-name/ba/back/src/issues/issue/raw.rs +++ b/pkgs/by-name/ba/back/src/web/issue/raw.rs @@ -13,7 +13,7 @@ use gix::{bstr::ByteSlice, Repository}; use serde::Deserialize; use serde_json::Value; -use crate::issues::format::BackString; +use crate::web::format::BackString; use super::{Author, Status}; diff --git a/pkgs/by-name/ba/back/src/issues/issue_show.rs b/pkgs/by-name/ba/back/src/web/issue_show.rs index 638840e..638840e 100644 --- a/pkgs/by-name/ba/back/src/issues/issue_show.rs +++ b/pkgs/by-name/ba/back/src/web/issue_show.rs diff --git a/pkgs/by-name/ba/back/src/issues/mod.rs b/pkgs/by-name/ba/back/src/web/mod.rs index 744d5ba..ed91e7e 100644 --- a/pkgs/by-name/ba/back/src/issues/mod.rs +++ b/pkgs/by-name/ba/back/src/web/mod.rs @@ -12,19 +12,17 @@ use std::path::Path; use crate::{ - issues::issue::{Issue, Status}, - SOURCE_CODE_REPOSITORY, + config::BackConfig, + web::issue::{Issue, Status}, }; -use format::BackString; use gix::{refs::Target, Repository}; use issue_show::BackPrefix; use rocket::{ get, response::content::{RawCss, RawHtml}, + State, }; -use crate::REPOSITORY; - mod format; mod issue; mod issue_show; @@ -51,8 +49,12 @@ fn list_all_issues(repo: &'_ Repository) -> Vec<Issue<'_>> { .collect() } -pub fn issue_list_boilerplate(wanted_status: Status, counter_status: Status) -> RawHtml<String> { - let repository = REPOSITORY.get().expect("This should have been set"); +pub fn issue_list_boilerplate( + config: &State<BackConfig>, + wanted_status: Status, + counter_status: Status, +) -> RawHtml<String> { + let repository = &config.repository; let issue_list = list_all_issues(&repository.to_thread_local()) .iter() @@ -94,25 +96,22 @@ pub fn issue_list_boilerplate(wanted_status: Status, counter_status: Status) -> </body> </html> "#, - SOURCE_CODE_REPOSITORY.get().expect("This should be set") + config.source_code_repository_url )) } #[get("/issues/open")] -pub fn open() -> RawHtml<String> { - issue_list_boilerplate(Status::Open, Status::Closed) +pub fn open(config: &State<BackConfig>) -> RawHtml<String> { + issue_list_boilerplate(config, Status::Open, Status::Closed) } #[get("/issues/closed")] -pub fn closed() -> RawHtml<String> { - issue_list_boilerplate(Status::Closed, Status::Open) +pub fn closed(config: &State<BackConfig>) -> RawHtml<String> { + issue_list_boilerplate(config, Status::Closed, Status::Open) } #[get("/issue/<prefix>")] -pub fn show_issue(prefix: BackPrefix) -> RawHtml<String> { - let repository = REPOSITORY - .get() - .expect("This should have been set") - .to_thread_local(); +pub fn show_issue(config: &State<BackConfig>, prefix: BackPrefix) -> RawHtml<String> { + let repository = config.repository.to_thread_local(); let all_issues = list_all_issues(&repository); let maybe_issue = all_issues @@ -120,7 +119,7 @@ pub fn show_issue(prefix: BackPrefix) -> RawHtml<String> { .find(|issue| issue.id.to_string().starts_with(&prefix.to_string())); match maybe_issue { - Some(issue) => issue.to_html(), + Some(issue) => issue.to_html(config), None => RawHtml(format!("Issue with id '{prefix}' not found!")), } } |