Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 106 additions & 29 deletions .github/workflows/design-done-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
if: github.event.issue != null
runs-on: ubuntu-latest
permissions:
issues: write # Required to add labels and create them if missing.
issues: write # Required to add/remove labels.

steps:
- name: Check checklist item and apply label
Expand All @@ -30,40 +30,117 @@ jobs:
const escapedItem = CHECKLIST_ITEM.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const checkedPattern = /^[\s]*[-*]\s+\[x\]\s+.*\*{0,2}Design Document\*{0,2}.*$/im;

if (!checkedPattern.test(body)) {
console.log('Checklist item is not checked — nothing to do.');
return;
}
if (checkedPattern.test(body)) {
console.log('Checklist item is checked. Ensuring label exists...');

console.log('Checklist item is checked. Ensuring label exists...');
// Ensure the "Design Done" label exists in this repository.
// If it already exists this call will throw a 422; we catch and ignore that.
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: LABEL_NAME,
color: '0075ca', // Blue — feel free to change.
description: 'Design document has been created and reviewed.',
});
console.log(`Label "${LABEL_NAME}" created.`);
} catch (err) {
if (err.status === 422) {
// Label already exists — that is fine.
console.log(`Label "${LABEL_NAME}" already exists.`);
} else {
throw err;
}
}

// Ensure the "Design Done" label exists in this repository.
// If it already exists this call will throw a 422; we catch and ignore that.
try {
await github.rest.issues.createLabel({
// Add the label to the issue. GitHub ignores duplicates, so this is
// idempotent — applying it again will not cause an error.
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
name: LABEL_NAME,
color: '0075ca', // Blue — feel free to change.
description: 'Design document has been created and reviewed.',
issue_number: context.payload.issue.number,
labels: [LABEL_NAME],
});
console.log(`Label "${LABEL_NAME}" created.`);
} catch (err) {
if (err.status === 422) {
// Label already exists — that is fine.
console.log(`Label "${LABEL_NAME}" already exists.`);
} else {
throw err;

console.log(`Label "${LABEL_NAME}" added to issue #${context.payload.issue.number}.`);
} else {
console.log('Checklist item is not checked. Removing label if present...');

// Remove the label from the issue if it exists.
// GitHub returns 404 if the label is not on the issue; we catch and ignore that.
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
name: LABEL_NAME,
});
console.log(`Label "${LABEL_NAME}" removed from issue #${context.payload.issue.number}.`);
} catch (err) {
if (err.status === 404) {
// Label was not on the issue — nothing to remove.
console.log(`Label "${LABEL_NAME}" was not present on issue #${context.payload.issue.number}.`);
} else {
throw err;
}
}
}
- name: Check "Design Mail" checklist item and apply "Mail Sent" label
uses: actions/github-script@v7
with:
script: |
const LABEL_NAME = 'Mail Sent';

const body = context.payload.issue.body || '';

// Matches a checked GFM checkbox line containing "Design Mail"
const checkedPattern = /^[\s]*[-*]\s+\[x\]\s+.*Design Mail.*$/im;

// Add the label to the issue. GitHub ignores duplicates, so this is
// idempotent — applying it again will not cause an error.
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
labels: [LABEL_NAME],
});
if (checkedPattern.test(body)) {
console.log('"Design Mail" checklist item is checked. Ensuring label exists...');

console.log(`Label "${LABEL_NAME}" added to issue #${context.payload.issue.number}.`);
// Ensure the "Mail Sent" label exists in this repository.
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: LABEL_NAME,
color: 'e4e669', // Yellow — feel free to change.
description: 'Design mail has been sent.',
});
console.log(`Label "${LABEL_NAME}" created.`);
} catch (err) {
if (err.status === 422) {
console.log(`Label "${LABEL_NAME}" already exists.`);
} else {
throw err;
}
}

await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
labels: [LABEL_NAME],
});

console.log(`Label "${LABEL_NAME}" added to issue #${context.payload.issue.number}.`);
} else {
console.log('"Design Mail" checklist item is not checked. Removing label if present...');

try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
name: LABEL_NAME,
});
console.log(`Label "${LABEL_NAME}" removed from issue #${context.payload.issue.number}.`);
} catch (err) {
if (err.status === 404) {
console.log(`Label "${LABEL_NAME}" was not present on issue #${context.payload.issue.number}.`);
} else {
throw err;
}
}
}
49 changes: 49 additions & 0 deletions .github/workflows/enforce-design-gate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Enforce Design Gate

# Fires when a label is added or removed from an issue.
# Used to warn when required design labels are missing.
on:
issues:
types: [labeled, unlabeled]

jobs:
enforce-design-gate:
runs-on: ubuntu-latest
permissions:
issues: write # Required to post a comment on the issue.

steps:
- name: Warn if design gate labels are incomplete
uses: actions/github-script@v7
with:
script: |
const REQUIRED_LABELS = ['Design Done', 'Mail Sent'];
const GATE_LABEL = 'Design Done'; // Only warn when a required label is removed.

// Only act when a required label is removed.
const removedLabel = context.payload.label?.name;
if (
context.payload.action !== 'unlabeled' ||
!REQUIRED_LABELS.includes(removedLabel)
) {
console.log('Not a relevant label change — skipping.');
return;
}

console.log(`Label "${removedLabel}" removed. Posting design gate warning...`);

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: [
'> [!WARNING]',
`> **Design gate incomplete.** The \`${removedLabel}\` label was removed from this issue.`,
'>',
`> This issue should **not** be moved to the **Development** phase until both of the following labels are present:`,
'>',
...REQUIRED_LABELS.map(l => `> - \`${l}\``),
].join('\n'),
});

console.log(`Warning comment posted on issue #${context.payload.issue.number}.`);
Loading