8000 [FEATURE] Add option to exclude the PR description from the check (#13) · GsActions/commit-message-checker@39e2a46 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39e2a46

Browse files
authored
[FEATURE] Add option to exclude the PR description from the check (#13)
Resolves #12
1 parent fe66986 commit 39e2a46

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
pattern: '^[^#].{74}'
5555
error: 'The maximum line length of 74 characters is exceeded.'
56+
excludeDescription: '1'
5657
- name: Check for Resolves / Fixes
5758
uses: gsactions/commit-message-checker@v1
5859
with:

__tests__/input-helper.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,27 @@ describe('input-helper tests', () => {
166166
expect(checkerArguments.messages[0]).toBe('some-title\n\nsome-body')
167167
})
168168

169+
it('excludes pull_request body payload', () => {
170+
mockGitHub.context = {
171+
eventName: 'pull_request',
172+
payload: {
173+
pull_request: {
174+
title: 'some-title',
175+
body: 'some-body'
176+
}
177+
}
178+
}
179+
inputs.pattern = 'some-pattern'
180+
inputs.error = 'some-error'
181+
inputs.excludeDescription = '1'
182+
const checkerArguments: ICheckerArguments = inputHelper.getInputs()
183+
expect(checkerArguments).toBeTruthy()
184+
expect(checkerArguments.pattern).toBe('some-pattern')
185+
expect(checkerArguments.error).toBe('some-error')
186+
expect(checkerArguments.messages).toBeTruthy()
187+
expect(checkerArguments.messages[0]).toBe('some-title')
188+
})
189+
169190
it('push payload is optional', () => {
170191
mockGitHub.context = {
171192
eventName: 'push',

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
error:
1313
description: 'A error message which will be returned in case of an error.'
1414
required: true
15+
excludeDescription:
16+
description: 'Setting this input to 1 will exclude the Pull Request description from the check.'
17+
required: false
18+
default: ''
1519
runs:
1620
using: node12
1721
main: dist/index.js

dist/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8741,8 +8741,10 @@ function getInputs() {
87418741
result.flags = core.getInput('flags');
87428742
// Get error message
87438743
result.error = core.getInput('error', { required: true });
8744+
// Get excludeDescription
8745+
const excludeDescription = core.getInput('excludeDescription') !== '';
87448746
// Get error message
8745-
result.messages = getMessages();
8747+
result.messages = getMessages(excludeDescription);
87468748
return result;
87478749
}
87488750
exports.getInputs = getInputs;
@@ -8752,15 +8754,15 @@ exports.getInputs = getInputs;
87528754
*
87538755
* @returns string[]
87548756
*/
8755-
function getMessages() {
8757+
function getMessages(excludeDescription) {
87568758
const messages = [];
87578759
switch (github.context.eventName) {
87588760
case 'pull_request': {
87598761
if (github.context.payload &&
87608762
github.context.payload.pull_request &&
87618763
github.context.payload.pull_request.title) {
87628764
let message = github.context.payload.pull_request.title;
8763-
if (github.context.payload.pull_request.body) {
8765+
if (github.context.payload.pull_request.body && !excludeDescription) {
87648766
message = message.concat('\n\n', github.context.payload.pull_request.body);
87658767
}
87668768
messages.push(message);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gsactions/commit-message-checker",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "GitHub Action that checks commit messages of pushes and pull request against a regex pattern",
55
"keywords": [
66
"github",

src/input-helper.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ export function getInputs(): ICheckerArguments {
3939
// Get error message
4040
result.error = core.getInput('error', {required: true})
4141

42+
// Get excludeDescription
43+
const excludeDescription = core.getInput('excludeDescription') !== ''
44+
4245
// Get error message
43-
result.messages = getMessages()
46+
result.messages = getMessages(excludeDescription)
4447

4548
return result
4649
}
@@ -51,7 +54,7 @@ export function getInputs(): ICheckerArguments {
5154
*
5255
* @returns string[]
5356
*/
54-
function getMessages(): string[] {
57+
function getMessages(excludeDescription: boolean): string[] {
5558
const messages: string[] = []
5659

5760
switch (github.context.eventName) {
@@ -62,7 +65,7 @@ function getMessages(): string[] {
6265
github.context.payload.pull_request.title
6366
) {
6467
let message: string = github.context.payload.pull_request.title
65-
if (github.context.payload.pull_request.body) {
68+
if (github.context.payload.pull_request.body && !excludeDescription) {
6669
message = message.concat(
6770
'\n\n',
6871
github.context.payload.pull_request.body

0 commit comments

Comments
 (0)
0