From efe12640f5c72bcccd7687c11ef62c976bd35979 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Mon, 6 May 2024 17:23:58 -0400 Subject: [PATCH 01/15] change clean_title variable depending on special character in pr_title --- doc-changelog/action.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 9576f006e..3b2d352f5 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -171,8 +171,17 @@ runs: # 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) + # Check for special characters in PR title + if [[ ${{ env.PR_TITLE }} == *'* ]] && [[ ${{ env.PR_TITLE }} == *`* ]]; then + echo "The pull request title cannot contain both a backtick and a single quote" + exit 1 + elif [[ ${{ env.PR_TITLE }} == *[']* ]]; then + # If the title contains a single quote + clean_title=$(echo ${{ env.PR_TITLE }} | xargs -0) + else + # If the title contains a backtick, double quote, or no special character + clean_title=$(echo '${{ env.PR_TITLE }}' | xargs) + fi # Create changelog fragment with towncrier # Fragment file contains the title of the PR From 7686f3a3bce5e67205691965d4730177dd3be471 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 11:52:13 -0400 Subject: [PATCH 02/15] add brackets around first if special chars --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 3b2d352f5..04fb35860 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -172,7 +172,7 @@ runs: fragment="${{ env.PR_NUMBER }}.${{ env.PR_LABEL }}.md" # Check for special characters in PR title - if [[ ${{ env.PR_TITLE }} == *'* ]] && [[ ${{ env.PR_TITLE }} == *`* ]]; then + if [[ ${{ env.PR_TITLE }} == *[']* ]] && [[ ${{ env.PR_TITLE }} == *[`]* ]]; then echo "The pull request title cannot contain both a backtick and a single quote" exit 1 elif [[ ${{ env.PR_TITLE }} == *[']* ]]; then From c1b1b4e4ba38653852771baa00dcaa1a568672c7 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 12:43:14 -0400 Subject: [PATCH 03/15] clean PR title in separate step and save env var --- doc-changelog/action.yml | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 04fb35860..ee1fda8cc 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -160,10 +160,30 @@ runs: rm $file fi + - name: "Clean PR title" + env: + PR_TITLE: ${{ github.event.pull_request.title }} + shell: python + run: | + # Save PR_TITLE to variable + pr_title = ${{ env.PR_TITLE }} + + # Remove extra whitespace + clean_title = " ".join(pr_title.split()) + + # 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: | @@ -171,21 +191,9 @@ runs: # For example, 20.added.md fragment="${{ env.PR_NUMBER }}.${{ env.PR_LABEL }}.md" - # Check for special characters in PR title - if [[ ${{ env.PR_TITLE }} == *[']* ]] && [[ ${{ env.PR_TITLE }} == *[`]* ]]; then - echo "The pull request title cannot contain both a backtick and a single quote" - exit 1 - elif [[ ${{ env.PR_TITLE }} == *[']* ]]; then - # If the title contains a single quote - clean_title=$(echo ${{ env.PR_TITLE }} | xargs -0) - else - # If the title contains a backtick, double quote, or no special character - clean_title=$(echo '${{ env.PR_TITLE }}' | xargs) - fi - # 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' From 847c5b0d519b73a1e34cf19550c2ba31552e7582 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 12:48:15 -0400 Subject: [PATCH 04/15] split pr title env var directly --- doc-changelog/action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index ee1fda8cc..e3f6ec9bc 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -165,11 +165,8 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | - # Save PR_TITLE to variable - pr_title = ${{ env.PR_TITLE }} - # Remove extra whitespace - clean_title = " ".join(pr_title.split()) + clean_title = " ".join(${{ env.PR_TITLE }}.split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From c3b54d66582bb9e56e4be60ea3ab09955f97fe83 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:01:29 -0400 Subject: [PATCH 05/15] change env pr_title to string --- doc-changelog/action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index e3f6ec9bc..1fdad5320 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -165,8 +165,11 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | + # Save PR_TITLE to variable + pr_title = str(${{ env.PR_TITLE }}) + # Remove extra whitespace - clean_title = " ".join(${{ env.PR_TITLE }}.split()) + clean_title = " ".join(pr_title.split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From 2aca8cea00a3ecbf3eb6b9951203aea2735046f0 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:04:34 -0400 Subject: [PATCH 06/15] make it a raw string --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 1fdad5320..d2e30d03b 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -169,7 +169,7 @@ runs: pr_title = str(${{ env.PR_TITLE }}) # Remove extra whitespace - clean_title = " ".join(pr_title.split()) + clean_title = " ".join(fr"{pr_title}".split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From 8a32e265dbe4294b34af1bdb4a941f3c851d9219 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:06:15 -0400 Subject: [PATCH 07/15] use env var --- doc-changelog/action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index d2e30d03b..76602c71e 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -165,11 +165,8 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | - # Save PR_TITLE to variable - pr_title = str(${{ env.PR_TITLE }}) - # Remove extra whitespace - clean_title = " ".join(fr"{pr_title}".split()) + clean_title = " ".join(fr"${{ env.PR_TITLE }}".split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From 0621a5113cdcadf30cc5e35758f5ae545a89cbbd Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:16:23 -0400 Subject: [PATCH 08/15] encode unicode_escape --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 76602c71e..c5016ee11 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -166,7 +166,7 @@ runs: shell: python run: | # Remove extra whitespace - clean_title = " ".join(fr"${{ env.PR_TITLE }}".split()) + clean_title = " ".join(str(${{ env.PR_TITLE }}.encode('unicode_escape')).split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From dc24eff2de988d7e3048c6ba733d7db650f0ff54 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:18:03 -0400 Subject: [PATCH 09/15] use double quotes --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index c5016ee11..866184a69 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -166,7 +166,7 @@ runs: shell: python run: | # Remove extra whitespace - clean_title = " ".join(str(${{ env.PR_TITLE }}.encode('unicode_escape')).split()) + clean_title = " ".join(str(${{ env.PR_TITLE }}.encode("unicode_escape")).split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From 2980fae9b6741c36506db6a18f0e0a3eae89832c Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:26:18 -0400 Subject: [PATCH 10/15] replace single quote with 2 --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 866184a69..d4af754c9 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -166,7 +166,7 @@ runs: shell: python run: | # Remove extra whitespace - clean_title = " ".join(str(${{ env.PR_TITLE }}.encode("unicode_escape")).split()) + clean_title = " ".join(${{ env.PR_TITLE }}.replace("'", "''").split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From c9dbdb6f5cb185b9169e4ded2855cd6f888b10fb Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:27:33 -0400 Subject: [PATCH 11/15] replace with backslash single quote --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index d4af754c9..7e394c83c 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -166,7 +166,7 @@ runs: shell: python run: | # Remove extra whitespace - clean_title = " ".join(${{ env.PR_TITLE }}.replace("'", "''").split()) + clean_title = " ".join(${{ env.PR_TITLE }}.replace("'", "\'").split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From 5b96644ee2c6cb289b3bc30f0bd3075ab4333879 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:30:39 -0400 Subject: [PATCH 12/15] try replace --- doc-changelog/action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 7e394c83c..5d0ad9e3a 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -165,8 +165,11 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | + # Save PR_TITLE to variable + pr_title = str(${{ env.PR_TITLE }}.replace(":", "\:").replace("'", "\'")) + # Remove extra whitespace - clean_title = " ".join(${{ env.PR_TITLE }}.replace("'", "\'").split()) + clean_title = " ".join(fr"{pr_title}".split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From edbfee049e4f78f6c6ee9378e6c81c7983afd045 Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:55:19 -0400 Subject: [PATCH 13/15] triple quotes around env var --- doc-changelog/action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 5d0ad9e3a..ef24e2b15 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -165,11 +165,8 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | - # Save PR_TITLE to variable - pr_title = str(${{ env.PR_TITLE }}.replace(":", "\:").replace("'", "\'")) - # Remove extra whitespace - clean_title = " ".join(fr"{pr_title}".split()) + clean_title = " ".join("""${{ env.PR_TITLE }}""".split()) # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"') From 5c3686a32c90f489d6b8f71f5822edea6acddb0e Mon Sep 17 00:00:00 2001 From: klmcadams Date: Tue, 7 May 2024 13:56:13 -0400 Subject: [PATCH 14/15] import os --- doc-changelog/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index ef24e2b15..0630c99b4 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -165,6 +165,8 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | + import os + # Remove extra whitespace clean_title = " ".join("""${{ env.PR_TITLE }}""".split()) From 0971f08178870f8e10e8cdc56fb9502500a5c5ac Mon Sep 17 00:00:00 2001 From: Kerry McAdams <58492561+klmcadams@users.noreply.github.com> Date: Wed, 8 May 2024 08:45:25 -0400 Subject: [PATCH 15/15] use strip instead of join Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- doc-changelog/action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 0630c99b4..026a47bc0 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -167,8 +167,11 @@ runs: run: | import os + # Retrieve title + clean_title = os.getenv('PR_TITLE') + # Remove extra whitespace - clean_title = " ".join("""${{ env.PR_TITLE }}""".split()) + clean_title = clean_title.strip() # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\`").replace('"', '\\"')