From 106550d9485f8f1b96fffcba698d2b28dcd5b95c Mon Sep 17 00:00:00 2001 From: Daniel Paschke Date: Wed, 24 Nov 2021 12:41:37 +0100 Subject: [PATCH] feat: make checks optional (#216) --- README.md | 16 ++++++++++++++-- action.yml | 8 ++++++++ package-lock.json | 25 +++++++++++++------------ src/commitlint.ts | 12 +++++++----- src/main.ts | 46 +++++++++++++++++++++++++--------------------- 5 files changed, 67 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 7168088..6546839 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ This github actions checks if a pull request has valid commits by using commitlint -* it will check the title of the PR -* it will check all commits of the PR +* it can check the title of the PR +* it can check all commits of the PR * it will comment on the PR if invalid messages are found. (optional) ## usage @@ -56,3 +56,15 @@ Should commitlint output also valid commits ### `create_comment` (optional) if set to anything the action will comment on the pr with the results. + +### `check_title` (optional) + +if set to false, will skip checking the pr title + +default: true + +### `check_commits` (optional) + +if set to false, will skip checking the commits + +default: true diff --git a/action.yml b/action.yml index 84a5aa9..8331fb4 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,14 @@ inputs: create_comment: required: false description: 'should the action comment on the pr' + check_title: + required: false + description: 'shall the title be checked?' + default: 'true' + check_commits: + required: false + description: 'shall all commits be checked?' + default: 'true' runs: using: docker image: docker://ghcr.io/paschdan/semantic-pullrequest-action:v1 diff --git a/package-lock.json b/package-lock.json index a05358b..161edbe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "semantic-pullrequest-action", "version": "1.5.0", "license": "MIT", "dependencies": { @@ -7650,9 +7651,9 @@ } }, "node_modules/path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "node_modules/path-type": { "version": "2.0.0", @@ -8591,9 +8592,9 @@ } }, "node_modules/tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "node_modules/to-fast-properties": { @@ -15113,9 +15114,9 @@ "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==" }, "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "path-type": { "version": "2.0.0", @@ -15836,9 +15837,9 @@ } }, "tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "to-fast-properties": { diff --git a/src/commitlint.ts b/src/commitlint.ts index 166af3f..a99cb55 100644 --- a/src/commitlint.ts +++ b/src/commitlint.ts @@ -1,8 +1,3 @@ -import load from '@commitlint/load' -import lint from '@commitlint/lint' -import {existsSync} from 'fs' -import {format} from '@commitlint/format' -import {resolve} from 'path' import * as core from '@actions/core' import { LintOptions, @@ -12,6 +7,13 @@ import { QualifiedConfig } from '@commitlint/types' +import {existsSync} from 'fs' +import {format} from '@commitlint/format' + +import lint from '@commitlint/lint' +import load from '@commitlint/load' +import {resolve} from 'path' + function selectParserOpts(parserPreset: ParserPreset): undefined | object { if (typeof parserPreset !== 'object') { return undefined diff --git a/src/main.ts b/src/main.ts index a51a194..adf8229 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,21 +26,22 @@ export async function run(): Promise { const repo = github.context.repo.repo const pull_number = pr.number - const livePr = await octoKit.rest.pulls.get({ - owner, - repo, - pull_number - }) + let output = '' - const prTitle = livePr.data.title + if (core.getBooleanInput('check_title')) { + const livePr = await octoKit.rest.pulls.get({ + owner, + repo, + pull_number + }) - let output = '' + const prTitle = livePr.data.title - const prMessages = [prTitle] + const prMessages = [prTitle] - const prOutput = await commitlint(prMessages) - if (prOutput) { - output += ` + const prOutput = await commitlint(prMessages) + if (prOutput) { + output += ` please fix your pull request title: \`\`\` @@ -49,19 +50,21 @@ ${prOutput} \`\`\` ` + } } - const {data: commits} = await octoKit.rest.pulls.listCommits({ - owner, - repo, - pull_number - }) + if (core.getBooleanInput('check_commits')) { + const {data: commits} = await octoKit.rest.pulls.listCommits({ + owner, + repo, + pull_number + }) - const messages = commits.map(commitEntry => commitEntry.commit.message) + const messages = commits.map(commitEntry => commitEntry.commit.message) - const commitOutput = await commitlint(messages) - if (commitOutput) { - output += ` + const commitOutput = await commitlint(messages) + if (commitOutput) { + output += ` please fix your commits: \`\`\` @@ -70,10 +73,11 @@ ${commitOutput} \`\`\` ` + } } if (output) { - if (core.getInput('create_comment')) { + if (core.getBooleanInput('create_comment')) { octoKit.rest.issues.createComment({ owner, repo,