Skip to content

Commit 7a4c9f1

Browse files
authored
Merge pull request #20 from input-output-hk/add-projects-to-pr-gathering
Classify PRs using `.projects` field
2 parents e83a747 + ea46b9b commit 7a4c9f1

File tree

1 file changed

+48
-22
lines changed

1 file changed

+48
-22
lines changed

scripts/generate-pr-changelogs.sh

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ select_notable() {
7171

7272
temp_changelog_yaml="$(mktemp)"
7373

74+
declare -A list_of_projects=()
75+
7476
for pr_number in $(
7577
git log --merges --oneline "$commit_range" \
7678
| grep 'Merge pull request' \
@@ -84,30 +86,54 @@ JQ
8486
| awk '/# Changelog/ {found=1} found {print}' \
8587
| awk '/^```yaml/{flag=1;next}/^```/{flag=0}flag' \
8688
> "$temp_changelog_yaml"
89+
pr_projects="$(cat "$temp_changelog_yaml" | yq -o json | jq -r ".[] | .projects? | .[]?")";
90+
for project in $pr_projects;
91+
do
92+
list_of_projects[$project]="${list_of_projects[$project]:+${list_of_projects[$project]} }$pr_number"
93+
done
94+
if [ -z "$pr_projects" ]; then
95+
list_of_projects["Project not specified"]="${list_of_projects["Project not specified"]:+${list_of_projects["Project not specified"]} }$pr_number"
96+
fi
97+
done
8798

88-
if cat "$temp_changelog_yaml" | select_notable; then
89-
if [ -s "$temp_changelog_yaml" ]; then
90-
cat "$temp_changelog_yaml" \
91-
| yq -o json \
92-
| jq -r "$(
93-
cat <<-JQ
94-
.[]
95-
| ([.type] | flatten | join(", ")) as \$type_string
96-
| ([.compatibility] | flatten | join(", ")) as \$compatibility
97-
| ([\$type_string, \$compatibility] | map(select(. != null and . != "")) | join ("; ")) as \$type_comp
98-
| "- \(.description | gsub("^[[:space:]]+|[[:space:]]+$"; "") | gsub("\n"; "\n "))\n (\(\$type_comp))"
99-
JQ
100-
)"
101-
else
102-
echo "- <missing changelog for PR ${pr_number}. Did you forget to run download-prs.sh?>"
103-
fi
104-
99+
for project in "${!list_of_projects[@]}"; do
100+
echo ""
101+
echo "## $project"
102+
echo ""
103+
for pr_number in ${list_of_projects[$project]}; do
105104
cat "$download_file" | yq -o json | jq -r "$(
106105
cat <<-JQ
107-
.[] | select(.number == $pr_number) | " [PR \(.number)](\(.url))"
106+
.[] | select(.number == $pr_number) | .body
108107
JQ
109-
)"
108+
)" \
109+
| awk '/# Changelog/ {found=1} found {print}' \
110+
| awk '/^```yaml/{flag=1;next}/^```/{flag=0}flag' \
111+
> "$temp_changelog_yaml"
112+
113+
if cat "$temp_changelog_yaml" | select_notable; then
114+
if [ -s "$temp_changelog_yaml" ]; then
115+
cat "$temp_changelog_yaml" \
116+
| yq -o json \
117+
| jq -r "$(
118+
cat <<-JQ
119+
.[]
120+
| ([.type] | flatten | join(", ")) as \$type_string
121+
| ([.compatibility] | flatten | join(", ")) as \$compatibility
122+
| ([\$type_string, \$compatibility] | map(select(. != null and . != "")) | join ("; ")) as \$type_comp
123+
| "- \(.description | gsub("^[[:space:]]+|[[:space:]]+$"; "") | gsub("\n"; "\n "))\n (\(\$type_comp))"
124+
JQ
125+
)"
126+
else
127+
echo "- <missing changelog for PR ${pr_number}. Did you forget to run download-prs.sh?>"
128+
fi
129+
130+
cat "$download_file" | yq -o json | jq -r "$(
131+
cat <<-JQ
132+
.[] | select(.number == $pr_number) | " [PR \(.number)](\(.url))"
133+
JQ
134+
)"
110135

111-
echo
112-
fi
113-
done
136+
echo
137+
fi
138+
done
139+
done

0 commit comments

Comments
 (0)