mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
Merge pull request #95 from wagoid/style/add-eslint-config
style: add eslint to the project
This commit is contained in:
commit
bd679b42e8
12 changed files with 2380 additions and 37 deletions
|
|
@ -7,3 +7,4 @@ coverage
|
||||||
fixtures
|
fixtures
|
||||||
src/action.test.js
|
src/action.test.js
|
||||||
src/testUtils.js
|
src/testUtils.js
|
||||||
|
.eslintrc.json
|
||||||
|
|
|
||||||
10
.eslintrc.json
Normal file
10
.eslintrc.json
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"extends": ["airbnb-base", "prettier", "plugin:node/recommended"],
|
||||||
|
"plugins": ["prettier"],
|
||||||
|
"rules": {
|
||||||
|
"prettier/prettier": "error",
|
||||||
|
"no-console": "off",
|
||||||
|
"no-process-exit": "off",
|
||||||
|
"node/no-unpublished-require": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
|
|
@ -2,8 +2,8 @@ name: CI
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
sanity-checks:
|
||||||
name: Test
|
name: Sanity Checks
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
@ -19,9 +19,10 @@ jobs:
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
- run: npm install
|
- run: npm install
|
||||||
|
- run: npm run lint
|
||||||
- run: npm test -- --ci --coverage
|
- run: npm test -- --ci --coverage
|
||||||
release:
|
release:
|
||||||
needs: test
|
needs: sanity-checks
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: "github.ref == 'refs/heads/master' && !contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
|
if: "github.ref == 'refs/heads/master' && !contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
|
||||||
env:
|
env:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'*.{ts,tsx,vue,css,less,scss,html,htm,md,markdown}': 'prettier --write',
|
'*.{ts,tsx,vue,css,less,scss,html,htm,md,markdown}': 'prettier --write',
|
||||||
'*.{js,jsx,json,yml,yaml}': ['prettier --write', () => 'npm run test'],
|
'*.{json,yml,yaml}': ['prettier --write', () => 'npm run test'],
|
||||||
|
'*.{js,jsx}': ['eslint --fix', () => 'npm run test']],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
const { maxLineLength } = require('@commitlint/ensure')
|
const { maxLineLength } = require('@commitlint/ensure')
|
||||||
|
|
||||||
const bodyMaxLineLength = 100
|
const bodyMaxLineLength = 100
|
||||||
|
|
||||||
const validateBodyMaxLengthIgnoringDeps = parsedCommit => {
|
const validateBodyMaxLengthIgnoringDeps = (parsedCommit) => {
|
||||||
const { type, scope, body } = parsedCommit
|
const { type, scope, body } = parsedCommit
|
||||||
const isDepsCommit =
|
const isDepsCommit =
|
||||||
type === 'chore' && (scope === 'deps' || scope === 'deps-dev')
|
type === 'chore' && (scope === 'deps' || scope === 'deps-dev')
|
||||||
|
|
|
||||||
2322
package-lock.json
generated
2322
package-lock.json
generated
File diff suppressed because it is too large
Load diff
13
package.json
13
package.json
|
|
@ -6,7 +6,11 @@
|
||||||
"main": "run.js",
|
"main": "run.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "NODE_PATH=./node_modules jest",
|
"test": "NODE_PATH=./node_modules jest",
|
||||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
||||||
|
"lint": "eslint --ignore-path .gitignore ."
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.0.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
@ -39,6 +43,13 @@
|
||||||
"@commitlint/test-environment": "^9.0.1",
|
"@commitlint/test-environment": "^9.0.1",
|
||||||
"commitlint-plugin-function-rules": "^1.1.20",
|
"commitlint-plugin-function-rules": "^1.1.20",
|
||||||
"conventional-changelog-cli": "^2.1.1",
|
"conventional-changelog-cli": "^2.1.1",
|
||||||
|
"eslint": "^7.20.0",
|
||||||
|
"eslint-config-airbnb-base": "^14.2.1",
|
||||||
|
"eslint-config-node": "^4.1.0",
|
||||||
|
"eslint-config-prettier": "^7.2.0",
|
||||||
|
"eslint-plugin-import": "^2.22.1",
|
||||||
|
"eslint-plugin-node": "^11.1.0",
|
||||||
|
"eslint-plugin-prettier": "^3.3.1",
|
||||||
"husky": "^5.0.9",
|
"husky": "^5.0.9",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"lint-staged": "^10.5.4",
|
"lint-staged": "^10.5.4",
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ const configPath = resolve(
|
||||||
|
|
||||||
const { context: eventContext } = github
|
const { context: eventContext } = github
|
||||||
|
|
||||||
const pushEventHasOnlyOneCommit = from => {
|
const pushEventHasOnlyOneCommit = (from) => {
|
||||||
const gitEmptySha = '0000000000000000000000000000000000000000'
|
const gitEmptySha = '0000000000000000000000000000000000000000'
|
||||||
|
|
||||||
return from === gitEmptySha
|
return from === gitEmptySha
|
||||||
|
|
@ -54,7 +54,7 @@ const getRangeForEvent = async () => {
|
||||||
repo,
|
repo,
|
||||||
pull_number: number,
|
pull_number: number,
|
||||||
})
|
})
|
||||||
const commitShas = commits.map(commit => commit.sha)
|
const commitShas = commits.map((commit) => commit.sha)
|
||||||
const [from] = commitShas
|
const [from] = commitShas
|
||||||
const to = commitShas[commitShas.length - 1]
|
const to = commitShas[commitShas.length - 1]
|
||||||
// Git revision range doesn't include the "from" field in "git log", so for "from" we use the parent commit of PR's first commit
|
// Git revision range doesn't include the "from" field in "git log", so for "from" we use the parent commit of PR's first commit
|
||||||
|
|
@ -93,25 +93,25 @@ function getOptsFromConfig(config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatErrors = lintedCommits =>
|
const formatErrors = (lintedCommits) =>
|
||||||
format(
|
format(
|
||||||
{ results: lintedCommits.map(commit => commit.lintResult) },
|
{ results: lintedCommits.map((commit) => commit.lintResult) },
|
||||||
{
|
{
|
||||||
color: true,
|
color: true,
|
||||||
helpUrl: core.getInput('helpURL'),
|
helpUrl: core.getInput('helpURL'),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const hasOnlyWarnings = lintedCommits =>
|
const hasOnlyWarnings = (lintedCommits) =>
|
||||||
lintedCommits.length &&
|
lintedCommits.length &&
|
||||||
lintedCommits.every(({ lintResult }) => lintResult.valid) &&
|
lintedCommits.every(({ lintResult }) => lintResult.valid) &&
|
||||||
lintedCommits.some(({ lintResult }) => lintResult.warnings.length)
|
lintedCommits.some(({ lintResult }) => lintResult.warnings.length)
|
||||||
|
|
||||||
const setFailed = formattedResults => {
|
const setFailed = (formattedResults) => {
|
||||||
core.setFailed(`You have commit messages with errors\n\n${formattedResults}`)
|
core.setFailed(`You have commit messages with errors\n\n${formattedResults}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnlyWarnings = formattedResults => {
|
const handleOnlyWarnings = (formattedResults) => {
|
||||||
if (core.getInput('failOnWarnings') === 'true') {
|
if (core.getInput('failOnWarnings') === 'true') {
|
||||||
setFailed(formattedResults)
|
setFailed(formattedResults)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -126,7 +126,7 @@ const showLintResults = async ([from, to]) => {
|
||||||
: await load({ extends: ['@commitlint/config-conventional'] })
|
: await load({ extends: ['@commitlint/config-conventional'] })
|
||||||
const opts = getOptsFromConfig(config)
|
const opts = getOptsFromConfig(config)
|
||||||
const lintedCommits = await Promise.all(
|
const lintedCommits = await Promise.all(
|
||||||
commits.map(async commit => ({
|
commits.map(async (commit) => ({
|
||||||
lintResult: await lint(commit.message, config.rules, opts),
|
lintResult: await lint(commit.message, config.rules, opts),
|
||||||
hash: commit.hash,
|
hash: commit.hash,
|
||||||
})),
|
})),
|
||||||
|
|
@ -144,7 +144,7 @@ const showLintResults = async ([from, to]) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const exitWithMessage = message => error => {
|
const exitWithMessage = (message) => (error) => {
|
||||||
core.setFailed(`${message}\n${error.message}\n${error.stack}`)
|
core.setFailed(`${message}\n${error.message}\n${error.stack}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
/* eslint-disable global-require */
|
||||||
|
/* eslint-env jest */
|
||||||
const { git } = require('@commitlint/test')
|
const { git } = require('@commitlint/test')
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
const td = require('testdouble')
|
const td = require('testdouble')
|
||||||
const {
|
const {
|
||||||
updateEnvVars,
|
|
||||||
gitEmptyCommit,
|
gitEmptyCommit,
|
||||||
getCommitHashes,
|
getCommitHashes,
|
||||||
updatePushEnvVars,
|
updatePushEnvVars,
|
||||||
|
|
@ -147,7 +148,7 @@ describe('Commit Linter action', () => {
|
||||||
await gitEmptyCommit(cwd, 'message from before push')
|
await gitEmptyCommit(cwd, 'message from before push')
|
||||||
await gitEmptyCommit(cwd, 'wrong message 1')
|
await gitEmptyCommit(cwd, 'wrong message 1')
|
||||||
await gitEmptyCommit(cwd, 'chore(WRONG): message 2')
|
await gitEmptyCommit(cwd, 'chore(WRONG): message 2')
|
||||||
const [before, , to] = await getCommitHashes(cwd)
|
const [, , to] = await getCommitHashes(cwd)
|
||||||
await createPushEventPayload(cwd, { before: gitEmptySha, to })
|
await createPushEventPayload(cwd, { before: gitEmptySha, to })
|
||||||
updatePushEnvVars(cwd, to)
|
updatePushEnvVars(cwd, to)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
@ -281,7 +282,7 @@ describe('Commit Linter action', () => {
|
||||||
pull_number: '1',
|
pull_number: '1',
|
||||||
}),
|
}),
|
||||||
).thenResolve({
|
).thenResolve({
|
||||||
data: [first, to].map(sha => ({ sha })),
|
data: [first, to].map((sha) => ({ sha })),
|
||||||
})
|
})
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ const core = require('@actions/core')
|
||||||
|
|
||||||
const resultsOutputId = 'results'
|
const resultsOutputId = 'results'
|
||||||
|
|
||||||
const mapMessageValidation = item => item.message
|
const mapMessageValidation = (item) => item.message
|
||||||
|
|
||||||
const mapResultOutput = ({
|
const mapResultOutput = ({
|
||||||
hash,
|
hash,
|
||||||
|
|
@ -15,7 +15,7 @@ const mapResultOutput = ({
|
||||||
warnings: warnings.map(mapMessageValidation),
|
warnings: warnings.map(mapMessageValidation),
|
||||||
})
|
})
|
||||||
|
|
||||||
const generateOutputs = lintedCommits => {
|
const generateOutputs = (lintedCommits) => {
|
||||||
const resultsOutput = lintedCommits.map(mapResultOutput)
|
const resultsOutput = lintedCommits.map(mapResultOutput)
|
||||||
|
|
||||||
core.setOutput(resultsOutputId, resultsOutput)
|
core.setOutput(resultsOutputId, resultsOutput)
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@ const hashDelimiter = '--------->hash---------'
|
||||||
|
|
||||||
const format = `%H${hashDelimiter}%B%n${commitDelimiter}`
|
const format = `%H${hashDelimiter}%B%n${commitDelimiter}`
|
||||||
|
|
||||||
const buildGitArgs = gitOpts => {
|
const buildGitArgs = (gitOpts) => {
|
||||||
const { from, to, ...otherOpts } = gitOpts
|
const { from, to, ...otherOpts } = gitOpts
|
||||||
var formatArg = `--format=${format}`
|
const formatArg = `--format=${format}`
|
||||||
var fromToArg = [from, to].filter(Boolean).join('..')
|
const fromToArg = [from, to].filter(Boolean).join('..')
|
||||||
|
|
||||||
var gitArgs = ['log', formatArg, fromToArg]
|
const gitArgs = ['log', formatArg, fromToArg]
|
||||||
|
|
||||||
return gitArgs.concat(
|
return gitArgs.concat(
|
||||||
dargs(gitOpts, {
|
dargs(gitOpts, {
|
||||||
|
|
@ -21,14 +21,14 @@ const buildGitArgs = gitOpts => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitCommits = async gitOpts => {
|
const gitCommits = async (gitOpts) => {
|
||||||
var args = buildGitArgs(gitOpts)
|
const args = buildGitArgs(gitOpts)
|
||||||
|
|
||||||
var { stdout } = await execa('git', args, {
|
const { stdout } = await execa('git', args, {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const commits = stdout.split(`${commitDelimiter}\n`).map(messageItem => {
|
const commits = stdout.split(`${commitDelimiter}\n`).map((messageItem) => {
|
||||||
const [hash, message] = messageItem.split(hashDelimiter)
|
const [hash, message] = messageItem.split(hashDelimiter)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,21 @@ const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const { promisify } = require('util')
|
const { promisify } = require('util')
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
const td = require('testdouble')
|
|
||||||
|
|
||||||
const writeFile = promisify(fs.writeFile)
|
const writeFile = promisify(fs.writeFile)
|
||||||
|
|
||||||
const updateEnvVars = (exports.updateEnvVars = envVars => {
|
const updateEnvVars = (envVars) => {
|
||||||
Object.keys(envVars).forEach(key => {
|
Object.keys(envVars).forEach((key) => {
|
||||||
process.env[key] = envVars[key]
|
process.env[key] = envVars[key]
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
|
exports.updateEnvVars = updateEnvVars
|
||||||
|
|
||||||
exports.gitEmptyCommit = (cwd, message) =>
|
exports.gitEmptyCommit = (cwd, message) =>
|
||||||
execa('git', ['commit', '--allow-empty', '-m', message], { cwd })
|
execa('git', ['commit', '--allow-empty', '-m', message], { cwd })
|
||||||
|
|
||||||
exports.getCommitHashes = async cwd => {
|
exports.getCommitHashes = async (cwd) => {
|
||||||
const { stdout } = await execa.command('git log --pretty=%H', { cwd })
|
const { stdout } = await execa.command('git log --pretty=%H', { cwd })
|
||||||
const hashes = stdout.split('\n').reverse()
|
const hashes = stdout.split('\n').reverse()
|
||||||
|
|
||||||
|
|
@ -45,7 +46,7 @@ exports.createPushEventPayload = async (
|
||||||
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createPullRequestEventPayload = async cwd => {
|
exports.createPullRequestEventPayload = async (cwd) => {
|
||||||
const payload = {
|
const payload = {
|
||||||
number: '1',
|
number: '1',
|
||||||
repository: {
|
repository: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue