From 6c0f3442cce0e186cd6eab73f1acf36e3e713582 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Tue, 7 Mar 2023 09:40:26 +0200 Subject: [PATCH] Tools: add tool to determine which release (if any) a commit appears in (#8706) I've often found myself needing to determine which release a particular PR appears in. This tool makes that easy, and it accepts the merge commit ref of the PR. Example from https://github.com/grafana/loki/pull/7044, in which [a user is asking which version this feature appears in](https://github.com/grafana/loki/pull/7044#issuecomment-1455694087). ```bash $ ./tools/which-release.sh 93a5a71 Commit was found in the following releases: release-2.7.x ``` --- tools/which-release.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 tools/which-release.sh diff --git a/tools/which-release.sh b/tools/which-release.sh new file mode 100755 index 0000000000..7493b8ec80 --- /dev/null +++ b/tools/which-release.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +COMMIT=$1 +if [[ -z "${COMMIT}" ]]; then + echo "Usage: $0 " + exit 2 +fi + +REMOTE=$(git remote -v | grep grafana/loki | awk '{print $1}' | head -n1) +if [[ -z "${REMOTE}" ]]; then + echo "Could not find remote for grafana/loki" + exit 1 +fi + +echo "It is recommended that you run \`git fetch -ap ${REMOTE}\` to ensure you get a correct result." + +RELEASES=$(git branch -r --contains "${COMMIT}" | grep "${REMOTE}" | grep "/release-" | sed "s|${REMOTE}/||") +if [[ -z "${RELEASES}" ]]; then + echo "Commit was not found in any release" + exit 1 +fi + + +echo "Commit was found in the following releases:" +echo "${RELEASES}"