Skip to content
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def add_pr_comments() -> int:
print(f"Creating a new comment on PR #{pr_number}.")
pull_request.create_comment(body=pr_comments)

# output pr_comments to GitHub Actions
print(f"::set-output name=pr_comments::{pr_comments}")

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace deprecated ::set-output with GITHUB_OUTPUT and handle multiline safely

GitHub deprecated ::set-output. Use the GITHUB_OUTPUT environment file to set step outputs. This also handles multiline values (your pr_comments includes code fences and newlines) without brittle escaping.

Apply this diff:

-        # output pr_comments to GitHub Actions
-        print(f"::set-output name=pr_comments::{pr_comments}")
+        # Output pr_comments to GitHub Actions using the env file (set-output is deprecated)
+        gh_output = os.getenv("GITHUB_OUTPUT")
+        if gh_output:
+            with open(gh_output, "a") as gh_out:
+                delimiter = "PR_COMMENTS_EOF"
+                gh_out.write(f"pr_comments<<{delimiter}\n{pr_comments}\n{delimiter}\n")
+        else:
+            # Fallback for local runs where GITHUB_OUTPUT is unset
+            print(f"pr_comments:\n{pr_comments}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# output pr_comments to GitHub Actions
print(f"::set-output name=pr_comments::{pr_comments}")
# Output pr_comments to GitHub Actions using the env file (set-output is deprecated)
gh_output = os.getenv("GITHUB_OUTPUT")
if gh_output:
with open(gh_output, "a") as gh_out:
delimiter = "PR_COMMENTS_EOF"
gh_out.write(f"pr_comments<<{delimiter}\n{pr_comments}\n{delimiter}\n")
else:
# Fallback for local runs where GITHUB_OUTPUT is unset
print(f"pr_comments:\n{pr_comments}")
🤖 Prompt for AI Agents
In main.py around lines 171 to 173, replace the deprecated GitHub Actions
"::set-output" print with writing to the GITHUB_OUTPUT environment file to
safely handle multiline pr_comments: import os if not already, get the output
path via os.environ["GITHUB_OUTPUT"], and append a heredoc-style entry for
pr_comments (for example: write 'pr_comments<<EOF\n' + pr_comments + '\nEOF\n')
to that file so multiline content and code fences are preserved; ensure the
write uses text mode and handle KeyError with a clear fallback or raise if
GITHUB_OUTPUT is missing.

Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code assumes GITHUB_OUTPUT environment variable exists without checking. This could raise a KeyError if the environment variable is not set. Consider using os.environ.get("GITHUB_OUTPUT") with appropriate error handling.

Suggested change
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output is None:
raise EnvironmentError("GITHUB_OUTPUT environment variable is not set")
with open(github_output, "a", encoding="utf-8") as output_file:
output_file.write(f"pr_comments={pr_comments}\n")

Copilot uses AI. Check for mistakes.

return 0 if result_text is None else 1
except Exception as e:
print(f"Error posting PR comment: {e}", file=sys.stderr)
Expand Down
Loading