8000 feat(github): add GitHub Comment resource for issue and PR comments (… · sam-goodwin/alchemy@a4a8218 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit a4a8218

Browse files
authored
feat(github): add GitHub Comment resource for issue and PR comments (#365)
1 parent 3768a37 commit a4a8218

File tree

7 files changed

+816
-21
lines changed

7 files changed

+816
-21
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: GitHub Comment
3+
description: Learn how to create, update, and manage comments on GitHub issues and pull requests using Alchemy.
4+
---
5+
6+
# Comment
7+
8+
The Comment resource lets you manage [GitHub issue and pull request comments](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/commenting-on-an-issue). Comments support full GitHub Markdown and can be updated or deleted as needed.
9+
10+
## Minimal Example
11+
12+
Create a comment on an issue:
13+
14+
```ts
15+
import { Comment } from "alchemy/github";
16+
17+
const comment = await Comment("issue-comment", {
18+
owner: "my-org",
19+
repository: "my-repo",
20+
issueNumber: 123,
21+
body: "This is a comment created by Alchemy!"
22+
});
23+
```
24+
25+
## Pull Request Comment
26+
27+
Comments work the same way for pull requests:
28+
29+
```ts
30+
import { Comment } from "alchemy/github";
31+
32+
const prComment = await Comment("pr-comment", {
33+
owner: "my-org",
34+
repository: "my-repo",
35+
issueNumber: 456, // PR number
36+
body: "## Deployment Status\n\n✅ Successfully deployed to staging!"
37+
});
38+
```
39+
40+
## Update Comment Content
41+
42+
Comments can be updated by changing the body content:
43+
44+
```ts
45+
import { Comment } from "alchemy/github";
46+
47+
const comment = await Comment("status-comment", {
48+
owner: "my-org",
49+
repository: "my-repo",
50+
issueNumber: 789,
51+
body: "🔄 Deployment in progress..."
52+
});
53+
54+
// Later, update the comment
55+
await Comment("status-comment", {
56+
owner: "my-org",
57+
repository: "my-repo",
58+
issueNumber: 789,
59+
body: "✅ Deployment completed successfully!"
60+
});
61+
```
62+
63+
## Allow Comment Deletion
64+
65+
By default comments are preserved to maintain discussion history, but you can opt-in to deletion:
66+
67+
```ts
68+
import { Comment } from "alchemy/github";
69+
70+
const comment = await Comment("temp-comment", {
71+
owner: "my-org",
72+
repository: "my-repo",
73+
issueNumber: 123,
74+
body: "This comment can be deleted",
75+
allowDelete: true
76+
});
77+
```
78+
79+
## Custom Authentication
80+
81+
Pass a custom GitHub token for authentication:
82+
83+
```ts
84+
import { Comment } from "alchemy/github";
85+
86+
const comment = await Comment("authenticated-comment", {
87+
owner: "my-org",
88+
repository: "my-repo",
89+
issueNumber: 123,
90+
body: "Comment with custom token",
91+
token: alchemy.secret(process.env.CUSTOM_GITHUB_TOKEN)
92+
});
93+
```
94+
95+
## Properties
96+
97+
The Comment resource supports the following properties:
98+
99+
### Input Properties
100+
101+
- `owner` (string, required): Repository owner (user or organization)
102+
- `repository` (string, required): Repository B421 name
103+
- `issueNumber` (number, required): Issue or Pull Request number to comment on
104+
- `body` (string, required): Comment body (supports GitHub Markdown)
105+
- `allowDelete` (boolean, optional): Whether to allow deletion of the comment. Default: `false` to preserve discussion history
106+
- `token` (Secret, optional): GitHub API token. If not provided, uses environment variables `GITHUB_TOKEN` or `GITHUB_ACCESS_TOKEN`
107+
108+
### Output Properties
109+
110+
- `id` (string): The resource ID
111+
- `commentId` (number): The numeric ID of the comment in GitHub
112+
- `htmlUrl` (string): URL to view the comment
113+
- `updatedAt` (string): Time at which the comment was created/updated
114+
- All input properties except `token`
115+
116+
## Authentication
117+
118+
Authentication is handled in the following order:
119+
120+
1. `token` parameter in the resource props (if provided)
121+
2. `GITHUB_ACCESS_TOKEN` environment variable (for actions with admin permissions)
122+
3. `GITHUB_TOKEN` environment variable
123+
4. GitHub CLI token (if gh is installed and authenticated)
124+
125+
The token must have the following permissions:
126+
- 'repo' scope for private repositories
127+
- 'public_repo' scope for public repositories
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# GitHub
2+
3+
GitHub is a web-based version control and collaboration platform that provides Git repository hosting, issue tracking, project management, and CI/CD workflows. Alchemy provides resources to manage GitHub repositories, environments, secrets, and comments programmatically.
4+
5+
[Official GitHub Documentation](https://docs.github.com/) | [GitHub API Reference](https://docs.github.com/en/rest)
6+
7+
## Resources
8+
9+
- [Comment](./comment.md) - Create and manage comments on issues and pull requests
10+
- [RepositoryEnvironment](./repository-environment.md) - Create and manage deployment environments with protection rules
11+
- [Secret](./secret.md) - Create and manage GitHub Actions and Dependabot secrets
12+
13+
## Example Usage
14+
15+
```ts
16+
import { Comment, RepositoryEnvironment, GitHubSecret } from "alchemy/github";
17+
18+
// Create a repository environment
19+
const prodEnv = await RepositoryEnvironment("production", {
20+
owner: "my-org",
21+
repository: "my-repo",
22+
name: "production",
23+
waitTimer: 10,
24+
preventSelfReview: true,
25+
reviewers: {
26+
teams: ["platform-team"],
27+
users: ["security-admin"],
28+
},
29+
deploymentBranchPolicy: {
30+
protectedBranches: true,
31+
customBranchPolicies: false,
32+
},
33+
});
34+
35+
// Create a secret for the environment
36+
const secret = await GitHubSecret("deploy-key", {
37+
owner: "my-org",
38+
repository: "my-repo",
39+
name: "DEPLOY_KEY",
40+
value: alchemy.secret(process.env.DEPLOY_KEY),
41+
environment: "production",
42+
});
43+
44+
// Add a deployment status comment to a PR
45+
const deploymentComment = await Comment("deployment-status", {
46+
owner: "my-org",
47+
repository: "my-repo",
48+
issueNumber: 123,
49+
body: "✅ Successfully deployed to production environment!",
50+
});
51+
```

0 commit comments

Comments
 (0)
0