Highlight current PR

This commit is contained in:
Timothy Andrew 2021-04-13 18:05:30 +05:30
parent ec46361f1e
commit eef30d7a68
No known key found for this signature in database
GPG Key ID: ABD64509E977B249
2 changed files with 11 additions and 9 deletions

View File

@ -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

View File

@ -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<dyn Error>> {
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)
});