Skip to content

[FEATURE] Add option to exclude the PR description from the check #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
pattern: '^[^#].{74}'
error: 'The maximum line length of 74 characters is exceeded.'
excludeDescription: '1'
- name: Check for Resolves / Fixes
uses: gsactions/commit-message-checker@v1
with:
Expand Down
21 changes: 21 additions & 0 deletions __tests__/input-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ describe('input-helper tests', () => {
expect(checkerArguments.messages[0]).toBe('some-title\n\nsome-body')
})

it('excludes pull_request body payload', () => {
mockGitHub.context = {
eventName: 'pull_request',
payload: {
pull_request: {
title: 'some-title',
body: 'some-body'
}
}
}
inputs.pattern = 'some-pattern'
inputs.error = 'some-error'
inputs.excludeDescription = '1'
const checkerArguments: ICheckerArguments = inputHelper.getInputs()
expect(checkerArguments).toBeTruthy()
expect(checkerArguments.pattern).toBe('some-pattern')
expect(checkerArguments.error).toBe('some-error')
expect(checkerArguments.messages).toBeTruthy()
expect(checkerArguments.messages[0]).toBe('some-title')
})

it('push payload is optional', () => {
mockGitHub.context = {
eventName: 'push',
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
error:
description: 'A error message which will be returned in case of an error.'
required: true
excludeDescription:
description: 'Setting this input to 1 will exclude the Pull Request description from the check.'
required: false
default: ''
runs:
using: node12
main: dist/index.js
Expand Down
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8741,8 +8741,10 @@ function getInputs() {
result.flags = core.getInput('flags');
// Get error message
result.error = core.getInput('error', { required: true });
// Get excludeDescription
const excludeDescription = core.getInput('excludeDescription') !== '';
// Get error message
result.messages = getMessages();
result.messages = getMessages(excludeDescription);
return result;
}
exports.getInputs = getInputs;
Expand All @@ -8752,15 +8754,15 @@ exports.getInputs = getInputs;
*
* @returns string[]
*/
function getMessages() {
function getMessages(excludeDescription) {
const messages = [];
switch (github.context.eventName) {
case 'pull_request': {
if (github.context.payload &&
github.context.payload.pull_request &&
github.context.payload.pull_request.title) {
let message = github.context.payload.pull_request.title;
if (github.context.payload.pull_request.body) {
if (github.context.payload.pull_request.body && !excludeDescription) {
message = message.concat('\n\n', github.context.payload.pull_request.body);
}
messages.push(message);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gsactions/commit-message-checker",
"version": "0.2.0",
"version": "0.3.0",
"description": "GitHub Action that checks commit messages of pushes and pull request against a regex pattern",
"keywords": [
"github",
Expand Down
9 changes: 6 additions & 3 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export function getInputs(): ICheckerArguments {
// Get error message
result.error = core.getInput('error', {required: true})

// Get excludeDescription
const excludeDescription = core.getInput('excludeDescription') !== ''

// Get error message
result.messages = getMessages()
result.messages = getMessages(excludeDescription)

return result
}
Expand All @@ -51,7 +54,7 @@ export function getInputs(): ICheckerArguments {
*
* @returns string[]
*/
function getMessages(): string[] {
function getMessages(excludeDescription: boolean): string[] {
const messages: string[] = []

switch (github.context.eventName) {
Expand All @@ -62,7 +65,7 @@ function getMessages(): string[] {
github.context.payload.pull_request.title
) {
let message: string = github.context.payload.pull_request.title
if (github.context.payload.pull_request.body) {
if (github.context.payload.pull_request.body && !excludeDescription) {
message = message.concat(
'\n\n',
github.context.payload.pull_request.body
Expand Down