github.com/quay/claircore@v1.5.28/.github/scripts/changelog-edit (about)

     1  #!/bin/sh
     2  set -e
     3  : "${GIT_NOTES_REF:=refs/notes/changelog}"
     4  GIT_NOTES_DISPLAY_REF=$GIT_NOTES_REF
     5  export GIT_NOTES_REF GIT_NOTES_DISPLAY_REF FILTER_BRANCH_SQUELCH_WARNING=1
     6  : "${remote:=$(git remote | grep -q upstream && echo upstream || echo origin)}"
     7  : "${remoteref:=$(dirname "${GIT_NOTES_REF}")/${remote}/$(basename "${GIT_NOTES_REF}")}"
     8  while getopts smh flag; do
     9  	case "$flag" in
    10  		s)
    11  			: sync only
    12  			synconly=1
    13  			;;
    14  		m)
    15  			: menu only
    16  			menuonly=1
    17  			;;
    18  		h|?) printf 'Usage: %s [-s] [-m]\n' "$0" >&2
    19  			printf '  -s\tsync only\n' >&2
    20  			printf '  -m\tmenu only\n' >&2
    21  			exit 2 ;;
    22  	esac
    23  done
    24  
    25  if [ -n "$menuonly" ] && [ -n "$synconly" ]; then
    26  	printf 'mutually exclusive flags\n' >&2
    27  	exit 1
    28  fi
    29  
    30  if [ -z "$menuonly" ]; then
    31  	: fetching and merging from "${remote}"
    32  	git fetch "${remote}"
    33  	: if the next command fails, run the setup script
    34  	git notes merge -s theirs "${remoteref}"
    35  	git update-ref -d "refs/original/${remoteref}" ||:
    36  	(
    37  	cd $(git rev-parse --show-toplevel) &&
    38  	git filter-branch --prune-empty "${GIT_NOTES_REF}"
    39  	)
    40  fi
    41  if [ -z "$synconly" ]; then
    42  	: prompting
    43  	prevtag="$(git tag --sort=-taggerdate --merged | grep '^v' | sed 1q)"
    44  	git log '--format=format:%s' "${prevtag}..." | awk '{print(NR,"\t",$0)}'
    45  	printf '? '
    46  	read -r n
    47  	commit="$(git log '--format=format:%H' "${prevtag}..." | sed -n "${n}p")"
    48  	git notes edit "${commit}"
    49  	git update-ref -d "refs/original/${remoteref}" ||:
    50  	(
    51  	cd $(git rev-parse --show-toplevel) &&
    52  	git filter-branch --prune-empty "${GIT_NOTES_REF}"
    53  	)
    54  fi
    55  if [ -z "$menuonly" ]; then
    56  	: pushing back to "${remote}"
    57  	git push "${remote}" "${GIT_NOTES_REF}"
    58  fi