Skip to content

Commit

Permalink
feat: make checks optional (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
paschdan committed Nov 24, 2021
1 parent 4516e3d commit 106550d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 40 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 13 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/commitlint.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
46 changes: 25 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ export async function run(): Promise<void> {
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:
\`\`\`
Expand All @@ -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:
\`\`\`
Expand All @@ -70,10 +73,11 @@ ${commitOutput}
\`\`\`
`
}
}

if (output) {
if (core.getInput('create_comment')) {
if (core.getBooleanInput('create_comment')) {
octoKit.rest.issues.createComment({
owner,
repo,
Expand Down

0 comments on commit 106550d

Please sign in to comment.