diff --git a/.github/workflows/issue-label.yaml b/.github/workflows/issue-label.yaml index 94f0d82ead..a2a343a022 100644 --- a/.github/workflows/issue-label.yaml +++ b/.github/workflows/issue-label.yaml @@ -2,7 +2,7 @@ name: Issue Labeler on: issues: - types: [opened] + types: [opened, edited] permissions: issues: write @@ -22,22 +22,48 @@ jobs: return; } + const isEdit = context.payload.action === 'edited'; + const titleWasEdited = Boolean(context.payload.changes?.title); + + if (isEdit && !titleWasEdited) { + return; + } + const title = issue.title ?? ''; const body = issue.body ?? ''; // Freeform bug reports: "issue: ...", "bug: ...", "fix: ...", "[Bug] ...", "issue/UX: ..." - const bugLikeTitle = /^\s*\[?(bug|issue|fix)\]?\s*[:/\-]/i.test(title); + const bugLikeTitle = /^\s*(\[\s*(bug|issue|fix)\b[^\]]*\]|(bug|issue|fix)\s*[:/\-])/i.test(title); // API/CLI-created issues that reproduce the bug report form structure. // Only headings distinctive to the bug form (both are required fields there) — // generic headings like "Expected Behavior" also appear in freeform feature requests. const bugFormBody = /###\s*(Installation Method|Open WebUI Version)/i.test(body); - if (bugLikeTitle || bugFormBody) { - await github.rest.issues.addLabels({ + if (!bugLikeTitle && !bugFormBody) { + return; + } + + if (isEdit) { + const events = await github.paginate(github.rest.issues.listEvents, { owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, - labels: ['bug'] + per_page: 100 }); + + const bugLabelWasRemoved = events.some( + (event) => event.event === 'unlabeled' && event.label?.name === 'bug' + ); + + if (bugLabelWasRemoved) { + return; + } } + + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + labels: ['bug'] + });