Skip to content

Commit 6a6c1c4

Browse files
authored
feat: add bots_ignore input (#231)
1 parent 30540d3 commit 6a6c1c4

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ jobs:
3737
3838
## Inputs
3939
40+
### `bots_ignore`
41+
42+
**Optional** A list of bots to ignore when linting the pull request title. Can be a comma-separated list.
43+
4044
### `comment`
4145

4246
**Optional** Post a comment in the pull request conversation with examples.

action.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ branding:
44
icon: align-left
55
color: blue
66
inputs:
7+
bots_ignore:
8+
required: false
9+
description: A list of bots to ignore when linting the pull request title. Can be a comma-separated list.
10+
default: ''
711
comment:
812
required: false
913
description: Post a comment in the pull request conversation with examples.

jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} **/
22
module.exports = {
3+
collectCoverage: true,
34
testEnvironment: 'node',
45
transform: {
56
'^.+.tsx?$': ['ts-jest', {}],

src/__tests__/lint.test.ts

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import {getConventionalCommitTypes, lintPullRequest} from '../lint';
1+
import {
2+
getConventionalCommitTypes,
3+
lintPullRequest,
4+
isBotIgnored,
5+
} from '../lint';
6+
import {getInput} from '@actions/core';
7+
8+
jest.mock('@actions/core');
29

310
describe('getConvetionalCommitTypes tests', () => {
4-
it('should return types', () => {
11+
test('should return types', () => {
512
const types = getConventionalCommitTypes();
613

714
expect(
@@ -30,8 +37,26 @@ describe('lintPullRequest tests', () => {
3037
];
3138

3239
tests.forEach(({args, expected}) => {
33-
it(`should pass or fail linting ['${args}', '${expected}']`, async () => {
40+
test(`should pass or fail linting ['${args}', '${expected}']`, async () => {
3441
expect(await lintPullRequest(args)).toBe(expected);
3542
});
3643
});
3744
});
45+
46+
jest.mock('@actions/github', () => ({
47+
context: {
48+
actor: 'test-bot',
49+
},
50+
}));
51+
52+
describe('isBotIgnored tests', () => {
53+
test('should return true if the bot is in the ignore list', () => {
54+
(getInput as jest.Mock).mockReturnValue('test-bot,another-bot');
55+
expect(isBotIgnored()).toBe(true);
56+
});
57+
58+
test('should return false if the bot is not in the ignore list', () => {
59+
(getInput as jest.Mock).mockReturnValue('another-bot');
60+
expect(isBotIgnored()).toBe(false);
61+
});
62+
});

src/lint.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import {
55
getPullRequest,
66
} from './github';
77
import * as conventionalCommitTypes from 'conventional-commit-types';
8-
import {getInput} from '@actions/core';
8+
import {getInput, info} from '@actions/core';
9+
import {context} from '@actions/github';
910

1011
const types = Object.keys(conventionalCommitTypes.types);
1112

13+
export function isBotIgnored() {
14+
const botsIgnore = getInput('bots_ignore').split(',');
15+
return botsIgnore.includes(context.actor);
16+
}
17+
1218
export function getConventionalCommitTypes(): string {
1319
return types
1420
.map(type => {
@@ -28,8 +34,12 @@ export async function lintPullRequest(title: string) {
2834
}
2935

3036
export async function lint() {
31-
const pr = await getPullRequest();
37+
if (isBotIgnored()) {
38+
info('Bot is ignored. Skipping linting.');
39+
return;
40+
}
3241

42+
const pr = await getPullRequest();
3343
const isPrTitleOk = await lintPullRequest(pr.title);
3444

3545
if (isPrTitleOk) {

0 commit comments

Comments
 (0)