Skip to content

Commit 78ede50

Browse files
authored
ci: Add authors to release notes (#5834)
1 parent 322a4d9 commit 78ede50

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

scripts/release/check_commit_metadata.sh

+18-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ range="$from_ref..$to_ref"
3232
dependencies gh
3333

3434
COMMIT_METADATA_BREAKING=0
35-
declare -A COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY
35+
declare -A COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY COMMIT_METADATA_AUTHORS
3636

3737
# This environment variable can be set to 1 to ignore missing commit metadata,
3838
# useful for dry-runs.
@@ -66,22 +66,26 @@ main() {
6666
#
6767
# Example output:
6868
#
69-
# 27386d49d08455b6f8fbf2c18f38244d03fda892 label:security
70-
# d9f2aaf3b430d8b6f3d5f24032ed6357adaab1f1
71-
# fd54512858c906e66f04b0744d8715c2e0de97e6 label:stale label:enhancement
69+
# 27386d49d08455b6f8fbf2c18f38244d03fda892 author:hello labels:label:security
70+
# d9f2aaf3b430d8b6f3d5f24032ed6357adaab1f1 author:world
71+
# fd54512858c906e66f04b0744d8715c2e0de97e6 author:bye labels:label:stale label:enhancement
72+
from_commit_date=2023-01-18
7273
mapfile -t pr_labels_raw < <(
7374
gh pr list \
7475
--base main \
7576
--state merged \
7677
--limit 10000 \
7778
--search "merged:>=$from_commit_date" \
78-
--json mergeCommit,labels \
79-
--jq '.[] | .mergeCommit.oid + " " + (["label:" + .labels[].name] | join(" "))'
79+
--json mergeCommit,labels,author \
80+
--jq '.[] | "\( .mergeCommit.oid ) author:\( .author.login ) labels:\(["label:\( .labels[].name )"] | join(" "))"'
8081
)
81-
declare -A labels
82+
declare -A authors labels
8283
for entry in "${pr_labels_raw[@]}"; do
8384
commit_sha_long=${entry%% *}
84-
all_labels=${entry#* }
85+
commit_author=${entry#* author:}
86+
commit_author=${commit_author%% *}
87+
authors[$commit_sha_long]=$commit_author
88+
all_labels=${entry#* labels:}
8589
labels[$commit_sha_long]=$all_labels
8690
done
8791

@@ -92,7 +96,7 @@ main() {
9296
commit_prefix=${parts[2]}
9397

9498
# Safety-check, guarantee all commits had their metadata fetched.
95-
if [[ ! -v labels[$commit_sha_long] ]]; then
99+
if [[ ! -v authors[$commit_sha_long] ]] || [[ ! -v labels[$commit_sha_long] ]]; then
96100
if [[ $ignore_missing_metadata != 1 ]]; then
97101
error "Metadata missing for commit $commit_sha_short"
98102
else
@@ -104,6 +108,9 @@ main() {
104108
title=${parts[*]:2}
105109
title=${title%$'\n'}
106110
COMMIT_METADATA_TITLE[$commit_sha_short]=$title
111+
if [[ -v authors[$commit_sha_long] ]]; then
112+
COMMIT_METADATA_AUTHORS[$commit_sha_short]="@${authors[$commit_sha_long]}"
113+
fi
107114

108115
# First, check the title for breaking changes. This avoids doing a
109116
# GH API request if there's a match.
@@ -132,12 +139,12 @@ main() {
132139
}
133140

134141
declare_print_commit_metadata() {
135-
declare -p COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY
142+
declare -p COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY COMMIT_METADATA_AUTHORS
136143
}
137144

138145
export_commit_metadata() {
139146
_COMMIT_METADATA_CACHE="${range}:$(declare_print_commit_metadata)"
140-
export _COMMIT_METADATA_CACHE COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY
147+
export _COMMIT_METADATA_CACHE COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY COMMIT_METADATA_AUTHORS
141148
}
142149

143150
# _COMMIT_METADATA_CACHE is used to cache the results of this script in

scripts/release/generate_release_notes.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ for cat in "${!section_titles[@]}"; do
112112
done
113113

114114
for commit in "${commits[@]}"; do
115-
line="- $commit ${COMMIT_METADATA_TITLE[$commit]}\n"
115+
line="- $commit ${COMMIT_METADATA_TITLE[$commit]}"
116+
if [[ -v COMMIT_METADATA_AUTHORS[$commit] ]]; then
117+
line+=" (${COMMIT_METADATA_AUTHORS[$commit]})"
118+
fi
116119

117120
# Default to "other" category.
118121
cat=other
@@ -122,7 +125,7 @@ for commit in "${commits[@]}"; do
122125
break
123126
fi
124127
done
125-
declare "$cat"_changelog+="$line"
128+
declare "$cat"_changelog+="$line"$'\n'
126129
done
127130

128131
changelog="$(

0 commit comments

Comments
 (0)