diff --git a/Cargo.toml b/Cargo.toml index 89de860..32fa4a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ name = "pr-tracker" version = "1.2.0" authors = ["Alyssa Ross "] -edition = "2018" +edition = "2021" license = "AGPL-3.0-or-later WITH GPL-3.0-linking-exception" [build-dependencies] diff --git a/src/main.rs b/src/main.rs index b088e1f..2ebcfee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ use futures_util::future::join_all; use http_types::mime; use once_cell::sync::Lazy; use serde::Deserialize; +use serde_json::json; use structopt::StructOpt; use tide::{Request, Response}; @@ -71,8 +72,10 @@ static GITHUB_TOKEN: Lazy = Lazy::new(|| { struct PageTemplate { error: Option, pr_number: Option, + email: Option, pr_title: Option, closed: bool, + subscribed: bool, tree: Option, source_url: String, } @@ -80,14 +83,10 @@ struct PageTemplate { #[derive(Debug, Deserialize)] struct Query { pr: Option, + email: Option, } -async fn track_pr(pr_number: Option, status: &mut u16, page: &mut PageTemplate) { - let pr_number = match pr_number { - Some(pr_number) => pr_number, - None => return, - }; - +async fn track_pr(pr_number: String, status: &mut u16, page: &mut PageTemplate) { let pr_number_i64 = match pr_number.parse() { Ok(n) => n, Err(_) => { @@ -146,8 +145,30 @@ async fn handle_request(request: Request) -> http_types::Result }; let pr_number = request.query::()?.pr; + let email = request.query::()?.email; + page.email = email.clone(); - track_pr(pr_number, &mut status, &mut page).await; + match pr_number.clone() { + Some(pr_number) => track_pr(pr_number, &mut status, &mut page).await, + None => {} + }; + match email { + Some(email) => { + if let Some(ref tree) = page.tree { + let mut v = Vec::new(); + let remaining = tree.collect_branches(&mut v); + if !remaining { + page.error = Some("There are no branches remaining to be tracked".to_string()) + } else { + page.subscribed = true; + let folder = format!("data/{}", pr_number.unwrap()); + std::fs::create_dir_all(folder.clone())?; + std::fs::write(format!("{folder}/{email}"), json!(v).to_string())?; + } + } + } + None => {} + } Ok(Response::builder(status) .content_type(mime::HTML) diff --git a/src/tree.rs b/src/tree.rs index 91dc05d..a6718ae 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -39,6 +39,18 @@ impl Tree { children: nexts, } } + pub fn collect_branches(&self, vec: &mut Vec) -> bool { + let mut res = false; + if let Some(true) = self.accepted { + vec.push(self.branch_name.clone()); + } else { + res = true + } + for c in &self.children { + res |= c.collect_branches(vec); + } + res + } fn fill_accepted(&mut self, branches: &BTreeSet, missing_means_absent: bool) { self.accepted = match branches.contains(OsStr::new(&self.branch_name)) { diff --git a/templates/page.html b/templates/page.html index fa1c07a..6a09f46 100644 --- a/templates/page.html +++ b/templates/page.html @@ -4,212 +4,237 @@ - - {% match pr_number %} - {%- when Some with (pr_number) -%} - {% match pr_title %} - {%- when Some with (pr_title) -%} - Nixpkgs PR #{{ pr_number }} ("{{ pr_title }}") progress - {%- else -%} - Nixpkgs PR #{{ pr_number }} progress - {%- endmatch -%} - {%- else -%} - Nixpkgs PR progress tracker - {% endmatch %} - - + + {% match pr_number %} + {%- when Some with (pr_number) -%} + {% match pr_title %} + {%- when Some with (pr_title) -%} + Nixpkgs PR #{{ pr_number }} ("{{ pr_title }}") progress + {%- else -%} + Nixpkgs PR #{{ pr_number }} progress + {%- endmatch -%} + {%- else -%} + Nixpkgs PR progress tracker + {% endmatch %} - - + ul>li:last-child>span::before { + content: none; + } - -
-

Nixpkgs Pull Request Tracker

+ ol { + position: relative; + } -
- - + + + +
+

Nixpkgs Pull Request Tracker

+ + {%- if subscribed -%} +
You will be notified be by mail when this PR reaches a new ???
+ {%- endif -%} + + + - - -
+
+ + +
+ + +
- {% match error %} - {% when Some with (error) %} -
-

{{ error }}

-
- {% else %} - {% endmatch %} + {% match error %} + {% when Some with (error) %} +
+

{{ error }}

+
+ {% else %} + {% endmatch %} - {% match pr_number %} - {%- when Some with (pr_number) -%} -
-
    -
  1. - {%- if closed -%} - - {%- else -%} - - {%- endif -%} - PR #{{ pr_number }} - {% match pr_title %} - {%- when Some with (pr_title) -%} - ("{{ pr_title }}") - {%- else -%} - {%- endmatch -%} - {% if closed %} - (closed) - {%- endif -%} -
  2. + {% match pr_number %} + {%- when Some with (pr_number) -%} +
    +
      +
    1. + {%- if closed -%} + + {%- else -%} + + {%- endif -%} + PR #{{ pr_number }} + {% match pr_title %} + {%- when Some with (pr_title) -%} + ("{{ pr_title }}") + {%- else -%} + {%- endmatch -%} + {% if closed %} + (closed) + {%- endif -%} +
    2. - {% match tree %} - {%- when Some with (tree) -%} - {{- tree|safe -}} - {%- else -%} - {%- endmatch -%} -
    -
    - {%- else -%} - {% endmatch %} - -
    -

    By Alyssa Ross

    + {% match tree %} + {%- when Some with (tree) -%} + {{- tree|safe -}} + {%- else -%} + {%- endmatch -%} +
+
+ {%- else -%} + {% endmatch %} + + + -

Source code

- -