Skip to content

Commit

Permalink
Merge pull request #3 from igtm/feature/rm-merged-pr
Browse files Browse the repository at this point in the history
rm merged pr
  • Loading branch information
igtm committed Mar 6, 2023
2 parents 0421b20 + f907e5f commit 627b4cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "create-release-pr"
version = "0.0.3"
version = "0.0.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
23 changes: 23 additions & 0 deletions src/main.rs
Expand Up @@ -257,12 +257,20 @@ fn get_diff_pr(base: &str, head: &str) -> Vec<PR> {
let parts = RE_GIT_LS_REMOTE.captures(a).unwrap();
for pr in prs.iter_mut() {
if parts["hash"] == pr.hash {
if get_merge_base(&pr.hash, base).eq(&pr.hash) {
// already merged
break;
}
pr.id = parts["prid"].parse().unwrap();
break;
}

for pr in pr.children.iter_mut() {
if parts["hash"] == pr.hash {
if get_merge_base(&pr.hash, base).eq(&pr.hash) {
// already merged
break;
}
pr.id = parts["prid"].parse().unwrap();
}
}
Expand All @@ -278,6 +286,21 @@ fn get_diff_pr(base: &str, head: &str) -> Vec<PR> {
prs
}

fn get_merge_base(feature_hash: &str, base: &str) -> String {
// get merge base
let merge_base = Command::new("git")
.arg("merge-base")
.arg(feature_hash)
.arg(format!("origin/{}", base))
.output()
.expect("failed to execute process");
let out = std::str::from_utf8(&merge_base.stdout).unwrap();
out.strip_suffix("\r\n")
.or(out.strip_suffix("\n"))
.unwrap_or(out)
.to_owned()
}

fn get_repo_name() -> (String, String) {
// get feature branch commit hash of merge commits
let url = Command::new("git")
Expand Down

0 comments on commit 627b4cf

Please sign in to comment.