Skip to content

Commit a3b6386

Browse files
committed
Fix commit message body blank lines
1 parent ff2b83d commit a3b6386

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Dominik Aschbacher
3+
Copyright (c) 2021 Dominik Aschbacher
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
name: GitLint
2222
steps:
2323
- name: Lint commits, branches, and pull requests
24-
uses: aschbacd/[email protected].0
24+
uses: aschbacd/[email protected].1
2525
with:
2626
github-token: ${{ secrets.GITHUB_TOKEN }}
2727
commit-message-body-max-length: 72
@@ -43,6 +43,7 @@ The following input keys can be used in your GitHub Actions workflow (shown abov
4343
| commit-message-subject-max-length | Max. characters for commit message subject | -1 (disabled) | 50 |
4444
| commit-message-subject-min-length | Min. characters for commit message subject | -1 (disabled) | -1 (disabled) |
4545
| github-token | Token used to authenticate against GitHub api | `-` | `${{ secrets.GITHUB_TOKEN }}` |
46+
| prohibit-blank-lines-cm-body | Commit message body cannot include blank lines | `false` | `false` |
4647
| prohibit-unknown-commit-authors | Commit author must be GitHub user | `false` | `true` |
4748
| prohibit-unknown-commit-committers | Commit committer must be GitHub user | `false` | `true` |
4849
| prohibit-unsigned-commits | Commits without a valid signature are invalid | `false` | `false` |

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
github-token:
2424
description: "GitHub token used to access api"
2525
required: true
26+
prohibit-blank-lines-cm-body:
27+
description: "Prohibit blank lines in commit message body"
28+
required: false
29+
default: false
2630
prohibit-unknown-commit-authors:
2731
description: "Prohibit commit authors that are not known to GitHub"
2832
required: false

index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async function run() {
3333
const commitMessageSubjectMaxLength = parseInt(core.getInput('commit-message-subject-max-length'))
3434
const commitMessageSubjectMinLength = parseInt(core.getInput('commit-message-subject-min-length'))
3535

36+
const prohibitBlankLinesCmBody = (core.getInput('prohibit-blank-lines-cm-body') == 'true')
3637
const prohibitUnknownCommitAuthors = (core.getInput('prohibit-unknown-commit-authors') == 'true')
3738
const prohibitUnknownCommitCommitters = (core.getInput('prohibit-unknown-commit-committers') == 'true')
3839
const prohibitUnsignedCommits = (core.getInput('prohibit-unsigned-commits') == 'true')
@@ -73,10 +74,10 @@ async function run() {
7374
core.info(`Commit hash: ${commit.sha}`)
7475
core.info(`Commit author email: ${commit.commit.author.email}`)
7576
core.info(`Commit author name: ${commit.commit.author.name}`)
76-
core.info(`Commit author GitHub account: ${commit.author}`)
77+
core.info(`Commit author GitHub account: ${commit.author == null ? undefined : commit.author.login}`)
7778
core.info(`Commit committer email: ${commit.commit.committer.email}`)
7879
core.info(`Commit committer name: ${commit.commit.committer.name}`)
79-
core.info(`Commit committer GitHub account: ${commit.committer}`)
80+
core.info(`Commit committer GitHub account: ${commit.committer == null ? undefined : commit.committer.login}`)
8081
core.info(`Commit has valid signature: ${commit.commit.verification.verified}`)
8182
core.info(`Commit message subject: ${commitMessageSubject}`)
8283
core.info(`Commit message body: ${commitMessageBody}`)
@@ -118,8 +119,12 @@ async function run() {
118119
// Check commit message body
119120
if (commitMessageBody != null) {
120121
commitMessageBody.split("\n").forEach(function (line, index) {
121-
if (commitMessageBodyMinLength != -1 && line.length < commitMessageBodyMinLength)
122+
if (line.length == 0) {
123+
if (prohibitBlankLinesCmBody)
124+
core.setFailed(`Blank lines are not allowed in commit message body; line ${(index+1).toString()} (${commit.sha.substr(0, 7)})`)
125+
} else if (commitMessageBodyMinLength != -1 && line.length < commitMessageBodyMinLength) {
122126
core.setFailed(`Commit message body line ${(index+1).toString()} is too short (${commit.sha.substr(0, 7)})`)
127+
}
123128

124129
if (commitMessageBodyMaxLength != -1 && line.length > commitMessageBodyMaxLength)
125130
core.setFailed(`Commit message body line ${(index+1).toString()} is too long (${commit.sha.substr(0, 7)})`)

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitlint-action",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "This GitHub Action ensures that your naming conventions for commits, branches, and pull requests are being respected.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)