From dfb5714045e99a09bf3f67890ae3cdeab47058b3 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 26 Dec 2024 17:50:54 +0100 Subject: feat(pkgs/back): Rewrite the `git-bug` interface code The previous code was more or less reverse engineered, whilst this code is based on the actually git-bug source code. This improves the whole issue and operation handling immensely and also makes the code better maintainable. Furthermore, it also adds support for the operations that had not already used in `vhack.eu/nixos-server.git`. --- pkgs/by-name/ba/back/src/web/issue_html.rs | 166 +++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 pkgs/by-name/ba/back/src/web/issue_html.rs (limited to 'pkgs/by-name/ba/back/src/web/issue_html.rs') diff --git a/pkgs/by-name/ba/back/src/web/issue_html.rs b/pkgs/by-name/ba/back/src/web/issue_html.rs new file mode 100644 index 0000000..45c0281 --- /dev/null +++ b/pkgs/by-name/ba/back/src/web/issue_html.rs @@ -0,0 +1,166 @@ +// Back - An extremely simple git issue tracking system. Inspired by tvix's +// panettone +// +// Copyright (C) 2024 Benedikt Peetz +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// This file is part of Back. +// +// You should have received a copy of the License along with this program. +// If not, see . + +use rocket::response::content::RawHtml; + +use crate::{ + config::BackConfig, + git_bug::{ + format::HtmlString, + issue::{identity::Author, CollapsedIssue, Comment}, + }, +}; + +impl CollapsedIssue { + pub fn to_list_entry(&self) -> RawHtml { + let comment_list = if self.comments.is_empty() { + String::new() + } else { + let comments_string = if self.comments.len() > 1 { + "comments" + } else { + "comment" + }; + + format!( + r#" + - {} {} + "#, + self.comments.len(), + comments_string + ) + }; + + let CollapsedIssue { + id, + title, + message: _, + author, + timestamp, + comments: _, + status: _, + last_status_change: _, + labels: _, + } = self; + + let Author { name, email, id: _ } = author; + + RawHtml(format!( + r#" +
  • + +

    + {title} +

    + {id} - Opened by {name} <{email}> at {timestamp}{comment_list}
    +
  • +"#, + )) + } + + pub fn to_html(&self, config: &BackConfig) -> RawHtml { + let comments = if self.comments.is_empty() { + String::new() + } else { + let fmt_comments: String = self + .comments + .iter() + .map(|val| { + let Comment { + id, + author, + message, + timestamp, + } = val; + let Author { + name, + email: _, + id: _, + } = author; + + format!( + r#" +
  • + {message} +

    {name} at {timestamp}

    +
  • + "#, + ) + }) + .collect::>() + .join("\n"); + + format!( + r#" +
      + {fmt_comments} +
    + "# + ) + }; + + { + let CollapsedIssue { + id, + title, + message, + author, + timestamp, + comments: _, + status: _, + last_status_change: _, + labels: _, + } = self; + let Author { name, email, id: _ } = author; + let html_title = HtmlString::from(title.clone()); + + RawHtml(format!( + r#" + + + + {html_title} | Back + + + + +
    + +
    +

    {title}

    +
    {id}
    +
    +
    +
    + Opened by {name} <{email}> at {timestamp} +
    + {message} + {comments} +
    + +
    + + +"#, + config.source_code_repository_url + )) + } + } +} -- cgit 1.4.1