Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Jan 19, 2025
1 parent f31c682 commit e73d500
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/scripts/prepare-new-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
#
# This script uses chloggen file to get the change_type and add it as a label to the PR.
# This script uses chloggen file to get the change_type and adds it as a label to the PR.
# If there are none or multiple changelog files, it will ignore the PR.
#
# Notes:
# - label should exist in the repository in order to add it to the PR.
# - if label already exist, this is a no-op.
# - if any error happens, the script quietly exits with 0.

if [ -z ${PR:-} ]; then
echo "PR number is required"
exit 1
fi

CHLOG="$(gh pr view $PR --json files --jq '.files.[].path | select (. | startswith(".chloggen/"))')"
echo "Change log file: ${CHLOG}"
echo "Change log file(s): ${CHLOG}"

COUNT="$(echo "$CHLOG" | wc -l)"
if [ -z "$CHLOG" ]; then
echo "No changelog found in the PR. Ignoring this change."
exit 0
fi

COUNT="$(echo "$CHLOG" | wc -l)"
if [ $COUNT -eq 1 ]; then
CHANGE_TYPE=$(awk -F': ' '/^change_type:/ {print $2}' $CHLOG | xargs)
echo $CHANGE_TYPE
gh pr edit "${PR}" --add-label "${CHANGE_TYPE}" || true
else
echo "Found multiple changelogs= files - $CHLOG. Ignoring this change."
echo "Found multiple changelog files - $CHLOG. Ignoring this change."
fi

exit 0

0 comments on commit e73d500

Please sign in to comment.