Skip to content

Commit 95a79f4

Browse files
committed
feat: make default messages and dynamic content syntax
1 parent 230463e commit 95a79f4

File tree

3 files changed

+107
-67
lines changed

3 files changed

+107
-67
lines changed

.github/workflows/pr-auto-comments.yml

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ on:
1616
description: 'Message for first PR comments (leave empty to disable first PR comments)'
1717
required: false
1818
type: string
19-
default: ''
19+
default: 'Hello @{{username}}, thank you for submitting your first pull request to the {{repository}} repository. We value your contribution and encourage you to review our contribution guidelines to ensure your submission meets our standards. Please note that every merged PR is automatically enrolled in our Best PR Initiative, offering a chance to win $500 each quarter. Our team is available via GitHub Discussions or Discord if you have any questions. Welcome aboard!'
2020
ready_for_review_comment:
2121
description: 'Message for PR ready for review comments (leave empty to disable ready for review comments)'
2222
required: false
2323
type: string
24-
default: ''
24+
default: 'Thank you for your submission! As you prepare for the review process, please ensure that your PR title, description, and any linked issues fully comply with our contribution guidelines. A clear explanation of your changes and their context will help expedite the review process. Every merged PR is automatically entered into our Best PR Initiative, offering a chance to win $500 every quarter. We appreciate your attention to detail and look forward to reviewing your contribution!'
2525
merged_pr_comment:
2626
description: 'Message for merged PR comments (leave empty to disable merged PR comments)'
2727
required: false
2828
type: string
29-
default: ''
29+
default: 'Congratulations, your pull request has been merged! Thank you for your valuable contribution to Request Network. As a reminder, every merged PR is automatically entered into our Best PR Initiative, offering a quarterly prize of $500. Your work significantly supports our project\'s growth, and we encourage you to continue engaging with our community. Additionally, if you want to build or add crypto payments and invoicing features, explore how our API can reduce deployment time from months to hours while offering advanced features. Book a call with our expert to learn more and fast-track your development.'
3030
secrets:
3131
token:
3232
description: 'GitHub token with org:read permission'
@@ -127,11 +127,23 @@ jobs:
127127
with:
128128
github-token: ${{ github.token }}
129129
script: |
130+
const variables = {
131+
username: context.payload.pull_request.user.login,
132+
repository: context.payload.repository.name,
133+
org: context.repo.owner,
134+
};
135+
136+
let commentBody = `${{ inputs.first_pr_comment }}`;
137+
Object.entries(variables).forEach(([key, value]) => {
138+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
139+
commentBody = commentBody.replace(regex, value);
140+
});
141+
130142
github.rest.issues.createComment({
131143
issue_number: context.issue.number,
132144
owner: context.repo.owner,
133145
repo: context.repo.repo,
134-
body: `${{ inputs.first_pr_comment }}`
146+
body: commentBody
135147
});
136148
137149
# Leave a comment when PR is marked ready for review
@@ -146,11 +158,23 @@ jobs:
146158
with:
147159
github-token: ${{ github.token }}
148160
script: |
161+
const variables = {
162+
username: context.payload.pull_request.user.login,
163+
repository: context.payload.repository.name,
164+
org: context.repo.owner,
165+
};
166+
167+
let commentBody = `${{ inputs.ready_for_review_comment }}`;
168+
Object.entries(variables).forEach(([key, value]) => {
169+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
170+
commentBody = commentBody.replace(regex, value);
171+
});
172+
149173
github.rest.issues.createComment({
150174
issue_number: context.issue.number,
151175
owner: context.repo.owner,
152176
repo: context.repo.repo,
153-
body: `${{ inputs.ready_for_review_comment }}`
177+
body: commentBody
154178
});
155179
156180
# Leave a comment when PR is merged
@@ -165,9 +189,21 @@ jobs:
165189
with:
166190
github-token: ${{ github.token }}
167191
script: |
192+
const variables = {
193+
username: context.payload.pull_request.user.login,
194+
repository: context.payload.repository.name,
195+
org: context.repo.owner,
196+
};
197+
198+
let commentBody = `${{ inputs.merged_pr_comment }}`;
199+
Object.entries(variables).forEach(([key, value]) => {
200+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
201+
commentBody = commentBody.replace(regex, value);
202+
});
203+
168204
github.rest.issues.createComment({
169205
issue_number: context.issue.number,
170206
owner: context.repo.owner,
171207
repo: context.repo.repo,
172-
body: `${{ inputs.merged_pr_comment }}`
208+
body: commentBody
173209
});

README.md

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,11 @@ jobs:
2828
uses: your-org/auto-comments/.github/workflows/pr-auto-comments.yml@main
2929
with:
3030
org_name: "your-organization-name"
31-
# Enable only the comment types you want by providing content
31+
# Optional: override the default comments
3232
first_pr_comment: |
3333
# Welcome to our project!
3434
35-
Thanks for your first contribution. We're glad you're here.
36-
# To disable a comment type, either remove it or leave it empty
37-
merged_pr_comment: |
38-
# PR Merged
39-
40-
Thank you for your contribution!
35+
Thanks for your first contribution, @{{username}}. We're glad you're here.
4136
secrets:
4237
token: ${{ secrets.GITHUB_TOKEN }}
4338
```
@@ -52,36 +47,63 @@ jobs:
5247

5348
### Optional Inputs
5449

55-
| Input | Description | Default | Behavior if not provided |
50+
| Input | Description | Default | Behavior if empty string |
5651
|-------|-------------|---------|--------------------------|
5752
| `additional_internal_users` | Additional comma-separated list of usernames to consider as internal | `''` | No additional users excluded |
58-
| `first_pr_comment` | Message for first PR comments | `''` | First PR comments disabled |
59-
| `ready_for_review_comment` | Message for ready for review comments | `''` | Ready for review comments disabled |
60-
| `merged_pr_comment` | Message for merged PR comments | `''` | Merged PR comments disabled |
53+
| `first_pr_comment` | Message for first PR comments | Default welcome message | First PR comments disabled |
54+
| `ready_for_review_comment` | Message for ready for review comments | Default guidelines message | Ready for review comments disabled |
55+
| `merged_pr_comment` | Message for merged PR comments | Default thank you message | Merged PR comments disabled |
6156

6257
### Secrets
6358

6459
| Secret | Description | Required | Default |
6560
|--------|-------------|----------|---------|
6661
| `token` | GitHub token with org:read permission | No | `github.token` |
6762

63+
## Default Messages
64+
65+
The workflow includes default messages for each comment type:
66+
67+
### First PR Comment
68+
A welcome message that mentions the contributor by username, introduces them to the project, and highlights the Best PR Initiative with its $500 quarterly prize.
69+
70+
### Ready for Review Comment
71+
A reminder about contribution guidelines and the Best PR Initiative, encouraging clear PR descriptions to expedite the review process.
72+
73+
### Merged PR Comment
74+
A congratulatory message that thanks the contributor, reminds them about the Best PR Initiative, and promotes the Request Network API for crypto payments and invoicing features.
75+
6876
## Enabling and Disabling Comment Types
6977

70-
You can selectively enable comment types by providing content for the corresponding input:
78+
By default, all comment types are enabled with predefined messages. You can:
79+
80+
- **Override** a default comment by providing your own message text
81+
- **Disable** a comment type by providing an empty string `''`
82+
83+
For example, to disable ready for review comments:
7184

72-
- To **enable** a comment type: provide the message text
73-
- To **disable** a comment type: omit the input or provide an empty string
85+
```yaml
86+
ready_for_review_comment: '' # Explicitly set to empty string to disable
87+
```
88+
89+
## Dynamic Content with Variable Placeholders
90+
91+
You can include dynamic content in your messages using placeholders with the format `{{variable}}`. The following variables are available:
7492

75-
For example, to enable only first PR and merged PR comments:
93+
| Variable | Description | Example |
94+
|----------|-------------|---------|
95+
| `{{username}}` | The PR author's username | `octocat` |
96+
| `{{repository}}` | The repository name | `auto-comments` |
97+
| `{{org}}` | The organization/owner name | `your-org` |
98+
99+
Example usage in a custom message:
76100

77101
```yaml
78102
first_pr_comment: |
79-
# Welcome!
80-
Thanks for your contribution.
81-
# ready_for_review_comment is omitted to disable it
82-
merged_pr_comment: |
83-
# Merged
84-
Your PR has been merged.
103+
# Welcome @{{username}}!
104+
105+
Thank you for your first contribution to the {{repository}} repository.
106+
We at {{org}} appreciate your interest in our project.
85107
```
86108

87109
## Comment Formatting
@@ -95,6 +117,10 @@ You can use full Markdown syntax in your comment messages, including:
95117
- Code blocks
96118
- Emojis (`:tada:`)
97119

120+
## Special Placeholders
121+
122+
The first PR comment supports the `@<username>` placeholder, which will be automatically replaced with the PR author's username.
123+
98124
## How It Works
99125

100126
1. The workflow first checks the PR author in a central job:
@@ -103,7 +129,7 @@ You can use full Markdown syntax in your comment messages, including:
103129

104130
2. Based on the event type (opened/ready for review/merged) and author status:
105131
- Runs only the appropriate comment job
106-
- Only if the corresponding comment text is provided
132+
- Only if the corresponding comment text is not empty
107133

108134
3. Each enabled job posts its specific comment to the PR
109135

example-usage.yml

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,37 @@ on:
55
types: [opened, ready_for_review, closed]
66

77
jobs:
8-
# Example 1: All comment types enabled
9-
pr-comments-all:
8+
# Example 1: Using default comments
9+
pr-comments-defaults:
1010
uses: your-org/auto-comments/.github/workflows/pr-auto-comments.yml@main
1111
with:
1212
org_name: "your-organization-name"
1313
additional_internal_users: "external-consultant,bot-account"
14-
15-
# First PR comment
16-
first_pr_comment: |
17-
# 🌟 Welcome to your first contribution!
18-
19-
We're thrilled to see your first PR to our project. Here at [Organization], we value every contribution.
20-
21-
## Next steps
22-
- Our team will review your changes soon
23-
- You might get some feedback or requests for changes
24-
- Feel free to ask questions if anything is unclear
25-
26-
Thank you for taking the time to contribute to our project!
27-
28-
# Ready for review comment
29-
ready_for_review_comment: |
30-
# Ready for review - thank you!
31-
32-
Your PR has been marked as ready for review and will be reviewed by our team soon.
33-
34-
Please allow 2-3 business days for the review process.
35-
36-
# Merged PR comment
37-
merged_pr_comment: |
38-
# Congratulations! 🎉
39-
40-
Your PR has been merged successfully. Thank you for your valuable contribution!
41-
42-
Your changes will be included in the next release of our software.
14+
# No comment content provided - will use defaults
4315
secrets:
4416
token: ${{ secrets.GITHUB_TOKEN }}
4517

46-
# Example 2: Only specific comment types enabled
47-
pr-comments-selective:
18+
# Example 2: Customizing some comments, disabling others
19+
pr-comments-custom:
4820
uses: your-org/auto-comments/.github/workflows/pr-auto-comments.yml@main
4921
with:
5022
org_name: "your-organization-name"
5123

52-
# Only enable first PR and merged PR comments
24+
# Custom first PR comment with variable placeholders
5325
first_pr_comment: |
54-
# Welcome to our project!
55-
Thank you for your first contribution!
26+
# Welcome @{{username}}!
27+
28+
Thank you for your first contribution to the {{repository}} repository.
29+
Our {{org}} team will review your changes soon.
5630
57-
# Ready for review comments disabled by not providing this input
31+
# Disable ready for review comments
32+
ready_for_review_comment: ''
5833

34+
# Custom merged PR comment with variable placeholders
5935
merged_pr_comment: |
60-
# PR Merged
61-
Thank you for your contribution!
36+
# Congratulations on your merged PR! 🎉
37+
38+
Thank you @{{username}} for your contribution to {{repository}}!
39+
Your changes are now part of the {{org}} codebase.
6240
secrets:
6341
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)