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
8 changes: 7 additions & 1 deletion .github/scripts/linked-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ function hasLinearKey(title, body, branch) {
return KEY.test([title, body, branch].join('\n'));
}

module.exports = { hasLinearKey };
// GitHub App bots (Dependabot, schema generators) open PRs with no issue.
// Only org admins can install apps, so a person cannot use this to skip.
function isBot(user) {
return user.type === 'Bot';
}

module.exports = { hasLinearKey, isBot };
5 changes: 4 additions & 1 deletion .github/scripts/linked-issue.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('node:assert/strict');
const { hasLinearKey } = require('./linked-issue.js');
const { hasLinearKey, isBot } = require('./linked-issue.js');

assert.ok(hasLinearKey('Fix login', '', 'user/abc-42'), 'lowercase branch key');
assert.ok(hasLinearKey('Fix login', 'Fixes ABC-123', 'user/fix-login'), 'key in body');
Expand All @@ -8,4 +8,7 @@ assert.ok(!hasLinearKey('Fix login', null, 'user/fix-login'), 'empty body, no ke
for (const s of ['UTF-8', 'ISO-8601', 'CVE-2024-1234', 'RFC-9110', 'TLS-1']) {
assert.ok(!hasLinearKey(s, '', 'main'), `${s} is not a key`);
}
assert.ok(isBot({ login: 'dependabot[bot]', type: 'Bot' }), 'Dependabot is a bot');
assert.ok(isBot({ login: 'nps-schema-doc-generator[bot]', type: 'Bot' }), 'app bot');
assert.ok(!isBot({ login: 'someone', type: 'User' }), 'a person is not a bot');
console.log('ok');
4 changes: 2 additions & 2 deletions .github/workflows/linked-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
...context.repo,
pull_number: context.payload.pull_request.number,
});
if (pr.user.login === 'dependabot[bot]') return;
const { hasLinearKey } = require(`${process.env.GITHUB_WORKSPACE}/central/.github/scripts/linked-issue.js`);
const { hasLinearKey, isBot } = require(`${process.env.GITHUB_WORKSPACE}/central/.github/scripts/linked-issue.js`);
if (isBot(pr.user)) return;
if (!hasLinearKey(pr.title, pr.body, pr.head.ref)) {
core.setFailed('Add a Linear issue key, for example ABC-123, to the PR title, body, or branch name.');
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Workflows that GitHub runs on pull requests in every North Pole Security reposit

The `linked-issue` check fails when a pull request has no Linear issue key. A key is 2 to 5 letters, a dash, and a number, for example `ABC-123`. The check looks in the pull request title, the body, and the branch name. It ignores case.

The check does not count common tokens such as `SHA-256`, `UTF-8`, and `CVE-2024-1234` as keys. Pull requests from Dependabot pass.
The check does not count common tokens such as `SHA-256`, `UTF-8`, and `CVE-2024-1234` as keys. Pull requests from GitHub App bots, such as Dependabot, pass.

If the check fails, add the key to the title or the body. Then push a commit or run the check again. GitHub does not run the check again when you only edit the title or the body.

Expand Down
Loading