Skip to content

Commit c8d2672

Browse files
Merge pull request #68 from Soumyosish/issue-create-automate-message
issue create automate message
2 parents 4478282 + 51bac7b commit c8d2672

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Auto Comment on Issue
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
workflow_dispatch: {} # optional: lets you test the script manually
7+
8+
permissions:
9+
issues: write
10+
reactions: write
11+
12+
concurrency:
13+
group: issue-${{ github.event.issue.number }}-autocomment
14+
cancel-in-progress: true
15+
16+
jobs:
17+
comment:
18+
# Skip bots and only run for outside folks
19+
if: >
20+
github.event_name == 'workflow_dispatch' ||
21+
(
22+
github.event.issue.user.type != 'Bot' &&
23+
contains(fromJson('["NONE","FIRST_TIME_CONTRIBUTOR","CONTRIBUTOR"]'), github.event.issue.author_association) &&
24+
!contains(github.event.issue.title, '[skip-autoreply]') &&
25+
!contains(github.event.issue.body || '', '[skip-autoreply]') &&
26+
!contains(join(github.event.issue.labels.*.name, ','), 'no-bot')
27+
)
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Auto-triage & comment
32+
uses: actions/github-script@v7
33+
with:
34+
script: |
35+
const owner = context.repo.owner;
36+
const repo = context.repo.repo;
37+
const issue_number = context.payload.issue?.number || context.issue.number;
38+
39+
// Hidden marker to avoid duplicates
40+
const COMMENT_MARKER = '<!-- auto-comment-marker:v1 -->';
41+
42+
// 1) Ensure "needs triage" label exists; create if missing (best-effort)
43+
const triageLabel = 'needs triage';
44+
try {
45+
const allLabels = await github.paginate(github.rest.issues.listLabelsForRepo, { owner, repo, per_page: 100 });
46+
const hasTriage = allLabels.some(l => l.name.toLowerCase() === triageLabel.toLowerCase());
47+
if (!hasTriage) {
48+
await github.rest.issues.createLabel({
49+
owner, repo,
50+
name: triageLabel,
51+
color: 'FBCA04',
52+
description: 'Awaiting maintainer triage'
53+
}).catch(() => {}); // ignore race if another run creates it
54+
}
55+
const currentIssue = context.payload.issue;
56+
if (currentIssue) {
57+
const existing = (currentIssue.labels || []).map(l => l.name.toLowerCase());
58+
if (!existing.includes(triageLabel.toLowerCase())) {
59+
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [triageLabel] });
60+
}
61+
}
62+
} catch (e) {
63+
console.log('Label step skipped/failed (non-fatal):', e.message);
64+
}
65+
66+
// 2) Avoid duplicate comments (paginate all comments)
67+
const comments = await github.paginate(github.rest.issues.listComments, {
68+
owner, repo, issue_number, per_page: 100
69+
});
70+
const hasMarker = comments.some(c => (c.body || '').includes(COMMENT_MARKER));
71+
if (hasMarker) {
72+
console.log('Comment already exists, skipping.');
73+
return;
74+
}
75+
76+
// 3) Craft the message (dynamic author mention when available)
77+
const author = context.payload.issue?.user?.login || 'there';
78+
const message = `### Thanks for opening this issue, @${author}! ✨
79+
80+
We'll review it as soon as possible. We truly appreciate your contribution.
81+
82+
> In the meantime, please confirm you’ve read the \`README.md\`, \`CONTRIBUTING.md\`, and \`CODE_OF_CONDUCT.md\`.
83+
> Also, please **do not** open a PR until a maintainer has assigned this issue to you. 😊
84+
85+
${COMMENT_MARKER}`;
86+
87+
await github.rest.issues.createComment({
88+
owner, repo, issue_number, body: message
89+
});
90+
91+
// 4) Add a friendly reaction (non-fatal)
92+
try {
93+
await github.rest.reactions.createForIssue({
94+
owner, repo, issue_number, content: 'heart'
95+
});
96+
} catch (e) {
97+
console.log('Reaction failed (non-fatal):', e.message);
98+
}
99+
100+
console.log('Auto-comment complete.');

0 commit comments

Comments
 (0)