Implementation:0xSteph Pentest ai post pr comment
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, CI_CD |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Concrete async function that posts a CI gate report as a PR comment via the GitHub API, reading repo, PR number, and token from environment variables.
Description
post_pr_comment posts the markdown-rendered CI report as a comment on a GitHub pull request. It reads:
- repo: From `GITHUB_REPOSITORY` env (or parameter)
- pr_number: From `GITHUB_REF` env (parses `/pull/N` pattern) or parameter
- token: From `GITHUB_TOKEN` env (or parameter)
Returns True on success (HTTP 2xx), False if any required input is missing. Uses httpx as the HTTP client.
Usage
Import this when you need to:
- Post security results as PR comments in GitHub Actions
- Notify developers of security gate results inline in PRs
Code Reference
Source Location
- Repository: pentest-ai
- File: cli/ci.py
Signature
async def post_pr_comment(
report: CIReport,
*,
repo: str | None = None,
pr_number: int | None = None,
token: str | None = None,
client: httpx.AsyncClient | None = None,
) -> bool:
"""Post the markdown report as a PR comment. Returns True on success."""
Import
from cli.ci import post_pr_comment
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| report | CIReport | Yes | The CI gate report to post |
| repo | None | No | GitHub repo (default: GITHUB_REPOSITORY env) |
| pr_number | None | No | PR number (default: parsed from GITHUB_REF) |
| token | None | No | GitHub token (default: GITHUB_TOKEN env) |
| client | None | No | Optional pre-configured client |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | bool | True on success (HTTP 2xx), False if inputs missing or request failed |
Usage Examples
Posting a PR Comment in GitHub Actions
import asyncio
from cli.ci import build_report, render_markdown, post_pr_comment
async def main():
report = build_report(engagement, findings, threshold="high")
success = await post_pr_comment(report)
if success:
print("PR comment posted")
else:
print("Could not post PR comment (missing repo/pr/token?)")
asyncio.run(main())
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment