Comment
The Comment resource lets you manage GitHub issue and pull request comments. Comments support full GitHub Markdown and can be updated or deleted as needed.
Minimal Example
Section titled “Minimal Example”Create a comment on an issue:
import { Comment } from "alchemy/github";
const comment = await Comment("issue-comment", { owner: "my-org", repository: "my-repo", issueNumber: 123, body: "This is a comment created by Alchemy!"});
Pull Request Comment
Section titled “Pull Request Comment”Comments work the same way for pull requests:
import { Comment } from "alchemy/github";
const prComment = await Comment("pr-comment", { owner: "my-org", repository: "my-repo", issueNumber: 456, // PR number body: "## Deployment Status\n\n✅ Successfully deployed to staging!"});
Update Comment Content
Section titled “Update Comment Content”Comments can be updated by changing the body content:
import { Comment } from "alchemy/github";
const comment = await Comment("status-comment", { owner: "my-org", repository: "my-repo", issueNumber: 789, body: "🔄 Deployment in progress..."});
// Later, update the commentawait Comment("status-comment", { owner: "my-org", repository: "my-repo", issueNumber: 789, body: "✅ Deployment completed successfully!"});
Allow Comment Deletion
Section titled “Allow Comment Deletion”By default comments are preserved to maintain discussion history, but you can opt-in to deletion:
import { Comment } from "alchemy/github";
const comment = await Comment("temp-comment", { owner: "my-org", repository: "my-repo", issueNumber: 123, body: "This comment can be deleted", allowDelete: true});
Custom Authentication
Section titled “Custom Authentication”Pass a custom GitHub token for authentication:
import { Comment } from "alchemy/github";
const comment = await Comment("authenticated-comment", { owner: "my-org", repository: "my-repo", issueNumber: 123, body: "Comment with custom token", token: alchemy.secret(process.env.CUSTOM_GITHUB_TOKEN)});
Properties
Section titled “Properties”The Comment resource supports the following properties:
Input Properties
Section titled “Input Properties”owner
(string, required): Repository owner (user or organization)repository
(string, required): Repository nameissueNumber
(number, required): Issue or Pull Request number to comment onbody
(string, required): Comment body (supports GitHub Markdown)allowDelete
(boolean, optional): Whether to allow deletion of the comment. Default:false
to preserve discussion historytoken
(Secret, optional): GitHub API token. If not provided, uses environment variablesGITHUB_TOKEN
orGITHUB_ACCESS_TOKEN
Output Properties
Section titled “Output Properties”id
(string): The resource IDcommentId
(number): The numeric ID of the comment in GitHubhtmlUrl
(string): URL to view the commentupdatedAt
(string): Time at which the comment was created/updated- All input properties except
token
Authentication
Section titled “Authentication”Authentication is handled in the following order:
token
parameter in the resource props (if provided)GITHUB_ACCESS_TOKEN
environment variable (for actions with admin permissions)GITHUB_TOKEN
environment variable- GitHub CLI token (if gh is installed and authenticated)
The token must have the following permissions:
- ‘repo’ scope for private repositories
- ‘public_repo’ scope for public repositories