diff --git a/.node-version b/.node-version deleted file mode 100644 index ec101ca..0000000 --- a/.node-version +++ /dev/null @@ -1 +0,0 @@ -12.20.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 41d1297..4eb0d7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [1.3.0](https://github.com/jef/conventional-commits-pr-action/compare/v1.2.0...v1.3.0) (2024-12-11) + + +### Features + +* 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)) + +## [1.2.0](https://github.com/jef/conventional-commits-pr-action/compare/v1.1.1...v1.2.0) (2024-12-11) + + +### Features + +* 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)) + ### [1.1.1](https://github.com/jef/conventional-commits-pr-action/compare/v1.1.0...v1.1.1) (2022-03-22) diff --git a/README.md b/README.md index 11f7ffe..7c1d357 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ jobs: ## Inputs +### `bots_ignore` + +**Optional** A list of bots to ignore when linting the pull request title. Can be a comma-separated list. + ### `comment` **Optional** Post a comment in the pull request conversation with examples. @@ -43,7 +47,8 @@ jobs: | Default value | `true` | |---------------|--------| -**Note**: commenting in the pull request conversation requires that the token is configured with the `pull-requests` permission. +> [!NOTE] +> Commenting in the pull request conversation requires that the token is configured with the `pull-requests` permission. ### `token` diff --git a/action.yaml b/action.yaml index 72709cf..661c3fd 100644 --- a/action.yaml +++ b/action.yaml @@ -4,6 +4,10 @@ branding: icon: align-left color: blue inputs: + bots_ignore: + required: false + description: A list of bots to ignore when linting the pull request title. Can be a comma-separated list. + default: '' comment: required: false description: Post a comment in the pull request conversation with examples. diff --git a/jest.config.js b/jest.config.js index 107397f..a4c0f9e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,6 @@ /** @type {import('ts-jest').JestConfigWithTsJest} **/ module.exports = { + collectCoverage: true, testEnvironment: 'node', transform: { '^.+.tsx?$': ['ts-jest', {}], diff --git a/package-lock.json b/package-lock.json index fa162c3..2ad940c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@jef/conventional-commits-pr-action", - "version": "1.1.1", + "version": "1.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@jef/conventional-commits-pr-action", - "version": "1.1.1", + "version": "1.3.0", "dependencies": { "@actions/core": "^1.11.1", "@actions/github": "^6.0.0", diff --git a/package.json b/package.json index f14165d..9a826d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jef/conventional-commits-pr-action", - "version": "1.1.1", + "version": "1.3.0", "private": true, "description": "Lints pull requests based on Conventional Commits and Jira tickets", "main": "./src/main.ts", diff --git a/src/__tests__/lint.test.ts b/src/__tests__/lint.test.ts index 518e245..04c5bef 100644 --- a/src/__tests__/lint.test.ts +++ b/src/__tests__/lint.test.ts @@ -1,7 +1,14 @@ -import {getConventionalCommitTypes, lintPullRequest} from '../lint'; +import { + getConventionalCommitTypes, + lintPullRequest, + isBotIgnored, +} from '../lint'; +import {getInput} from '@actions/core'; + +jest.mock('@actions/core'); describe('getConvetionalCommitTypes tests', () => { - it('should return types', () => { + test('should return types', () => { const types = getConventionalCommitTypes(); expect( @@ -30,8 +37,26 @@ describe('lintPullRequest tests', () => { ]; tests.forEach(({args, expected}) => { - it(`should pass or fail linting ['${args}', '${expected}']`, async () => { + test(`should pass or fail linting ['${args}', '${expected}']`, async () => { expect(await lintPullRequest(args)).toBe(expected); }); }); }); + +jest.mock('@actions/github', () => ({ + context: { + actor: 'test-bot', + }, +})); + +describe('isBotIgnored tests', () => { + test('should return true if the bot is in the ignore list', () => { + (getInput as jest.Mock).mockReturnValue('test-bot,another-bot'); + expect(isBotIgnored()).toBe(true); + }); + + test('should return false if the bot is not in the ignore list', () => { + (getInput as jest.Mock).mockReturnValue('another-bot'); + expect(isBotIgnored()).toBe(false); + }); +}); diff --git a/src/lint.ts b/src/lint.ts index 260779a..fb7c170 100644 --- a/src/lint.ts +++ b/src/lint.ts @@ -5,10 +5,16 @@ import { getPullRequest, } from './github'; import * as conventionalCommitTypes from 'conventional-commit-types'; -import {getInput} from '@actions/core'; +import {getInput, info} from '@actions/core'; +import {context} from '@actions/github'; const types = Object.keys(conventionalCommitTypes.types); +export function isBotIgnored() { + const botsIgnore = getInput('bots_ignore').split(','); + return botsIgnore.includes(context.actor); +} + export function getConventionalCommitTypes(): string { return types .map(type => { @@ -28,8 +34,12 @@ export async function lintPullRequest(title: string) { } export async function lint() { - const pr = await getPullRequest(); + if (isBotIgnored()) { + info('Bot is ignored. Skipping linting.'); + return; + } + const pr = await getPullRequest(); const isPrTitleOk = await lintPullRequest(pr.title); if (isPrTitleOk) {