summary refs log tree commit diff stats
path: root/pkgs/by-name
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-26 17:59:32 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-26 17:59:32 +0100
commit1a8886610d6a9662646ddb6c3541546dbe77f8df (patch)
tree5634a1be4f92c45f365e749a65d22c47e9bac899 /pkgs/by-name
parentfeat(pkgs/back): Rewrite the `git-bug` interface code (diff)
downloadnixos-server-1a8886610d6a9662646ddb6c3541546dbe77f8df.tar.gz
nixos-server-1a8886610d6a9662646ddb6c3541546dbe77f8df.zip
fix(pkgs/back): Sort the issues by descending date
Diffstat (limited to 'pkgs/by-name')
-rw-r--r--pkgs/by-name/ba/back/src/git_bug/format/mod.rs21
-rw-r--r--pkgs/by-name/ba/back/src/web/mod.rs31
2 files changed, 39 insertions, 13 deletions
diff --git a/pkgs/by-name/ba/back/src/git_bug/format/mod.rs b/pkgs/by-name/ba/back/src/git_bug/format/mod.rs
index 4ebf6d4..b3b6bcc 100644
--- a/pkgs/by-name/ba/back/src/git_bug/format/mod.rs
+++ b/pkgs/by-name/ba/back/src/git_bug/format/mod.rs
@@ -61,6 +61,27 @@ impl Display for TimeStamp {
     }
 }
 
+/// An UNIX time stamp.
+///
+/// These should only ever be used for human-display, because timestamps are unreliably in a
+/// distributed system.
+///
+/// This one allows underlying access to it's value and is only obtainable via `unsafe` code.
+/// The reason behind this is, that you might need to access this to improve the display for humans
+/// (i.e., sorting by date).
+#[derive(Debug, Default, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)]
+pub struct UnsafeTimeStamp {
+    value: u64,
+}
+impl TimeStamp {
+    /// # Safety
+    /// This is not really unsafe, but there is just no way your can trust a time stamp in a
+    /// distributed system. As such access to the raw value could lead to bugs.
+    pub unsafe fn to_unsafe(self) -> UnsafeTimeStamp {
+        UnsafeTimeStamp { value: self.value }
+    }
+}
+
 #[derive(Debug, Default, Deserialize, Clone, PartialEq, Eq)]
 /// A string that should be escaped when injected into html content.
 pub struct HtmlString {
diff --git a/pkgs/by-name/ba/back/src/web/mod.rs b/pkgs/by-name/ba/back/src/web/mod.rs
index 1e6a5af..35dc59f 100644
--- a/pkgs/by-name/ba/back/src/web/mod.rs
+++ b/pkgs/by-name/ba/back/src/web/mod.rs
@@ -39,20 +39,25 @@ pub fn issue_list_boilerplate(
 ) -> error::Result<RawHtml<String>> {
     let repository = &config.repository;
 
-    let issue_list = issues_from_repository(&repository.to_thread_local())?
+    let mut issue_list = issues_from_repository(&repository.to_thread_local())?
         .into_iter()
-        .fold(String::new(), |acc, val| {
-            let issue = val.collaps();
+        .map(|issue| issue.collapse())
+        .collect::<Vec<CollapsedIssue>>();
 
-            format!("{}{}", acc, {
-                if issue.status == wanted_status {
-                    let issue_entry = issue.to_list_entry();
-                    issue_entry.0
-                } else {
-                    String::new()
-                }
-            })
-        });
+    // Sort by date descending.
+    issue_list.sort_by_key(|issue| unsafe { issue.timestamp.to_unsafe() });
+    issue_list.reverse();
+
+    let issue_list_str = issue_list.into_iter().fold(String::new(), |acc, issue| {
+        format!("{}{}", acc, {
+            if issue.status == wanted_status {
+                let issue_entry = issue.to_list_entry();
+                issue_entry.0
+            } else {
+                String::new()
+            }
+        })
+    });
 
     let counter_status_lower = counter_status.to_string().to_lowercase();
     Ok(RawHtml(format!(
@@ -81,7 +86,7 @@ pub fn issue_list_boilerplate(
                    -->
                 </div>
                 <ol class="issue-list">
-                {issue_list}
+                {issue_list_str}
                 </ol>
              </main>
           </div>