Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add download PRs and generate PR changelog scripts
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
(yq --version | grep https://github.com/mikefarah/yq/ > /dev/null) || { | ||
echo "Please install yq from https://github.com/mikefarah/yq/" > /dev/stderr | ||
exit 1 | ||
} | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 repository" >&2 | ||
echo "Example: $0 input-output-hk/cardano-node" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ "$(uname -s)" == "Darwin" ]]; then | ||
date_cmd=gdate | ||
else | ||
date_cmd=date | ||
fi | ||
|
||
repository="$1" | ||
|
||
root_dir="$HOME/.cardano-updates" | ||
out_dir="$root_dir/$repository" | ||
|
||
mkdir -p "$out_dir" | ||
|
||
temp_json_file="$(mktemp).json" | ||
|
||
# Requires the default repository to be set in gh | ||
max_pr_number="$(gh pr list --state all --limit 1 --json number | jq '.[0].number // 1000')" | ||
|
||
echo "Downloading up to $max_pr_number PRs" | ||
|
||
gh pr list --repo "$repository" \ | ||
-L "$max_pr_number" \ | ||
--state all \ | ||
--json number,title,author,createdAt,closedAt,files,mergedAt,baseRefName,url,body \ | ||
> "$temp_json_file" | ||
|
||
cat "$temp_json_file" | yq -P > "$out_dir/download.yaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env bash | ||
|
||
repository="$1" | ||
subdir="$2" | ||
commit_range="$3" | ||
|
||
root_dir="$HOME/.cardano-updates" | ||
work_dir="$root_dir/$repository" | ||
work_subdir="$work_dir/$subdir" | ||
download_file="$work_dir/download.yaml" | ||
|
||
trim() { | ||
local trimmed=$1 | ||
# Remove leading whitespace | ||
trimmed=${trimmed##+([[:space:]])} | ||
# Remove trailing whitespace | ||
trimmed=${trimmed%%+([[:space:]])} | ||
printf '%s' "$trimmed" | ||
} | ||
|
||
extract_changelog() { | ||
local in_changelog=false | ||
|
||
# Read from stdin | ||
while IFS= read -r line; do | ||
trimmed_line=$(trim "$line") | ||
|
||
echo ">>>> $line ]" | ||
|
||
if [[ $trimmed_line == "# Changelog" ]]; then | ||
in_changelog=true | ||
elif [[ $trimmed_line == "# "* ]]; then | ||
in_changelog=false | ||
fi | ||
|
||
if [ "$in_changelog" = true ]; then | ||
echo "$line" | ||
fi | ||
done | ||
} | ||
|
||
select_notable() { | ||
yq -o json \ | ||
| jq -r ' | ||
["feature", "bugfix"] as $notable | ||
| if length == 0 then | ||
true | ||
elif .[0] | [.type] | flatten | any([.] | inside($notable)) then | ||
true | ||
else | ||
halt_error(1) | ||
end | ||
' \ | ||
> /dev/null 2> /dev/null | ||
} | ||
|
||
temp_changelog_yaml="$(mktemp)" | ||
|
||
for pr_number in $( | ||
git log --merges --oneline "$commit_range" \ | ||
| sed 's|^[0-9a-z]\+ Merge pull request #\([0-9]\+\) .*$|\1|g' | ||
); do | ||
cat "$download_file" | yq -o json | jq -r "$( | ||
cat <<-JQ | ||
.[] | select(.number == $pr_number) | .body | ||
JQ | ||
)" \ | ||
| awk '/# Changelog/{flag=1;next}/^#/{flag=0}flag' \ | ||
| awk '/^```yaml/{flag=1;next}/^```/{flag=0}flag' \ | ||
> "$temp_changelog_yaml" | ||
|
||
if cat "$temp_changelog_yaml" | select_notable; then | ||
if [ -s "$temp_changelog_yaml" ]; then | ||
cat "$temp_changelog_yaml" \ | ||
| yq -o json \ | ||
| jq -r "$( | ||
cat <<-JQ | ||
.[] | ||
| ([.type] | flatten | join(", ")) as \$type_string | ||
| "- \(.description | gsub("^[[:space:]]+|[[:space:]]+$"; "") | gsub("\n"; "\n "))\n (\(\$type_string); \(.compatibility))" | ||
JQ | ||
)" | ||
else | ||
echo "- <missing changelog>" | ||
fi | ||
|
||
cat "$download_file" | yq -o json | jq -r "$( | ||
cat <<-JQ | ||
.[] | select(.number == $pr_number) | " [PR \(.number)](\(.url))" | ||
JQ | ||
)" | ||
|
||
echo | ||
fi | ||
done |