Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved version of source_changelog #541

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 49 additions & 16 deletions source_changelog.bash
Original file line number Diff line number Diff line change
@@ -1,24 +1,57 @@
#!/bin/bash
set -e

PREV_TAG=$1
current_origin_remote=$(git config --get remote.origin.url)

git fetch --tags
# need tweaks if using ssh
if [[ "${current_origin_remote/git@}" != "${current_origin_remote}" ]]; then
current_origin_remote=${current_origin_remote/\.git}
current_origin_remote=${current_origin_remote/[email protected]:/https://github.com/}
fi

REPO=$(basename `git rev-parse --show-toplevel`)
REPO_FULL="${REPO/ign-/ignition-}"
MAJOR=${PREV_TAG%.*.*}
BRANCH=${REPO/sdformat/sdf}${MAJOR}
if [[ -z ${current_origin_remote} ]]; then
echo "Script is unable to detect current remote.origin.url in this directory"
exit 1
fi

COMMITS=$(git log ${BRANCH}...${REPO_FULL}${MAJOR}_${PREV_TAG} --pretty=format:"%h")
if [[ $(git branch --show-current) == 'main' ]]; then
echo "Error: main branch should not be used for releasing"
exit 1
fi

for COMMIT in $COMMITS
do
TITLE_FULL=$(git log --format="%s" -n 1 $COMMIT)
TITLE=${TITLE_FULL% (\#*)}
PR=${TITLE_FULL#*\#}
PR=${PR%)}
if [[ -f "Changelog.md" ]]; then
software_name=$(head -1 Changelog*)
printf "%s (%s)\n\n" "${software_name}" "$(date +%Y-%m-%d)"
fi

echo "1. $TITLE"
echo " * [Pull request #$PR](https://github.com/ignitionrobotics/$REPO/pull/$PR)"
echo ""
current_tag=$(git symbolic-ref HEAD)
start_ref="HEAD"

# Find the previous release on the same branch, skipping prereleases if the
# current tag is a full release
previous_tag=""
while [[ -z $previous_tag || ( $previous_tag == *-* && $current_tag != *-* ) ]]; do
previous_tag="$(git describe --tags "$start_ref"^ --abbrev=0)"
start_ref="$previous_tag"
done

REPO=$(basename `git rev-parse --show-toplevel`)
REPO_FULL="${REPO/ign-/ignition-}"
VERSION=${previous_tag/${REPO_FULL}*_}
MAJOR=${VERSION%.*.*}
BRANCH=${REPO/sdformat/sdf}${MAJOR}

git log "${BRANCH}"..."${previous_tag}" --pretty=format:"%h|%s|%ae|%an" | \
while IFS='|' read -r sha title author_email author || [[ -n ${sha} ]]; do
pr_num="$(grep -o '#[[:digit:]]\+' <<<"$title")"
pr_num="${pr_num:1}"
pr_desc=${title/\ (#[[:digit:]]*)}
printf "1. %s\n" "$pr_desc"
printf " * [Pull request #%s](%s/pull/%s)\n" "$pr_num" "$current_origin_remote" "$pr_num"
if [[ "${author_email/@openrobotics.org}" == "${author_email}" ]] && \
[[ "${author_email/@osrfoundation.org}" == "${author_email}" ]] && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about excluding us, we need love too ❤️

[[ "${author_email/@users.noreply.github.com}" == "${author_email}" ]]; then
printf " * A contribution from: %s <%s>\n" "$author" "$author_email"
fi
echo
done