Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit 117aac1

Browse files
authored
Merge pull request #9 from calebephrem/main
fix: prevent empty label validation errors on issue open
2 parents c269e2d + 3464442 commit 117aac1

1 file changed

Lines changed: 28 additions & 37 deletions

File tree

.github/workflows/bot.yml

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515

1616
cc_warning_message:
1717
required: false
18-
default: '⚠️ Please consider using Conventional Commits (e.g. feat:, fix:, docs:).'
18+
default: "⚠️ Please consider using Conventional Commits (e.g. feat:, fix:, docs:).\nhttps://www.conventionalcommits.org/en/v1.0.0/"
1919
type: string
2020

2121
secrets:
@@ -27,7 +27,7 @@ on:
2727
jobs:
2828
pr-handler:
2929
runs-on: ubuntu-latest
30-
if: github.event_name == 'pull_request'
30+
if: github.event_name == 'pull_request' && github.event.action != 'closed'
3131

3232
steps:
3333
- name: Generate DevHub Bot token
@@ -167,63 +167,54 @@ jobs:
167167
app-id: ${{ secrets.DEVHUB_APP_ID }}
168168
private-key: ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
169169

170-
- name: Handle new issue (labels + comment)
170+
- name: Handle issue open (labels + comment)
171171
uses: actions/github-script@v7
172172
with:
173173
github-token: ${{ steps.app-token.outputs.token }}
174174
script: |
175175
const issue = context.payload.issue;
176176
177-
const text = `${issue.title}\n${issue.body || ""}`.toLowerCase();
178-
179-
const detectedLabels = [];
177+
const text = `${issue.title}\n${issue.body ?? ""}`.toLowerCase();
180178
181179
const rules = [
182-
{ keywords: ["bug", "error", "crash", "fail"], label: "bug" },
183-
{ keywords: ["feature", "request", "enhancement"], label: "enhancement" },
184-
{ keywords: ["doc", "docs", "readme"], label: "documentation" },
185-
{ keywords: ["question", "help"], label: "question" },
180+
{ label: "bug", keywords: ["bug", "error", "crash", "fail", "issue"] },
181+
{ label: "enhancement", keywords: ["feature", "request", "enhance"] },
182+
{ label: "documentation", keywords: ["docs", "readme", "documentation"] },
183+
{ label: "question", keywords: ["question", "help"] },
186184
];
187185
188-
for (const rule of rules) {
189-
if (
190-
rule.label &&
191-
rule.keywords.some((k) => text.includes(k))
192-
) {
193-
detectedLabels.push(rule.label);
194-
}
195-
}
196-
197-
// Deduplicate + remove invalid values
198-
const labels = [...new Set(detectedLabels)].filter(
199-
(l) => typeof l === "string" && l.trim().length > 0
200-
);
186+
const labels = rules
187+
.filter(r => r.label && r.keywords.some(k => text.includes(k)))
188+
.map(r => r.label)
189+
.filter(l => typeof l === "string" && l.trim().length > 0);
201190
202191
if (labels.length > 0) {
192+
console.log("Applying labels:", labels);
193+
203194
await github.rest.issues.addLabels({
204195
owner: context.repo.owner,
205196
repo: context.repo.repo,
206197
issue_number: issue.number,
207198
labels,
208199
});
200+
} else {
201+
console.log("No labels detected — skipping label API call");
209202
}
210203
211-
const comment = [
212-
"👋 **Thanks for opening this issue!**",
213-
"",
214-
"The DevHub maintainers have been notified and will review it ASAP 🚀",
215-
"",
216-
"📌 **Tips to help us help you:**",
217-
"- Clear steps to reproduce (for bugs)",
218-
"- Expected vs actual behavior",
219-
"- Screenshots or logs if applicable",
220-
"",
221-
"Thanks for contributing 💙",
222-
].join("\n");
223-
224204
await github.rest.issues.createComment({
225205
owner: context.repo.owner,
226206
repo: context.repo.repo,
227207
issue_number: issue.number,
228-
body: comment,
208+
body: [
209+
"👋 **Thanks for opening this issue!**",
210+
"",
211+
"Our maintainers have been notified and will review it as soon as possible 🚀",
212+
"",
213+
"📌 **To help us resolve this faster:**",
214+
"- Include clear steps to reproduce (for bugs)",
215+
"- Mention expected vs actual behavior",
216+
"- Add screenshots or logs if relevant",
217+
"",
218+
"Thanks for contributing to **Open DevHub** 💙",
219+
].join("\n"),
229220
});

0 commit comments

Comments
 (0)