Skip to content

Commit b83c525

Browse files
committed
feat: add bots_ignore input
1 parent b584084 commit b83c525

File tree

9 files changed

+68
-10
lines changed

9 files changed

+68
-10
lines changed

.node-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [1.3.0](https://github.com/jef/conventional-commits-pr-action/compare/v1.2.0...v1.3.0) (2024-12-11)
4+
5+
6+
### Features
7+
8+
* add bots_ignore input ([#231](https://github.com/jef/conventional-commits-pr-action/issues/231)) ([6a6c1c4](https://github.com/jef/conventional-commits-pr-action/commit/6a6c1c4e9d224ea5ee12911040d5983c028fe9a6))
9+
10+
## [1.2.0](https://github.com/jef/conventional-commits-pr-action/compare/v1.1.1...v1.2.0) (2024-12-11)
11+
12+
13+
### Features
14+
15+
* update node, deps, testing ([#229](https://github.com/jef/conventional-commits-pr-action/issues/229)) ([774e6b8](https://github.com/jef/conventional-commits-pr-action/commit/774e6b82d68662745722538184f979fb0dba9561))
16+
317
### [1.1.1](https://github.com/jef/conventional-commits-pr-action/compare/v1.1.0...v1.1.1) (2022-03-22)
418

519

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ jobs:
3636
3737
## Inputs
3838
39+
### `bots_ignore`
40+
41+
**Optional** A list of bots to ignore when linting the pull request title. Can be a comma-separated list.
42+
3943
### `comment`
4044

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

4347
| Default value | `true` |
4448
|---------------|--------|
4549

46-
**Note**: commenting in the pull request conversation requires that the token is configured with the `pull-requests` permission.
50+
> [!NOTE]
51+
> Commenting in the pull request conversation requires that the token is configured with the `pull-requests` permission.
4752

4853
### `token`
4954

action.yaml

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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', {}],

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jef/conventional-commits-pr-action",
3-
"version": "1.1.1",
3+
"version": "1.3.0",
44
"private": true,
55
"description": "Lints pull requests based on Conventional Commits and Jira tickets",
66
"main": "./src/main.ts",

src/__tests__/lint.test.ts

Lines changed: 28 additions & 3 deletions
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

Lines changed: 12 additions & 2 deletions
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)