Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slackbot: Escape special characters #466

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/slack-bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
summarizer = pipeline('summarization', model='tuner007/pegasus_summarizer')
neutral_summary = summarizer(pr_body, max_length=200, min_length=25, do_sample=False)[0]['summary_text']

# Escape double quotes and backslashes for safe inclusion in environment variables
escaped_summary = neutral_summary.replace('\\', '\\\\').replace('"', '\\"')

# PR label types with associated metadata
pr_label_types = {
'PR: Active': ['Active', 'https://github.com/search?q=org%3Aramp4-pcar4+state%3A%22open%22+type%3A%22pr%22+label%3A%22PR%3A+Active%22&type=pullrequests'],
Expand All @@ -24,18 +27,19 @@
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
# Validate and write all results to the 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')
# Double-check escaped summary
env_file.write(f'NEUTRAL_SUMMARY="{escaped_summary}"\n') # Quotes around the value for safety
env_file.write(f'PR_LABEL_STR="{pr_label_str}"\n') # Ensure consistent escaping
env_file.write(f'REG_LABEL_STR="{reg_label_str}"\n')
Loading