Skip to content

Commit

Permalink
fix: allow backtick, single, and double quotes for PR titles in the d…
Browse files Browse the repository at this point in the history
…oc-changelog action (#484)

Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com>
  • Loading branch information
klmcadams and RobPasMue authored May 8, 2024
1 parent cd8e715 commit ab84a38
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions doc-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,42 @@ runs:
rm $file
fi
- name: "Clean PR title"
env:
PR_TITLE: ${{ github.event.pull_request.title }}
shell: python
run: |
import os
# Retrieve title
clean_title = os.getenv('PR_TITLE')
# Remove extra whitespace
clean_title = clean_title.strip()
# Add backslash in front of backtick and double quote
clean_title = clean_title.replace("`", "\`").replace('"', '\\"')
# Get the GITHUB_ENV variable
github_env = os.getenv('GITHUB_ENV')
# Append the CLEAN_TITLE with its value to GITHUB_ENV
with open(github_env, "a") as f:
f.write(f"CLEAN_TITLE={clean_title}")
- name: "Create and commit towncrier fragment"
env:
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
PR_TITLE: '${{ github.event.pull_request.title }}'
PR_NUMBER: ${{ github.event.number }}
shell: bash
run: |
# Changelog fragment file in the following format
# For example, 20.added.md
fragment="${{ env.PR_NUMBER }}.${{ env.PR_LABEL }}.md"
# Remove extra whitespace from PR title
clean_title=$(echo '${{ env.PR_TITLE }}' | xargs)
# Create changelog fragment with towncrier
# Fragment file contains the title of the PR
towncrier create -c "$clean_title" $fragment
towncrier create -c "${{ env.CLEAN_TITLE }}" $fragment
# Configure git username & email
git config user.name 'pyansys-ci-bot'
Expand Down

0 comments on commit ab84a38

Please sign in to comment.