Skip to content

Commit 2fd573e

Browse files
committed
build: extract sign-off from commits and check all keywords
1 parent 0b47144 commit 2fd573e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

.github/workflows/scripts/generate_pr_commit_message

+17-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ on_error() {
5656
exit "$1"
5757
}
5858

59-
# Function to resolve GitHub handle to name and email using .mailmap
59+
# Resolves GitHub handle to name and email using .mailmap.
6060
#
6161
# $1 - GitHub handle
6262
resolve_user() {
@@ -76,7 +76,7 @@ resolve_user() {
7676
fi
7777
}
7878

79-
# Function to make authenticated GitHub API requests
79+
# Makes authenticated GitHub API requests.
8080
#
8181
# $1 - HTTP method (GET or POST)
8282
# $2 - API endpoint
@@ -114,12 +114,21 @@ main() {
114114
# Extract co-authors from commits:
115115
co_authors=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -i "Co-authored-by:" | awk -F': ' '{print $2}' | sort | uniq | paste -sd '\n' -)
116116

117-
# Extract linked issues from PR body (e.g., #123)
117+
# Extract 'Signed-off-by' lines from commits:
118+
signed_off_bys=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -Eio 'Signed-off-by:.*' | sort -u)
119+
120+
# Extract linked issues from PR body (e.g., #123):
118121
issue_numbers=$(echo "$pr_body" | grep -oE '#[0-9]+' | grep -oE '[0-9]+' | sort | uniq)
119122
closes_issues=""
120123
ref_issues=""
124+
125+
# GitHub-supported closing keywords:
126+
closing_keywords=("close" "closes" "closed" "fix" "fixes" "fixed" "resolve" "resolves" "resolved")
127+
# Create a regex pattern from the keywords:
128+
keywords_pattern=$(IFS='|'; echo "${closing_keywords[*]}")
129+
121130
for issue in $issue_numbers; do
122-
if echo "$pr_body" | grep -qi "closes.*#$issue"; then
131+
if echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then
123132
closes_issues+="Closes: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
124133
else
125134
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
@@ -146,10 +155,10 @@ main() {
146155
commit_body+="\nReviewed-by: $resolved_reviewer"
147156
done
148157

149-
# Add Signed-off-by line:
150-
pr_author=$(echo "$pr_details" | jq -r '.user.login')
151-
signed_off_by=$(resolve_user "$pr_author")
152-
commit_body+="\nSigned-off-by: $signed_off_by"
158+
# Include Signed-off-by lines if present in the commits:
159+
if [ -n "$signed_off_bys" ]; then
160+
commit_body+="\n$signed_off_bys"
161+
fi
153162

154163
# Combine subject and body:
155164
commit_message="$commit_subject\n\n$commit_body"

0 commit comments

Comments
 (0)