Last active
March 13, 2024 04:25
-
-
Save myersCody/5f924d717f81cf4080954b67c5101c6f to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# export AUTH_TOKEN="your-github-token" | |
REPO_OWNER="project-koku" | |
REPO_NAME="koku" | |
RELEASE_HASH="725c0c053eafe7ac36ecb7b73282b9f744eb0957" | |
BOILERPLATE="This includes bug fixes and performance enhancements. For more detailed information see below" | |
# Function to fetch commit details | |
fetch_commit_details() { | |
commit_sha=$1 | |
curl -s -H "Authorization: token $AUTH_TOKEN" "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/commits/$commit_sha" | |
} | |
# Function to process commit message | |
process_commit_message() { | |
commit_details=$1 | |
merge_msg_pattern='\(#\d+\)' | |
jira_link_pattern='s/\[COST-([0-9]+)\]/[COST-\1](https:\/\/issues.redhat.com\/browse\/COST-\1)/g' | |
github_pr_link="s/\(#([0-9]+)\)/[\1](https:\/\/github.com\/$REPO_OWNER\/$REPO_NAME\/pull\/\1)/g" | |
filtered_message=$(echo "$commit_details" | jq -r '.commit.message' | grep -E "$merge_msg_pattern" | sed '/^$/d' | sed -E "$jira_link_pattern;$github_pr_link") | |
echo "$filtered_message" | |
} | |
# Grab latest_release & format commit messages | |
latest_response=$(curl -s -H "Authorization: token $AUTH_TOKEN" "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest") | |
latest_tag_name=$(echo "$latest_response" | jq -r '.tag_name') | |
latest_commit_sha=$(echo "$latest_response" | jq -r '.target_commitish') | |
commit_list=$(curl -s -H "Authorization: token $AUTH_TOKEN" "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/compare/$latest_commit_sha...HEAD" | jq -r '.commits[].sha') | |
commit_messages=() | |
customer_impact=() | |
for commit_sha in $commit_list; do | |
commit_details=$(fetch_commit_details "$commit_sha") | |
filtered_message=$(process_commit_message "$commit_details") | |
commit_messages+=("$filtered_message") | |
pr_number=$(echo "$filtered_message" | grep -oE '\[[0-9]+\]' | grep -oE '[0-9]+') | |
labels=$(curl -s -H "Authorization: token $AUTH_TOKEN" "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$pr_number" | jq -r '.labels[].name') | |
if [[ "$labels" =~ "customer-impact" ]]; then | |
customer_impact+=("$filtered_message") | |
fi | |
done | |
## Build the release notes | |
echo "### Whats Changed" >> release_body.md | |
echo "$BOILERPLATE" >> release_body.md | |
if [ ${#customer_impact[@]} -gt 0 ]; then | |
echo "## TODO: Summarize the following" >> release_body.md | |
echo "The issues below need to be added to the summary above in greater detail." >> release_body.md | |
echo "1. Summarize the issue and describe what we did" >> release_body.md | |
echo "2. Any impacted urls" >> release_body.md | |
echo "3. Update jiras & PR description with relevant information" >> release_body.md | |
for commit_message in "${customer_impact[@]}"; do | |
echo "* $commit_message" >> release_body.md | |
done | |
fi | |
echo "" >> release_body.md | |
if [ ${#commit_messages[@]} -gt 0 ]; then | |
echo "## Change History" >> release_body.md | |
for commit_message in "${commit_messages[@]}"; do | |
echo "* $commit_message" >> release_body.md | |
done | |
fi | |
today=$(date +"%Y.%m.%d") | |
prev_release=$(git tag --list | tail -1) | |
prev_date="${prev_release%.*}" | |
minor_version=0 | |
case $prev_date in | |
*"$today"*) | |
minor_version=${prev_release##*.} | |
minor_version=$((minor_version+1)) | |
;; | |
*) | |
minor_version=0 | |
;; | |
esac | |
this_release_tag="r.$today.$minor_version" | |
echo "" >> release_body.md | |
echo "**Full Changelog**: https://github.com/project-koku/koku/compare/$latest_tag_name...$this_release_tag" >> release_body.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment