From aa78e83aca2706140a7ecc7d619945f3748a6169 Mon Sep 17 00:00:00 2001 From: Olivier Date: Tue, 10 Jan 2023 18:45:58 +0000 Subject: [PATCH] Support pulling out the original base commit --- src/api/pull_request.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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> {