Support pulling out the original base of the PR body to better preserve history
This commit is contained in:
parent
de3a4beece
commit
c283492fa7
|
@ -1,3 +1,4 @@
|
||||||
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
@ -70,6 +71,20 @@ impl PullRequest {
|
||||||
&self.base.gitref
|
&self.base.gitref
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stored version of the base branch in the pull request body.
|
||||||
|
/// Needed for when the original branch is merged and so it vanishes.
|
||||||
|
pub fn base_branch_orig(&self) -> Option<&str> {
|
||||||
|
let regex = Regex::new("git-stack-base-branch:([^ ]+)").unwrap();
|
||||||
|
self.body
|
||||||
|
.as_ref()
|
||||||
|
.map(|body| {
|
||||||
|
regex
|
||||||
|
.captures(&body)
|
||||||
|
.map(|re_match| re_match.get(1).unwrap().as_str())
|
||||||
|
})
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn url(&self) -> &str {
|
pub fn url(&self) -> &str {
|
||||||
&self.url
|
&self.url
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@ pub fn build(prs: &[Rc<PullRequest>]) -> Graph<Rc<PullRequest>, usize> {
|
||||||
|
|
||||||
for (i, pr) in prs.iter().enumerate() {
|
for (i, pr) in prs.iter().enumerate() {
|
||||||
let head_handle = handles[i];
|
let head_handle = handles[i];
|
||||||
if let Some(&base_handle) = handles_by_head.get(pr.base()) {
|
let base_to_use = pr.base_branch_orig().unwrap_or(pr.base());
|
||||||
|
if let Some(&base_handle) = handles_by_head.get(base_to_use) {
|
||||||
tree.add_edge(*base_handle, head_handle, 1);
|
tree.add_edge(*base_handle, head_handle, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue