Skip to content

Commit 28a8286

Browse files
Refactor auto-reply workflow with improved comments
Updated comments for clarity and added label handling for issues and pull requests.
1 parent de1bdb2 commit 28a8286

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

.github/workflows/auto-reply.yml

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: 🤖 Auto Reply to Issues & PRs
33
on:
44
issues:
55
types: [opened, reopened]
6-
# Use pull_request_target so the job can run in the base-repo context and comment/label PRs from forks.
7-
# WARNING: Do NOT check out or run untrusted PR code in this job when using pull_request_target.
6+
# Use pull_request_target so this job can write comments/labels on PRs from forks.
7+
# SECURITY: Do NOT check out or execute untrusted PR code in this workflow.
88
pull_request_target:
99
types: [opened, reopened]
1010

@@ -15,45 +15,54 @@ permissions:
1515
jobs:
1616
auto-comment:
1717
runs-on: ubuntu-latest
18-
1918
steps:
2019
- name: 🧠 Auto Comment
2120
uses: actions/github-script@v7
2221
with:
2322
github-token: ${{ secrets.GITHUB_TOKEN }}
2423
script: |
25-
// Prefer checking payload properties rather than exact eventName string,
26-
// so this works for both pull_request and pull_request_target events.
2724
const repo = context.repo;
2825
29-
// ISSUE opened/reopened
26+
// Issue opened/reopened
3027
if (context.payload.issue) {
31-
const user = context.payload.issue.user?.login || 'contributor';
32-
const message = `👋 Hi @${user}!\n\nThanks for opening an issue in **MyCMD**.\n\nWe’ll review it soon — meanwhile, please ensure logs and reproduction steps are clear.
33-
Please visit our Website[here](https://drive-for-java.github.io)`;
28+
const issue = context.payload.issue;
29+
const user = issue.user?.login || 'contributor';
30+
const issueNumber = issue.number;
31+
const message = `👋 Hi @${user}!\n\nThanks for opening an issue in **MyCMD**.\n\nWe’ll review it soon — please ensure reproduction steps and logs are included.`;
3432
3533
await github.rest.issues.createComment({
3634
owner: repo.owner,
3735
repo: repo.repo,
38-
issue_number: context.payload.issue.number,
36+
issue_number: issueNumber,
3937
body: message
4038
});
4139
42-
// add a reaction if desired (make sure permissions include issues: write)
4340
await github.rest.reactions.createForIssue({
4441
owner: repo.owner,
4542
repo: repo.repo,
46-
issue_number: context.payload.issue.number,
43+
issue_number: issueNumber,
4744
content: "tada"
4845
});
4946
47+
try {
48+
await github.rest.issues.addLabels({
49+
owner: repo.owner,
50+
repo: repo.repo,
51+
issue_number: issueNumber,
52+
labels: ["triage", "needs-info"]
53+
});
54+
} catch (err) {
55+
core && core.info && core.info("Could not add labels to issue: " + err.message);
56+
}
57+
5058
return;
5159
}
5260
53-
// PULL REQUEST opened/reopened
61+
// Pull request opened/reopened (or synchronized)
5462
if (context.payload.pull_request) {
55-
const user = context.payload.pull_request.user?.login || 'contributor';
56-
const prNumber = context.payload.pull_request.number;
63+
const pr = context.payload.pull_request;
64+
const user = pr.user?.login || 'contributor';
65+
const prNumber = pr.number;
5766
5867
const message = `🚀 Hi @${user}!\n\nThank you for contributing to **MyCMD**. A maintainer will review your PR shortly. 🎉`;
5968
@@ -71,8 +80,25 @@ jobs:
7180
content: "rocket"
7281
});
7382
83+
const headRepoFull = pr.head && pr.head.repo && pr.head.repo.full_name ? pr.head.repo.full_name : '';
84+
const baseFull = `${repo.owner}/${repo.repo}`;
85+
const isFork = headRepoFull.toLowerCase() !== baseFull.toLowerCase();
86+
87+
const labels = ["needs-review"];
88+
if (isFork) labels.push("from-fork");
89+
90+
try {
91+
await github.rest.issues.addLabels({
92+
owner: repo.owner,
93+
repo: repo.repo,
94+
issue_number: prNumber,
95+
labels: labels
96+
});
97+
} catch (err) {
98+
core && core.info && core.info("Could not add labels to PR: " + err.message);
99+
}
100+
74101
return;
75102
}
76103
77-
// If neither payload is present, do nothing (defensive)
78-
core.info("No issue or pull_request payload found; skipping auto-comment.");
104+
core && core.info && core.info('No issue or pull_request payload found. Nothing to do.');

0 commit comments

Comments
 (0)