From 7656c322f16d381919d5b9488b2121d935b6ba1f Mon Sep 17 00:00:00 2001 From: Takayuki Nakata Date: Mon, 17 May 2021 22:32:19 +0900 Subject: [PATCH 1/3] Add a filter to the triage dashboard --- src/main.rs | 9 ++++++- src/triage.rs | 47 +++++++++++++++++++++++++++++++++++-- templates/triage/pulls.html | 4 ++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 91a8d0ef..a196572b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,14 @@ async fn serve_req(req: Request, ctx: Arc) -> Result, owner: &str, repo: &str, + filter: Option, ) -> Result, hyper::Error> { let octocrab = &ctx.octocrab; let res = octocrab @@ -51,6 +52,24 @@ pub async fn pulls( next_page = page.next; } + let mut label_filter = Vec::new(); + let mut author_filter = Vec::new(); + let mut assignee_filter = Vec::new(); + if let Some(filter) = filter.clone() { + let kvs: Vec<&str> = filter.split_whitespace().collect(); + for kv in kvs { + match kv.split_once(':') { + Some((k, v)) if !v.is_empty() => match k { + "label" => label_filter.push(v.to_string()), + "author" => author_filter.push(v.to_string()), + "assignee" => assignee_filter.push(v.to_string()), + _ => {} + }, + _ => {} + } + } + } + let mut pulls: Vec = Vec::new(); for base_pull in base_pulls.into_iter() { let assignee = base_pull.assignee.map_or("".to_string(), |v| v.login); @@ -71,13 +90,25 @@ pub async fn pulls( (Utc::now() - base_pull.created_at).num_days() }; - let labels = base_pull.labels.map_or("".to_string(), |labels| { + let labels = base_pull.labels.map_or(Vec::new(), |labels| { labels .iter() .map(|label| label.name.clone()) .collect::>() - .join(", ") }); + if !label_filter.is_empty() { + let mut flg = false; + for filter in label_filter.iter() { + if !labels.iter().any(|label| *label == *filter) { + flg = true; + } + } + if flg { + continue; + } + } + + let labels = labels.join(", "); let wait_for_author = labels.contains("S-waiting-on-author"); let wait_for_review = labels.contains("S-waiting-on-review"); let html_url = base_pull.html_url; @@ -85,6 +116,13 @@ pub async fn pulls( let title = base_pull.title; let author = base_pull.user.login; + if !author_filter.is_empty() && !author_filter.iter().all(|s| *s == author) { + continue; + } + if !assignee_filter.is_empty() && !assignee_filter.iter().all(|s| *s == assignee) { + continue; + } + let pull = PullRequest { html_url, number, @@ -105,6 +143,11 @@ pub async fn pulls( context.insert("pulls", &pulls); context.insert("owner", &owner); context.insert("repo", &repo); + if let Some(filter) = filter { + context.insert("filter", &filter); + } else { + context.insert("filter", ""); + } let tera = tera::Tera::new("templates/triage/**/*").unwrap(); let body = Body::from(tera.render("pulls.html", &context).unwrap()); diff --git a/templates/triage/pulls.html b/templates/triage/pulls.html index c6ff52e2..48a95ab8 100644 --- a/templates/triage/pulls.html +++ b/templates/triage/pulls.html @@ -42,6 +42,10 @@

Triage dashboard - {{ owner }}/{{ repo }}

+
+ + +
From cd64ed0bdd1d4e5b8ac13ff3c1215a907562beb5 Mon Sep 17 00:00:00 2001 From: Takayuki Nakata Date: Tue, 18 May 2021 22:20:14 +0900 Subject: [PATCH 2/3] Filter on the client side --- src/main.rs | 9 +------ src/triage.rs | 47 ++-------------------------------- templates/triage/pulls.html | 51 +++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 58 deletions(-) diff --git a/src/main.rs b/src/main.rs index a196572b..91a8d0ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,14 +21,7 @@ async fn serve_req(req: Request, ctx: Arc) -> Result, owner: &str, repo: &str, - filter: Option, ) -> Result, hyper::Error> { let octocrab = &ctx.octocrab; let res = octocrab @@ -52,24 +51,6 @@ pub async fn pulls( next_page = page.next; } - let mut label_filter = Vec::new(); - let mut author_filter = Vec::new(); - let mut assignee_filter = Vec::new(); - if let Some(filter) = filter.clone() { - let kvs: Vec<&str> = filter.split_whitespace().collect(); - for kv in kvs { - match kv.split_once(':') { - Some((k, v)) if !v.is_empty() => match k { - "label" => label_filter.push(v.to_string()), - "author" => author_filter.push(v.to_string()), - "assignee" => assignee_filter.push(v.to_string()), - _ => {} - }, - _ => {} - } - } - } - let mut pulls: Vec = Vec::new(); for base_pull in base_pulls.into_iter() { let assignee = base_pull.assignee.map_or("".to_string(), |v| v.login); @@ -90,25 +71,13 @@ pub async fn pulls( (Utc::now() - base_pull.created_at).num_days() }; - let labels = base_pull.labels.map_or(Vec::new(), |labels| { + let labels = base_pull.labels.map_or("".to_string(), |labels| { labels .iter() .map(|label| label.name.clone()) .collect::>() + .join(", ") }); - if !label_filter.is_empty() { - let mut flg = false; - for filter in label_filter.iter() { - if !labels.iter().any(|label| *label == *filter) { - flg = true; - } - } - if flg { - continue; - } - } - - let labels = labels.join(", "); let wait_for_author = labels.contains("S-waiting-on-author"); let wait_for_review = labels.contains("S-waiting-on-review"); let html_url = base_pull.html_url; @@ -116,13 +85,6 @@ pub async fn pulls( let title = base_pull.title; let author = base_pull.user.login; - if !author_filter.is_empty() && !author_filter.iter().all(|s| *s == author) { - continue; - } - if !assignee_filter.is_empty() && !assignee_filter.iter().all(|s| *s == assignee) { - continue; - } - let pull = PullRequest { html_url, number, @@ -143,11 +105,6 @@ pub async fn pulls( context.insert("pulls", &pulls); context.insert("owner", &owner); context.insert("repo", &repo); - if let Some(filter) = filter { - context.insert("filter", &filter); - } else { - context.insert("filter", ""); - } let tera = tera::Tera::new("templates/triage/**/*").unwrap(); let body = Body::from(tera.render("pulls.html", &context).unwrap()); diff --git a/templates/triage/pulls.html b/templates/triage/pulls.html index 48a95ab8..1d3aac32 100644 --- a/templates/triage/pulls.html +++ b/templates/triage/pulls.html @@ -38,15 +38,56 @@ border-radius:2; } +

Triage dashboard - {{ owner }}/{{ repo }}

-
- - - -
+ + +
From 8d05684e8609b4324fdcb67978a271316e98e93a Mon Sep 17 00:00:00 2001 From: Takayuki Nakata Date: Tue, 18 May 2021 22:43:39 +0900 Subject: [PATCH 3/3] Add a negative filter --- templates/triage/pulls.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/templates/triage/pulls.html b/templates/triage/pulls.html index 1d3aac32..7e9a6638 100644 --- a/templates/triage/pulls.html +++ b/templates/triage/pulls.html @@ -57,18 +57,23 @@ var td; switch (flt[0]) { case 'label': + case '-label': td = tr[i].getElementsByTagName("td")[6]; break; case 'assignee': + case '-assignee': td = tr[i].getElementsByTagName("td")[5]; break; case 'author': + case '-author': td = tr[i].getElementsByTagName("td")[4]; break; } if (td) { txtValue = td.textContent || td.innerText; - if (txtValue.indexOf(flt[1]) > -1) { + console.log(flt[0].charAt(0)); + if ((flt[0].charAt(0) != '-' && txtValue.indexOf(flt[1]) > -1) + || (flt[0].charAt(0) == '-' && txtValue.indexOf(flt[1]) <= -1)) { tr[i].style.display = ""; } else { tr[i].style.display = "none";
#