From eef30d7a68491c2a5df95dc101604de89ea0f80b Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Tue, 13 Apr 2021 18:05:30 +0530 Subject: [PATCH] Highlight current PR --- src/markdown.rs | 9 +-------- src/persist.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/markdown.rs b/src/markdown.rs index b4ac8ff..d61abe9 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -1,15 +1,8 @@ -use regex::Regex; use std::fs; use crate::api::{PullRequestReviewState, PullRequestStatus}; use crate::graph::FlatDep; -fn process(row: String) -> String { - // TODO: Make this configurable - let regex = Regex::new(r"\[[^\]]+\]\s*").unwrap(); - regex.replace_all(&row, "").into_owned() -} - pub fn build_table(deps: &FlatDep, title: &str, prelude_path: Option<&str>) -> String { let is_complete = deps .iter() @@ -67,7 +60,7 @@ pub fn build_table(deps: &FlatDep, title: &str, prelude_path: Option<&str>) -> S ), }; - out.push_str(&process(row)); + out.push_str(&row); } out diff --git a/src/persist.rs b/src/persist.rs index f875759..aa244c1 100644 --- a/src/persist.rs +++ b/src/persist.rs @@ -27,9 +27,18 @@ fn safe_replace(body: &str, table: &str) -> String { } } +fn remove_title_prefixes(row: String) -> String { + // TODO: Make this configurable + let regex = Regex::new(r"\[[^\]]+\]\s*").unwrap(); + regex.replace_all(&row, "").into_owned() +} + + pub async fn persist(prs: &FlatDep, table: &str, c: &Credentials) -> Result<(), Box> { let futures = prs.iter().map(|(pr, _)| { - let description = safe_replace(pr.body(), table); + let body = table.replace(&pr.title()[..], &format!("👉 {}", pr.title())[..]); + let body = remove_title_prefixes(body); + let description = safe_replace(pr.body(), body.as_ref()); pull_request::update_description(description, pr.clone(), c) });