Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.
TypeScript
fix(ci): stop the auto-titler downgrading a release
Lewis Carhart8a1e3901ec5e
diff --git a/.github/scripts/pr-title.sh b/.github/scripts/pr-title.shindex 347cc3a2..020b5ea4 100755--- a/.github/scripts/pr-title.sh+++ b/.github/scripts/pr-title.sh@@ -15,6 +15,59 @@ check() {return 0}+bump_of() {+ local title=${1-} head type+ head=${title%%:*}+ case "$head" in *'!') printf '3'; return ;; esac+ type=${head%%(*}+ case "$type" in+ feat) printf '2' ;;+ fix | perf | revert) printf '1' ;;+ *) printf '0' ;;+ esac+}++floor_of() {+ local base=$1 head=$2 subject best=0 bump+ if git log "$base..$head" --no-merges --format=%B | grep -q '^BREAKING[ -]CHANGE'; then+ printf '3'+ return+ fi+ while IFS= read -r subject; do+ bump=$(bump_of "$subject")+ [ "$bump" -gt "$best" ] && best=$bump+ done < <(git log "$base..$head" --no-merges --format=%s)+ printf '%s' "$best"+}++retype() {+ local title=$1 want=$2 head scope rest+ rest=${title#*: }+ head=${title%%:*}+ scope=''+ case "$head" in *'('*')'*) scope=$(printf '%s' "$head" | sed -e 's/^[^(]*(//' -e 's/).*$//') ;; esac++ case "$want" in+ 3) head='feat!' ;;+ 2) head='feat' ;;+ *) printf '%s' "$title"; return ;;+ esac++ if [ -n "$scope" ]; then+ case "$want" in+ 3) printf 'feat(%s)!: %s' "$scope" "$rest" ;;+ *) printf 'feat(%s): %s' "$scope" "$rest" ;;+ esac+ else+ printf '%s: %s' "$head" "$rest"+ fi+}++sufficient() {+ local base=$1 head=$2 title=$3+ [ "$(bump_of "$title")" -ge "$(floor_of "$base" "$head")" ]+}+scope_for() {local files=$1 scopesscopes=$(printf '%s\n' "$files" | sed -n \@@ -96,6 +149,14 @@ Reply with the title on one line and nothing else." \}generate() {+ local base=$1 head=$2 branch=${3-} floor+ floor=$(floor_of "$base" "$head")++ retype "$(propose "$base" "$head" "$branch")" "$floor"+ printf '\n'+}++propose() {local base=$1 head=$2 branch=${3-} files scope subject conventional titlefiles=$(git diff --name-only "$base..$head")@@ -137,8 +198,9 @@ generate() {case "${1-}" incheck) check "${2-}" ;;generate) generate "${2:?base ref}" "${3:?head ref}" "${4-}" ;;+sufficient) sufficient "${2:?base ref}" "${3:?head ref}" "${4-}" ;;*)- echo "usage: pr-title.sh check <title> | pr-title.sh generate <base> <head> [branch]" >&2+ echo "usage: pr-title.sh check <title> | pr-title.sh generate <base> <head> [branch] | pr-title.sh sufficient <base> <head> <title>" >&2exit 2;;esacdiff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.ymlindex df8fb7e1..023627be 100644--- a/.github/workflows/pr-title.yml+++ b/.github/workflows/pr-title.yml@@ -31,7 +31,6 @@ jobs:env:GH_TOKEN: ${{ secrets.AUTOMATION_TOKEN || secrets.GITHUB_TOKEN }}ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}- ACTION: ${{ github.event.action }}TITLE: ${{ github.event.pull_request.title }}BODY: ${{ github.event.pull_request.body }}NUMBER: ${{ github.event.pull_request.number }}@@ -42,14 +41,13 @@ jobs:set -euo pipefailbody=$(printf '%s' "$BODY" | tr -d '\r')- written=$(printf '%s\n' "$body" | sed -n 's/^<!-- pr-title: \(.*\) -->$/\1/p' | head -1)if ! .github/scripts/pr-title.sh check "$TITLE"; thenreason="it is not a release note"- elif [ "$ACTION" != "edited" ] && [ -n "$written" ] && [ "$written" = "$TITLE" ]; then- reason="the diff has moved and nobody has retitled it"+ elif ! .github/scripts/pr-title.sh sufficient "$BASE_SHA" "$HEAD_SHA" "$TITLE"; then+ reason="it releases less than the commits on the branch do"else- echo "\`$TITLE\` is yours — leaving it alone." >> "$GITHUB_STEP_SUMMARY"+ echo "\`$TITLE\` still covers the diff — leaving it alone." >> "$GITHUB_STEP_SUMMARY"exit 0fi