Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changelog/shy-bats-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
changelogs: patch
---

Fixed PR number detection to use merge commit instead of file creation commit.
38 changes: 38 additions & 0 deletions src/changelog_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,44 @@ pub struct CommitInfo {
pub fn get_commit_info(_changelog_dir: &Path, id: &str) -> Option<CommitInfo> {
let file_path = format!(".changelog/{}.md", id);

// First, try to find the merge commit that brought this file into the current branch
// This gives us the PR number from the merge commit message (e.g., "Merge pull request #37")
let merge_output = std::process::Command::new("git")
.args([
"log",
"--merges",
"--ancestry-path",
"--format=%H %s",
"-1",
"--",
&file_path,
])
.output()
.ok()?;

let merge_stdout = String::from_utf8_lossy(&merge_output.stdout);
let merge_line = merge_stdout.trim();

// If we found a merge commit, use it
if !merge_line.is_empty() {
let parts: Vec<&str> = merge_line.splitn(2, ' ').collect();
if parts.len() >= 2 {
let commit_sha = parts[0].to_string();
let commit_message = parts[1];
let pr_number = extract_pr_number(commit_message);

if pr_number.is_some() {
let authors = get_commit_authors(&file_path);
return Some(CommitInfo {
pr_number,
commit_sha,
authors,
});
}
}
}

// Fallback: find the commit that added the file
let output = std::process::Command::new("git")
.args([
"log",
Expand Down