Skip to content

Commit

Permalink
feat: add bots_ignore input
Browse files Browse the repository at this point in the history
  • Loading branch information
jef committed Dec 11, 2024
1 parent 30540d3 commit 89fbbdb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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.
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
collectCoverage: true,
testEnvironment: 'node',
transform: {
'^.+.tsx?$': ['ts-jest', {}],
Expand Down
27 changes: 26 additions & 1 deletion src/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
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', () => {
Expand Down Expand Up @@ -35,3 +42,21 @@ describe('lintPullRequest tests', () => {
});
});
});

jest.mock('@actions/github', () => ({
context: {
actor: 'test-bot',
},
}));

describe('isBotIgnored tests', () => {
it('should return true if the bot is in the ignore list', () => {
(getInput as jest.Mock).mockReturnValue('test-bot,another-bot');
expect(isBotIgnored()).toBe(true);
});

it('should return false if the bot is not in the ignore list', () => {
(getInput as jest.Mock).mockReturnValue('another-bot');
expect(isBotIgnored()).toBe(false);
});
});
14 changes: 13 additions & 1 deletion src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ 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 => {
Expand All @@ -28,6 +35,11 @@ export async function lintPullRequest(title: string) {
}

export async function lint() {
if (isBotIgnored()) {
info('Bot is ignored. Skipping linting.');
return;
}

const pr = await getPullRequest();

const isPrTitleOk = await lintPullRequest(pr.title);
Expand Down

0 comments on commit 89fbbdb

Please sign in to comment.