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
2 changes: 1 addition & 1 deletion .github/workflows/automation-group-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
jobs:
issue-open:
name: Issue Open
if: ${{ github.event_name == 'issues' && contains(fromJSON('["opened","reopened"]'), github.event.action) }}
if: ${{ github.event_name == 'issues' && (contains(fromJSON('["opened","reopened"]'), github.event.action) || (github.event.action == 'edited' && github.event.changes.body)) }}
uses: learningequality/.github/.github/workflows/manage-issue-header.yml@main
permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL: ${{ secrets.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL }}
issues:
name: Issues
if: ${{ (github.event_name == 'issues' && contains(fromJSON('["opened","reopened"]'), github.event.action)) || (github.event_name == 'issues' && contains(fromJSON('["labeled","unlabeled"]'), github.event.action) && github.event.label.name == 'help wanted') || (github.event_name == 'issues' && github.event.action == 'labeled' && (github.event.label.name == 'good first issue' || github.event.label.name == 'help wanted')) || (github.event_name == 'issues' && contains(fromJSON('["assigned","unassigned"]'), github.event.action)) || (github.event_name == 'issues' && (github.event.action == 'opened' || (contains(fromJSON('["edited","reopened"]'), github.event.action) && contains(github.event.issue.labels.*.name, 'needs-template')))) }}
if: ${{ (github.event_name == 'issues' && (contains(fromJSON('["opened","reopened"]'), github.event.action) || (github.event.action == 'edited' && github.event.changes.body))) || (github.event_name == 'issues' && contains(fromJSON('["labeled","unlabeled"]'), github.event.action) && github.event.label.name == 'help wanted') || (github.event_name == 'issues' && github.event.action == 'labeled' && (github.event.label.name == 'good first issue' || github.event.label.name == 'help wanted')) || (github.event_name == 'issues' && contains(fromJSON('["assigned","unassigned"]'), github.event.action)) || (github.event_name == 'issues' && (github.event.action == 'opened' || (contains(fromJSON('["edited","reopened"]'), github.event.action) && contains(github.event.issue.labels.*.name, 'needs-template')))) }}
uses: learningequality/.github/.github/workflows/automation-group-issues.yml@main
permissions:
contents: read
Expand Down
4 changes: 2 additions & 2 deletions automation-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ automations:
leaf: manage-issue-header.yml
on:
issues:
types: [opened, reopened]
if: "github.event_name == 'issues' && contains(fromJSON('[\"opened\",\"reopened\"]'), github.event.action)"
types: [opened, reopened, edited]
if: "github.event_name == 'issues' && (contains(fromJSON('[\"opened\",\"reopened\"]'), github.event.action) || (github.event.action == 'edited' && github.event.changes.body))"
secrets:
LE_BOT_APP_ID: required
LE_BOT_PRIVATE_KEY: required
Expand Down
9 changes: 6 additions & 3 deletions scripts/manage-issue-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = async ({ github, context, core }) => {
header = isIssueHelpWanted(issue) ? HELP_WANTED_HEADER : NON_HELP_WANTED_HEADER;
break;
case 'reopened':
// check for pre-existing 'help wanted' label
case 'edited':
header = isIssueHelpWanted(issue) ? HELP_WANTED_HEADER : NON_HELP_WANTED_HEADER;
break;
case 'labeled':
Expand Down Expand Up @@ -94,8 +94,11 @@ module.exports = async ({ github, context, core }) => {

const currentBody = issue.data.body || '';

let newBody = clearHeader(currentBody);
newBody = header + newBody;
const newBody = header + clearHeader(currentBody);
if (newBody === currentBody) {
core.info('Header is already up to date.');
return;
}

await github.rest.issues.update({
owner: repoOwner,
Expand Down
58 changes: 58 additions & 0 deletions scripts/manage-issue-header.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const test = require('node:test');
const assert = require('node:assert/strict');

const manageIssueHeader = require('./manage-issue-header');

function fakeGithub(body) {
const updates = [];
return {
updates,
rest: {
issues: {
get: async () => ({ data: { body } }),
update: async ({ body: updated }) => updates.push(updated),
},
},
};
}

function fakeCore() {
const failures = [];
return { failures, info() {}, setFailed: message => failures.push(message) };
}

function fakeContext(action, labels = []) {
return {
repo: { owner: 'learningequality', repo: 'kolibri' },
payload: { action, issue: { number: 7, labels: labels.map(name => ({ name })) } },
};
}

async function run(action, body, labels) {
const github = fakeGithub(body);
const core = fakeCore();
await manageIssueHeader({ github, context: fakeContext(action, labels), core });
assert.deepEqual(core.failures, []);
return github.updates;
}

test('an edit that drops the header restores it', async () => {
const [body] = await run('edited', 'Steps to reproduce', ['help wanted']);

assert.match(body, /^<!---HEADER START-->[\s\S]*This issue is open for contribution/);
assert.match(body, /<!---HEADER END-->\n\nSteps to reproduce$/);
});

test('an edit that keeps the header leaves the body alone', async () => {
const [withHeader] = await run('edited', 'Steps to reproduce', []);

assert.deepEqual(await run('edited', withHeader, []), []);
});

test('an edit replaces a header that no longer matches the labels', async () => {
const [notOpen] = await run('edited', 'Steps to reproduce', []);
const [open] = await run('edited', notOpen, ['help wanted']);

assert.match(open, /This issue is open for contribution/);
assert.doesNotMatch(open, /not open for contribution/);
});
Loading