Skip to content

Instantly share code, notes, and snippets.

@nejckorasa
Last active March 12, 2020 10:19
Show Gist options
  • Select an option

  • Save nejckorasa/be98d0065dfff5f685a0aedc601e28eb to your computer and use it in GitHub Desktop.

Select an option

Save nejckorasa/be98d0065dfff5f685a0aedc601e28eb to your computer and use it in GitHub Desktop.
Git tags scripts to find out what PRs are in staging and if your PR is in staging. Saves you from looking at various CI/CD pipelines.
#!/usr/bin/env bash
set -e
pr=$1
if [ -z "$1" ]
then
echo "PR number needs to be passed"
exit 1
fi
git fetch origin 'refs/tags/*:refs/tags/*' > /dev/null 2>&1
command="git log -3 --pretty=format:"%h" --grep='Merge pull request #${pr}'"
commit=$(eval "$command")
if [[ -z "${commit}" ]]
then
echo "No PR #$pr"
exit 1
fi
echo "PR #$pr with merge commit: $commit"
staging_tags=$(git tag --sort=-version:refname --contains "$commit" "staging*")
if [[ -z "${staging_tags}" ]]
then
echo "Not contained in any staging tag"
exit 0
else
echo "Contained in staging tags:"
echo "$staging_tags"
fi
#!/usr/bin/env bash
set -e
git fetch origin 'refs/tags/*:refs/tags/*' > /dev/null 2>&1
last_staging_tag=$(git tag --sort=-version:refname -l "staging*" | sed -n 1p)
previous_staging_tag=$(git tag --sort=-version:refname -l "staging*" | sed -n 2p)
last_staging_tag_time=$(git log -1 --format=%ai "${last_staging_tag}")
previous_staging_tag_time=$(git log -1 --format=%ai "${previous_staging_tag}")
echo "Merge commits between tags"
echo " - ($last_staging_tag) at [$last_staging_tag_time] <-- last staging tag"
echo " - ($previous_staging_tag) at [$previous_staging_tag_time] <-- prev staging tag"
echo ""
grep_by="Merge pull request"
if [[ $1 == "all" ]]; then
grep_by=""
fi
git log --pretty=oneline --grep="$grep_by" "${last_staging_tag}"..."${previous_staging_tag}" | sed 1d | \
while read -r it
do
echo "$it"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment