diff --git a/src/api/pull_request.rs b/src/api/pull_request.rs index d2979ef..a0e9407 100644 --- a/src/api/pull_request.rs +++ b/src/api/pull_request.rs @@ -71,6 +71,24 @@ impl PullRequest { &self.base.gitref } + /// The base commit of the branch is stored in the pull request for later. + /// This digs it out if possible. + /// There is a timestamp included. + pub fn base_commit(&self) -> Option<(&str, u64)> { + let regex = Regex::new("git-stack-base-commit:([a-z0-9]+)@([0-9]+)").unwrap(); + self.body + .as_ref() + .map(|body| { + regex.captures(&body).map(|re_match| { + ( + re_match.get(1).unwrap().as_str(), + re_match[2].parse().unwrap(), + ) + }) + }) + .flatten() + } + /// 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> {