|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright The Stash Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -eou pipefail |
| 18 | + |
| 19 | +# ref: https://gist.github.com/joshisa/297b0bc1ec0dcdda0d1625029711fa24 |
| 20 | +parse_url() { |
| 21 | + proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')" |
| 22 | + # remove the protocol |
| 23 | + url="$(echo ${1/$proto/})" |
| 24 | + |
| 25 | + IFS='/' # / is set as delimiter |
| 26 | + read -ra PARTS <<<"$url" # str is read into an array as tokens separated by IFS |
| 27 | + if [ ${PARTS[0]} != 'github.com' ] || [ ${#PARTS[@]} -ne 5 ]; then |
| 28 | + echo "failed to parse relase-tracker: $url" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + export RELEASE_TRACKER_OWNER=${PARTS[1]} |
| 32 | + export RELEASE_TRACKER_REPO=${PARTS[2]} |
| 33 | + export RELEASE_TRACKER_PR=${PARTS[4]} |
| 34 | +} |
| 35 | + |
| 36 | +RELEASE_TRACKER= |
| 37 | + |
| 38 | +while IFS=$': \t' read -r -u9 marker v; do |
| 39 | + case $marker in |
| 40 | + Release-tracker) |
| 41 | + export RELEASE_TRACKER=$v |
| 42 | + ;; |
| 43 | + Release) |
| 44 | + export RELEASE=$v |
| 45 | + ;; |
| 46 | + esac |
| 47 | +done 9< <(git show -s --format=%b) |
| 48 | + |
| 49 | +[ ! -z $RELEASE_TRACKER ] || { |
| 50 | + echo "Release-tracker url not found." |
| 51 | + exit 0 |
| 52 | +} |
| 53 | + |
| 54 | +parse_url $RELEASE_TRACKER |
| 55 | +api_url="repos/${RELEASE_TRACKER_OWNER}/${RELEASE_TRACKER_REPO}/issues/${RELEASE_TRACKER_PR}/comments" |
| 56 | + |
| 57 | +case $GITHUB_BASE_REF in |
| 58 | + master) |
| 59 | + msg="/ready-to-tag github.com/${GITHUB_REPOSITORY} ${GITHUB_SHA}" |
| 60 | + ;; |
| 61 | + *) |
| 62 | + msg="/cherry-picked github.com/${GITHUB_REPOSITORY} ${GITHUB_REF} ${GITHUB_SHA}" |
| 63 | + ;; |
| 64 | +esac |
| 65 | + |
| 66 | +hub api "$api_url" -f body="$msg" |
0 commit comments