Skip to content

Commit d3af5a1

Browse files
authored
fix: squash-pr.sh
1 parent 152eadf commit d3af5a1

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

scripts/merge-train/squash-pr.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ pr_author=$(echo "$pr_info" | jq -r '.author.login')
2121
head_repo=$(echo "$pr_info" | jq -r '.headRepository.nameWithOwner')
2222
is_fork=$(echo "$pr_info" | jq -r '.isCrossRepository')
2323

24-
# We'll use AztecBot as the committer
25-
author_name="AztecBot"
26-
author_email="[email protected]"
24+
# Get the PR author's name and email
25+
author_info=$(gh api "/users/$pr_author" --jq '{name: .name, email: .email}')
26+
author_name=$(echo "$author_info" | jq -r '.name // .login')
27+
# Use GitHub's noreply email format if no public email
28+
author_email=$(echo "$author_info" | jq -r '.email // empty')
29+
if [[ -z "$author_email" || "$author_email" == "null" ]]; then
30+
# Get user ID for noreply email format
31+
user_id=$(gh api "/users/$pr_author" --jq '.id')
32+
author_email="${user_id}+${pr_author}@users.noreply.github.com"
33+
fi
2734

2835
# Create a temporary worktree to do the squashing
2936
worktree_dir=$(mktemp -d)
@@ -58,11 +65,11 @@ merge_base=$(git merge-base "$original_head" "origin/$base_branch")
5865
# Get all commits between merge_base and HEAD, excluding merges
5966
authors_info=$(git log "$merge_base..$original_head" --no-merges --format='%an <%ae>' | sort -u)
6067

61-
# Build Co-authored-by trailers
68+
# Build Co-authored-by trailers, excluding the main PR author
6269
co_authors=""
6370
while IFS= read -r author_line; do
64-
# Skip empty lines and AztecBot itself
65-
if [[ -n "$author_line" ]] && [[ "$author_line" != *"AztecBot"* ]] && [[ "$author_line" != *"[email protected]"* ]]; then
71+
# Skip empty lines, the main PR author, AztecBot, and [email protected]
72+
if [[ -n "$author_line" ]] && [[ "$author_line" != *"$author_name"* ]] && [[ "$author_line" != *"$author_email"* ]] && [[ "$author_line" != *"AztecBot"* ]] && [[ "$author_line" != *"[email protected]"* ]]; then
6673
co_authors="${co_authors}Co-authored-by: ${author_line}
6774
"
6875
fi

0 commit comments

Comments
 (0)