-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# dist | ||
dist | ||
|
||
# commited dist files | ||
!packages/commitlint/dist | ||
|
||
# dependencies | ||
node_modules | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
var github = require('@actions/github'); | ||
var core = require('@actions/core'); | ||
var process = require('process'); | ||
var fs = require('fs'); | ||
var load = require('@commitlint/load'); | ||
var lint = require('@commitlint/lint'); | ||
|
||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
|
||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n.default = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
var github__namespace = /*#__PURE__*/_interopNamespace(github); | ||
var process__default = /*#__PURE__*/_interopDefault(process); | ||
var fs__namespace = /*#__PURE__*/_interopNamespace(fs); | ||
var load__default = /*#__PURE__*/_interopDefault(load); | ||
var lint__default = /*#__PURE__*/_interopDefault(lint); | ||
|
||
// src/index.ts | ||
function handleError(err, fail = true) { | ||
if (err instanceof Error) { | ||
core.error(err); | ||
fail && core.setFailed(err.message); | ||
} else { | ||
const message = typeof err == "string" ? err : "Unknown error has occurred!"; | ||
core.error(message); | ||
fail && core.setFailed(message); | ||
} | ||
} | ||
var errHandle_default = handleError; | ||
|
||
// src/log.ts | ||
var SEPARATOR = "====================="; | ||
function logWithTile(title, content) { | ||
return `${title} | ||
${SEPARATOR} | ||
${content}`; | ||
} | ||
var log_default = logWithTile; | ||
|
||
// src/lint.ts | ||
var defaultConfig = { | ||
extends: "@commitlint/config-conventional" | ||
}; | ||
function getLintOptions(configuration) { | ||
var _a; | ||
return { | ||
defaultIgnores: configuration.defaultIgnores ? configuration.defaultIgnores : true, | ||
ignores: configuration.ignores ? configuration.ignores : void 0, | ||
parserOpts: typeof ((_a = configuration.parserPreset) == null ? void 0 : _a.parserOpts) == "object" ? configuration.parserPreset.parserOpts : void 0, | ||
plugins: configuration.plugins ? configuration.plugins : void 0, | ||
helpUrl: configuration.helpUrl ? configuration.helpUrl : void 0 | ||
}; | ||
} | ||
async function verifyTitle(title, configPath = "") { | ||
const commitlintConfig = fs__namespace.existsSync(configPath) ? await load__default.default({}, { file: configPath, cwd: process__default.default.cwd() }) : await load__default.default(defaultConfig); | ||
const linterResult = await lint__default.default(title, commitlintConfig.rules, getLintOptions(commitlintConfig)); | ||
if (linterResult.valid) { | ||
return true; | ||
} else { | ||
const errors = linterResult.errors.map((error2) => { | ||
return `${error2.name}: ${error2.message}`; | ||
}).join("\n"); | ||
throw new Error(log_default("Commitlint check failed!", errors)); | ||
} | ||
} | ||
|
||
// src/index.ts | ||
async function run() { | ||
const pullRequestPayload = github__namespace.context.payload.pull_request; | ||
if (!(pullRequestPayload == null ? void 0 : pullRequestPayload.title)) | ||
throw new Error("Pull Request or Title not found!"); | ||
const pullRequestObject = { | ||
title: pullRequestPayload.title, | ||
number: pullRequestPayload.number | ||
}; | ||
await verifyTitle(pullRequestObject.title, "commitlint.config.js"); | ||
} | ||
run().catch(errHandle_default); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as github from '@actions/github'; | ||
import { error, setFailed } from '@actions/core'; | ||
import process from 'process'; | ||
import * as fs from 'fs'; | ||
import load from '@commitlint/load'; | ||
import lint from '@commitlint/lint'; | ||
|
||
// src/index.ts | ||
function handleError(err, fail = true) { | ||
if (err instanceof Error) { | ||
error(err); | ||
fail && setFailed(err.message); | ||
} else { | ||
const message = typeof err == "string" ? err : "Unknown error has occurred!"; | ||
error(message); | ||
fail && setFailed(message); | ||
} | ||
} | ||
var errHandle_default = handleError; | ||
|
||
// src/log.ts | ||
var SEPARATOR = "====================="; | ||
function logWithTile(title, content) { | ||
return `${title} | ||
${SEPARATOR} | ||
${content}`; | ||
} | ||
var log_default = logWithTile; | ||
|
||
// src/lint.ts | ||
var defaultConfig = { | ||
extends: "@commitlint/config-conventional" | ||
}; | ||
function getLintOptions(configuration) { | ||
var _a; | ||
return { | ||
defaultIgnores: configuration.defaultIgnores ? configuration.defaultIgnores : true, | ||
ignores: configuration.ignores ? configuration.ignores : void 0, | ||
parserOpts: typeof ((_a = configuration.parserPreset) == null ? void 0 : _a.parserOpts) == "object" ? configuration.parserPreset.parserOpts : void 0, | ||
plugins: configuration.plugins ? configuration.plugins : void 0, | ||
helpUrl: configuration.helpUrl ? configuration.helpUrl : void 0 | ||
}; | ||
} | ||
async function verifyTitle(title, configPath = "") { | ||
const commitlintConfig = fs.existsSync(configPath) ? await load({}, { file: configPath, cwd: process.cwd() }) : await load(defaultConfig); | ||
const linterResult = await lint(title, commitlintConfig.rules, getLintOptions(commitlintConfig)); | ||
if (linterResult.valid) { | ||
return true; | ||
} else { | ||
const errors = linterResult.errors.map((error2) => { | ||
return `${error2.name}: ${error2.message}`; | ||
}).join("\n"); | ||
throw new Error(log_default("Commitlint check failed!", errors)); | ||
} | ||
} | ||
|
||
// src/index.ts | ||
async function run() { | ||
const pullRequestPayload = github.context.payload.pull_request; | ||
if (!(pullRequestPayload == null ? void 0 : pullRequestPayload.title)) | ||
throw new Error("Pull Request or Title not found!"); | ||
const pullRequestObject = { | ||
title: pullRequestPayload.title, | ||
number: pullRequestPayload.number | ||
}; | ||
await verifyTitle(pullRequestObject.title, "commitlint.config.js"); | ||
} | ||
run().catch(errHandle_default); |