feat(release-notes-assistant): if no labels, fallback to prefix
* support feat: fix: feat!: fix! conventional commits prefixes * add unit tests
This commit is contained in:
		
					parent
					
						
							
								14d079a1eb
							
						
					
				
			
			
				commit
				
					
						db64236f85
					
				
			
		
					 3 changed files with 227 additions and 54 deletions
				
			
		| 
						 | 
					@ -19,6 +19,7 @@ jobs:
 | 
				
			||||||
      - uses: https://code.forgejo.org/actions/setup-go@v4
 | 
					      - uses: https://code.forgejo.org/actions/setup-go@v4
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          go-version-file: "go.mod"
 | 
					          go-version-file: "go.mod"
 | 
				
			||||||
 | 
					          cache: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: apt install jq
 | 
					      - name: apt install jq
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,6 +75,10 @@ jobs:
 | 
				
			||||||
          apt-get -q install -qq -y git
 | 
					          apt-get -q install -qq -y git
 | 
				
			||||||
          rm /etc/apt/sources.list.d/testing.list
 | 
					          rm /etc/apt/sources.list.d/testing.list
 | 
				
			||||||
          apt-get update -qq
 | 
					          apt-get update -qq
 | 
				
			||||||
 | 
					      - name: test release-notes-assistant.sh
 | 
				
			||||||
 | 
					        run: |
 | 
				
			||||||
 | 
					          apt-get -q install -qq -y jq
 | 
				
			||||||
 | 
					          ./release-notes-assistant.sh test_main
 | 
				
			||||||
      - run: |
 | 
					      - run: |
 | 
				
			||||||
          su forgejo -c 'make deps-backend'
 | 
					          su forgejo -c 'make deps-backend'
 | 
				
			||||||
      - run: |
 | 
					      - run: |
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,72 +2,240 @@
 | 
				
			||||||
# Copyright twenty-panda <twenty-panda@posteo.com>
 | 
					# Copyright twenty-panda <twenty-panda@posteo.com>
 | 
				
			||||||
# SPDX-License-Identifier: MIT
 | 
					# SPDX-License-Identifier: MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					label_worth=worth
 | 
				
			||||||
 | 
					label_bug=bug
 | 
				
			||||||
 | 
					label_feature=feature
 | 
				
			||||||
 | 
					label_ui=forgejo/ui
 | 
				
			||||||
 | 
					label_breaking=breaking
 | 
				
			||||||
 | 
					
 | 
				
			||||||
payload=$(mktemp)
 | 
					payload=$(mktemp)
 | 
				
			||||||
pr=$(mktemp)
 | 
					pr=$(mktemp)
 | 
				
			||||||
trap "rm $payload $pr" EXIT
 | 
					trap "rm $payload $pr" EXIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cat >$payload
 | 
					function test_main() {
 | 
				
			||||||
#
 | 
					  set -ex
 | 
				
			||||||
# If this is a backport, refer to the original PR to figure
 | 
					  PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}:  '
 | 
				
			||||||
# out the classification.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
if $(jq --raw-output .IsBackportedFrom <$payload); then
 | 
					 | 
				
			||||||
  jq --raw-output '.BackportedFrom[0]' <$payload >$pr
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
  jq --raw-output '.Pr' <$payload >$pr
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
labels=$(jq --raw-output '.labels[].name' <$pr)
 | 
					  test_payload_labels $label_worth $label_breaking $label_feature
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'AA Breaking features'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					  test_payload_labels $label_worth $label_breaking $label_bug
 | 
				
			||||||
# Was this PR labeled `worth a release note`?
 | 
					  test "$(categorize)" = 'AB Breaking bug fixes'
 | 
				
			||||||
#
 | 
					 | 
				
			||||||
if echo "$labels" | grep --quiet worth; then
 | 
					 | 
				
			||||||
  worth=true
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
  worth=false
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					  test_payload_labels $label_worth $label_breaking
 | 
				
			||||||
# If there was no release-notes/N.md file and it is not
 | 
					  test "$(categorize)" = 'ZC Breaking changes without a feature or bug label'
 | 
				
			||||||
# worth a release note, just forget about it.
 | 
					
 | 
				
			||||||
#
 | 
					  test_payload_labels $label_worth $label_ui $label_feature
 | 
				
			||||||
if test -z "$(jq --raw-output .Draft <$payload)"; then
 | 
					  test "$(categorize)" = 'BA User Interface features'
 | 
				
			||||||
  if ! $worth; then
 | 
					
 | 
				
			||||||
    echo -n ZA Included for completness but not worth a release note
 | 
					  test_payload_labels $label_worth $label_ui $label_bug
 | 
				
			||||||
    exit 0
 | 
					  test "$(categorize)" = 'BB User Interface bug fixes'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_labels $label_worth $label_ui
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'ZD User Interface changes without a feature or bug label'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_labels $label_worth $label_feature
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'CA Features'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_labels $label_worth $label_bug
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'CB Bug fixes'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_labels $label_worth
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'ZE Other changes without a feature or bug label'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_labels
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'ZF Included for completness but not worth a release note'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_draft "feat!: breaking feature"
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'AA Breaking features'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_draft "fix!: breaking bug fix"
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'AB Breaking bug fixes'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_draft "feat: feature"
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'CA Features'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_draft "fix: bug fix"
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'CB Bug fixes'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test_payload_draft "something with no prefix"
 | 
				
			||||||
 | 
					  test "$(categorize)" = 'ZE Other changes without a feature or bug label'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function main() {
 | 
				
			||||||
 | 
					  cat >$payload
 | 
				
			||||||
 | 
					  categorize
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function categorize() {
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
 | 
					  # If this is a backport, refer to the original PR to figure
 | 
				
			||||||
 | 
					  # out the classification.
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
 | 
					  if $(jq --raw-output .IsBackportedFrom <$payload); then
 | 
				
			||||||
 | 
					    jq --raw-output '.BackportedFrom[0]' <$payload >$pr
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    jq --raw-output '.Pr' <$payload >$pr
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
case "$labels" in
 | 
					  labels=$(jq --raw-output '.labels[].name' <$pr)
 | 
				
			||||||
*bug*)
 | 
					
 | 
				
			||||||
  if $(jq --raw-output .IsBackportedTo <$payload); then
 | 
					  #
 | 
				
			||||||
    #
 | 
					  # Was this PR labeled `worth a release note`?
 | 
				
			||||||
    # if it has been backported, it was in the release notes of an older stable release
 | 
					  #
 | 
				
			||||||
    # and does not need to be in this more recent release notes
 | 
					  if echo "$labels" | grep --quiet $label_worth; then
 | 
				
			||||||
    #
 | 
					    worth=true
 | 
				
			||||||
    echo -n ZB Already announced in the release notes of an older stable release
 | 
					  else
 | 
				
			||||||
    exit 0
 | 
					    worth=false
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
  ;;
 | 
					 | 
				
			||||||
esac
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
case "$labels" in
 | 
					  #
 | 
				
			||||||
*breaking*)
 | 
					  # If there was no release-notes/N.md file and it is not
 | 
				
			||||||
 | 
					  # worth a release note, just forget about it.
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
 | 
					  if test -z "$(jq --raw-output .Draft <$payload)"; then
 | 
				
			||||||
 | 
					    if ! $worth; then
 | 
				
			||||||
 | 
					      echo -n ZF Included for completness but not worth a release note
 | 
				
			||||||
 | 
					      exit 0
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  is_ui=false
 | 
				
			||||||
 | 
					  is_bug=false
 | 
				
			||||||
 | 
					  is_feature=false
 | 
				
			||||||
 | 
					  is_breaking=false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
 | 
					  # first try to figure out the category from the labels
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
  case "$labels" in
 | 
					  case "$labels" in
 | 
				
			||||||
  *feature*) echo -n AA Breaking features ;;
 | 
					  *$label_bug*)
 | 
				
			||||||
  *bug*) echo -n AB Breaking bug fixes ;;
 | 
					    is_bug=true
 | 
				
			||||||
  *) echo -n ZC Breaking changes without a feature or bug label ;;
 | 
					    ;;
 | 
				
			||||||
 | 
					  *$label_feature*)
 | 
				
			||||||
 | 
					    is_feature=true
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
  esac
 | 
					  esac
 | 
				
			||||||
  ;;
 | 
					
 | 
				
			||||||
*forgejo/ui*)
 | 
					 | 
				
			||||||
  case "$labels" in
 | 
					  case "$labels" in
 | 
				
			||||||
  *feature*) echo -n BA User Interface features ;;
 | 
					  *$label_breaking*)
 | 
				
			||||||
  *bug*) echo -n BB User Interface bug fixes ;;
 | 
					    is_breaking=true
 | 
				
			||||||
  *) echo -n ZD User Interface changes without a feature or bug label ;;
 | 
					    ;;
 | 
				
			||||||
  esac
 | 
					  esac
 | 
				
			||||||
  ;;
 | 
					
 | 
				
			||||||
*feature*) echo -n CA Features ;;
 | 
					  case "$labels" in
 | 
				
			||||||
*bug*) echo -n CB Bug fixes ;;
 | 
					  *$label_ui*)
 | 
				
			||||||
*) echo -n ZE Other changes without a feature or bug label ;;
 | 
					    is_ui=true
 | 
				
			||||||
esac
 | 
					    ;;
 | 
				
			||||||
 | 
					  esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
 | 
					  # then try the prefix of the release note
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
 | 
					  if ! $is_bug && ! $is_feature; then
 | 
				
			||||||
 | 
					    draft="$(jq --raw-output .Draft <$payload)"
 | 
				
			||||||
 | 
					    case "$draft" in
 | 
				
			||||||
 | 
					    fix!:*)
 | 
				
			||||||
 | 
					      is_bug=true
 | 
				
			||||||
 | 
					      is_breaking=true
 | 
				
			||||||
 | 
					      ;;
 | 
				
			||||||
 | 
					    fix:*)
 | 
				
			||||||
 | 
					      is_bug=true
 | 
				
			||||||
 | 
					      ;;
 | 
				
			||||||
 | 
					    feat!:*)
 | 
				
			||||||
 | 
					      is_feature=true
 | 
				
			||||||
 | 
					      is_breaking=true
 | 
				
			||||||
 | 
					      ;;
 | 
				
			||||||
 | 
					    feat:*)
 | 
				
			||||||
 | 
					      is_feature=true
 | 
				
			||||||
 | 
					      ;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if $is_bug; then
 | 
				
			||||||
 | 
					    if $(jq --raw-output .IsBackportedTo <$payload); then
 | 
				
			||||||
 | 
					      #
 | 
				
			||||||
 | 
					      # if it has been backported, it was in the release notes of an older stable release
 | 
				
			||||||
 | 
					      # and does not need to be in this more recent release notes
 | 
				
			||||||
 | 
					      #
 | 
				
			||||||
 | 
					      echo -n ZG Already announced in the release notes of an older stable release
 | 
				
			||||||
 | 
					      exit 0
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if $is_breaking; then
 | 
				
			||||||
 | 
					    if $is_feature; then
 | 
				
			||||||
 | 
					      echo -n AA Breaking features
 | 
				
			||||||
 | 
					    elif $is_bug; then
 | 
				
			||||||
 | 
					      echo AB Breaking bug fixes
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      echo -n ZC Breaking changes without a feature or bug label
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  elif $is_ui; then
 | 
				
			||||||
 | 
					    if $is_feature; then
 | 
				
			||||||
 | 
					      echo -n BA User Interface features
 | 
				
			||||||
 | 
					    elif $is_bug; then
 | 
				
			||||||
 | 
					      echo -n BB User Interface bug fixes
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      echo -n ZD User Interface changes without a feature or bug label
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    if $is_feature; then
 | 
				
			||||||
 | 
					      echo -n CA Features
 | 
				
			||||||
 | 
					    elif $is_bug; then
 | 
				
			||||||
 | 
					      echo -n CB Bug fixes
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      echo -n ZE Other changes without a feature or bug label
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function test_payload_labels() {
 | 
				
			||||||
 | 
					  local label1="$1"
 | 
				
			||||||
 | 
					  local label2="$2"
 | 
				
			||||||
 | 
					  local label3="$3"
 | 
				
			||||||
 | 
					  local label4="$4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cat >$payload <<EOF
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "Pr": {
 | 
				
			||||||
 | 
					    "labels": [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "$label1"
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "$label2"
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "$label3"
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "$label4"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "IsBackportedFrom": false,
 | 
				
			||||||
 | 
					  "Draft": ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function test_payload_draft() {
 | 
				
			||||||
 | 
					  local draft="$1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cat >$payload <<EOF
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "Pr": {
 | 
				
			||||||
 | 
					    "labels": [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "$label_worth"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "IsBackportedFrom": false,
 | 
				
			||||||
 | 
					  "Draft": "$draft"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"${@:-main}"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue