PR Comment System Specification
Overview
The PR Comment System provides functionality for creating comments on GitHub pull requests. It supports both general PR comments and line-specific review comments using the GitHub GraphQL API.
Requirements
Core Functionality
1. General PR Comments
- The system MUST support creating general comments on pull requests
- The system MUST accept the following parameters:
repo_name- Repository name in "owner/repo" formatpr_number- Pull request numbercomment_body- The comment text- The system MUST use the
addCommentGraphQL mutation - The system MUST return the comment URL, ID, and body after creation
2. Line-Specific Review Comments
- The system MUST support creating review comments on specific lines of files
- The system MUST accept the following parameters:
repo_name- Repository name in "owner/repo" formatpr_number- Pull request numberfile_path- Path to the file relative to repository rootline_number- Line number to comment oncomment_body- The comment text- The system MUST use the
addPullRequestReviewThreadGraphQL mutation - The system MUST return the comment URL, ID, body, and state after creation
3. Review Submission
- The system MUST support submitting review comments with a review event
- The system MUST support the following review events:
APPROVE- Submit the review with approvalREQUEST_CHANGES- Submit the review requesting changesCOMMENT- Submit the review as a general comment- The system MUST create a pending review when no event is specified
- The system MUST use the
submitPullRequestReviewmutation to submit reviews - The system MUST retrieve the pending review ID before submitting
4. Authentication
- The system MUST use the shared GitHub GraphQL client for authentication
- The system MUST obtain the GitHub token from the
GITHUB_TOKENenvironment variable or via parameter - The system MUST validate that a token is available before making API calls
Return Values
General Comment Response
Review Comment Response (Pending)
Review Comment Response (Submitted)
{
"html_url": string,
"id": string,
"body": string,
"state": "APPROVED" | "CHANGES_REQUESTED" | "COMMENTED"
}
Error Handling
- The system MUST raise exceptions when GitHub API returns errors
- The system MUST log errors using structlog
- The system MUST include relevant error context (e.g., repository, PR number)
- The system MUST handle missing or invalid repository format gracefully
GraphQL Operations
Query: Get PR Node ID
query($owner: String!, $repo: String!, $prNumber: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $prNumber) {
id
}
}
}
Mutation: Add Pull Request Review Thread
mutation($input: AddPullRequestReviewThreadInput!) {
addPullRequestReviewThread(input: $input) {
thread {
id
comments(first: 1) {
nodes {
id
url
body
}
}
}
}
}
Mutation: Add Comment
mutation($input: AddCommentInput!) {
addComment(input: $input) {
commentEdge {
node {
id
url
body
}
}
}
}
Mutation: Submit Pull Request Review
mutation($input: SubmitPullRequestReviewInput!) {
submitPullRequestReview(input: $input) {
pullRequestReview {
id
url
state
body
}
}
}
Logging
- The system MUST log successful comment creation with
comment_createdevent - The system MUST log successful review creation with
review_createdevent - The system MUST log successful review thread creation with
review_thread_createdevent - The system MUST log errors with
github_api_errorevent - All log entries MUST include relevant context (url, state, error details)