From 4802f7a68d515d78ae25988410d62c5dc1f8c8f4 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 24 Dec 2024 10:52:34 +0100 Subject: feat(pkgs/back): Add a link to the source code This is required by the AGPL license and should probably also be done, because we do not have a reason to hide or obfuscate the code. --- pkgs/by-name/ba/back/Cargo.lock | 1 + pkgs/by-name/ba/back/Cargo.toml | 1 + pkgs/by-name/ba/back/src/issues/issue/mod.rs | 4 ++++ pkgs/by-name/ba/back/src/issues/mod.rs | 11 ++++++++--- pkgs/by-name/ba/back/src/main.rs | 21 +++++++++++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) (limited to 'pkgs/by-name') diff --git a/pkgs/by-name/ba/back/Cargo.lock b/pkgs/by-name/ba/back/Cargo.lock index 4803593..ed7f120 100644 --- a/pkgs/by-name/ba/back/Cargo.lock +++ b/pkgs/by-name/ba/back/Cargo.lock @@ -146,6 +146,7 @@ dependencies = [ "rocket", "serde", "serde_json", + "url", ] [[package]] diff --git a/pkgs/by-name/ba/back/Cargo.toml b/pkgs/by-name/ba/back/Cargo.toml index 3e81ec8..f697511 100644 --- a/pkgs/by-name/ba/back/Cargo.toml +++ b/pkgs/by-name/ba/back/Cargo.toml @@ -28,6 +28,7 @@ markdown = "1.0.0-alpha.21" rocket = "0.5.1" serde = "1.0.216" serde_json = "1.0.134" +url = "2.5.4" [profile.release] lto = true diff --git a/pkgs/by-name/ba/back/src/issues/issue/mod.rs b/pkgs/by-name/ba/back/src/issues/issue/mod.rs index ada7593..b78f473 100644 --- a/pkgs/by-name/ba/back/src/issues/issue/mod.rs +++ b/pkgs/by-name/ba/back/src/issues/issue/mod.rs @@ -16,6 +16,8 @@ use gix::{bstr::ByteSlice, Commit, Id, ObjectId, Repository}; use raw::{Operation, RawIssue}; use rocket::response::content::RawHtml; +use crate::SOURCE_CODE_REPOSITORY; + use super::format::{BackString, Markdown}; mod raw; @@ -315,6 +317,7 @@ impl<'a> Issue<'a> { @@ -322,6 +325,7 @@ impl<'a> Issue<'a> { "#, + SOURCE_CODE_REPOSITORY.get().expect("This should be set") )) } } diff --git a/pkgs/by-name/ba/back/src/issues/mod.rs b/pkgs/by-name/ba/back/src/issues/mod.rs index df3e57e..744d5ba 100644 --- a/pkgs/by-name/ba/back/src/issues/mod.rs +++ b/pkgs/by-name/ba/back/src/issues/mod.rs @@ -11,7 +11,11 @@ use std::path::Path; -use crate::issues::issue::{Issue, Status}; +use crate::{ + issues::issue::{Issue, Status}, + SOURCE_CODE_REPOSITORY, +}; +use format::BackString; use gix::{refs::Target, Repository}; use issue_show::BackPrefix; use rocket::{ @@ -74,6 +78,7 @@ pub fn issue_list_boilerplate(wanted_status: Status, counter_status: Status) ->
    - {} + {issue_list}
"#, - issue_list + SOURCE_CODE_REPOSITORY.get().expect("This should be set") )) } diff --git a/pkgs/by-name/ba/back/src/main.rs b/pkgs/by-name/ba/back/src/main.rs index d0b0f81..86fe196 100644 --- a/pkgs/by-name/ba/back/src/main.rs +++ b/pkgs/by-name/ba/back/src/main.rs @@ -13,12 +13,14 @@ use std::{env::args, path::PathBuf, process, sync::OnceLock}; use gix::ThreadSafeRepository; use rocket::{launch, routes}; +use url::Url; use crate::issues::{closed, open, show_issue, styles}; mod issues; static REPOSITORY: OnceLock = OnceLock::new(); +static SOURCE_CODE_REPOSITORY: OnceLock = OnceLock::new(); #[launch] fn rocket() -> _ { @@ -31,6 +33,25 @@ fn rocket() -> _ { process::exit(1); } }; + let source_code_url = { + match std::env::var("BACK_SOURCE_CODE_REPOSITORY_URL") { + Ok(value) => match Url::parse(&value) { + Ok(url) => url, + Err(err) => { + eprintln!("Can't parse `BACK_SOURCE_CODE_REPOSITORY_URL` value as url: {err}"); + process::exit(1); + } + }, + Err(err) => { + eprintln!("back needs you to specify a source code repositiory as `BACK_SOURCE_CODE_REPOSITORY_URL`: {err}"); + process::exit(1); + } + } + }; + + SOURCE_CODE_REPOSITORY + .set(source_code_url) + .expect("This should be unset by this stage"); REPOSITORY .set( -- cgit 1.4.1