Skip to content

Commit

Permalink
Merge pull request #468 from gordlin/slackbot-escape-quotes
Browse files Browse the repository at this point in the history
Slackbot: Escape special characters
  • Loading branch information
gordlin authored Nov 28, 2024
2 parents 6ab1b8b + 5992d17 commit a62ba05
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions .github/slack-bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
f"<{pr_label_types[label['name']][1]}|{pr_label_types[label['name']][0]}>"
for label in pr_labels if pr_label_types.get(label['name'])
)
if (len(pr_label_str) == 0):
if len(pr_label_str) == 0:
pr_label_str = "None"

# Handle regular labels (not in pr_label_types)
reg_label_str = ", ".join(
label['name'] for label in pr_labels if pr_label_types.get(label['name']) is None
)
if (len(reg_label_str) == 0):
if len(reg_label_str) == 0:
reg_label_str = "None"

# Write all results to environment
# Escape using json.dumps for JSON compatibility
escaped_summary = json.dumps(neutral_summary)[1:-1] # Removes surrounding quotes added by json.dumps
pr_label_str = json.dumps(pr_label_str)[1:-1]
reg_label_str = json.dumps(reg_label_str)[1:-1]

# Write all results to environment
with open(os.environ['GITHUB_ENV'], 'a') as env_file:
env_file.write(f'NEUTRAL_SUMMARY={neutral_summary}\n')
env_file.write(f'PR_LABEL_STR={pr_label_str}\n')
env_file.write(f'REG_LABEL_STR={reg_label_str}\n')
env_file.write(f'NEUTRAL_SUMMARY="{escaped_summary}"\n')
env_file.write(f'PR_LABEL_STR="{pr_label_str}"\n')
env_file.write(f'REG_LABEL_STR="{reg_label_str}"\n')

0 comments on commit a62ba05

Please sign in to comment.