Skip to content

Commit

Permalink
Merge pull request #9 from matmar10/test-pr
Browse files Browse the repository at this point in the history
fix: test
  • Loading branch information
matmar10 authored Oct 19, 2021
2 parents d910d25 + 825e84b commit ff0991c
Show file tree
Hide file tree
Showing 8 changed files with 11,028 additions and 291 deletions.
75 changes: 75 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"plugins": [
"es-beautifier"
],
"extends": ["eslint:recommended", "plugin:es-beautifier/standard"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "script"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"globals": {},
"rules": {
"strict": [
2,
"global"
],
"quotes": [
2,
"single"
],
"no-undef": 2,
"no-unused-vars": 2,
"one-var": [
2,
{
"initialized": "never",
"uninitialized": "never"
}
],
"curly": 2,
"camelcase": 0,
"eqeqeq": 2,
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"lines-around-comment": [
"error", {
"allowBlockStart": true
}
],
"no-use-before-define": [
2,
{
"functions": false
}
],
"max-len": [
2,
{
"code": 200,
"ignoreComments": true
}
],
"max-statements-per-line": 2,
"new-cap": ["error", {
"properties": false
}],
"no-eq-null": 2,
"no-var": 2,
"one-var-declaration-per-line": 2,
"prefer-const": 2,
"semi": 2,
"spaced-comment": ["error", "always", {
"exceptions": ["-"]
}]
}
}
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## [1.1.0](https://github.com/matmar10/pr-conventional-commit/compare/0.4.0...1.1.0) (2021-10-19)


### Features

* allow specifying rules in file ([66e8ed4](https://github.com/matmar10/pr-conventional-commit/commit/66e8ed46ccb5e5aafd41ed8d02fc500df950bd98))
* allow specifying rules in file ([b82a9e0](https://github.com/matmar10/pr-conventional-commit/commit/b82a9e0cde6ba4b958f1f36aa7f0c74f18b1e3c0))
* specify rules in action ([4880aa2](https://github.com/matmar10/pr-conventional-commit/commit/4880aa25ae120dc87fe47e8ca8681ba7e077fbbf))
* specify rules in action ([0eb0d55](https://github.com/matmar10/pr-conventional-commit/commit/0eb0d55e1f0954038cf344511764218b4bd4ee0b))


### Bug Fixes

* correcty identify config path & load it ([a6a9754](https://github.com/matmar10/pr-conventional-commit/commit/a6a9754238145b2d6e37811891ccfb76437fec92))
* inconsistent github token param ([ee0386b](https://github.com/matmar10/pr-conventional-commit/commit/ee0386b3b0f0a06eeaaabc71e9b0d1b8a88c8657))
* remove overly verbose debug input ([df7c8ed](https://github.com/matmar10/pr-conventional-commit/commit/df7c8ed6d506ae3425ad972672fc02d2ddebdb7a))
* test ([cf046b5](https://github.com/matmar10/pr-conventional-commit/commit/cf046b55b4e85adde8ef97b8dba09a981296b68b))


### Continuous Integration

* add release & lint ([b46f016](https://github.com/matmar10/pr-conventional-commit/commit/b46f016294e20ae39175dc4dff4b211a14f97f39))

## [0.1.0](https://github.com/matmar10/pr-conventional-commit/compare/0.4.0...1.1.0) (2021-10-19)


### Features

* add github PR commit linter action ([70b508b](https://github.com/matmar10/pr-conventional-commit/commit/70b508bbfbe180a26793313cede10a0803a1e6c6))

2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
required: true
config_path:
description: Path to configuration file
default: './github/prclintrc.json'
default: './.github/prclintrc.json'
rules:
description: 'Rule set for commit linter. For examples, see https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/index.js'

Expand Down
37 changes: 24 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1520,60 +1520,72 @@ exports.issueCommand = issueCommand;


const lintLib = __webpack_require__(236);
const config = __webpack_require__(64);
const defaultConfig = __webpack_require__(64);
const core = __webpack_require__(470);
const github = __webpack_require__(861);
const fs = __webpack_require__(747);
const path = __webpack_require__(622);

const lint = lintLib.default;
const rules = config.rules;
const defaultConfigRules = defaultConfig.rules;

const validEvent = ['pull_request'];

async function run() {
try {
const token = core.getInput('token', { required: true });

// load rules from file, if there
const configPath = core.getInput('config_path', { required: true });
// relative to dist/index.js
const filename = path.join(__dirname, '/../', configPath);
const config = fs.existsSync(filename) ? JSON.parse(fs.readFileSync(filename, 'utf8')) : {};
const fileRules = config.rules || {};

// load raw rules from action, if there
const rulesRaw = core.getInput('rules');
const rules = rulesRaw ? JSON.parse(rulesRaw) : {};

const ruleSet = {
...defaultConfigRules,
...fileRules,
...rules,
};

const octokit = new github.getOctokit(token);

const {
eventName,
payload: {
repository: repo,
pull_request: pr
}
pull_request: pr,
},
} = github.context;

if (validEvent.indexOf(eventName) < 0) {
core.error(`Invalid event: ${eventName}`);
return;
}

const ruleSet = {
...config.rules,
...rules
};

const commits = await octokit.rest.pulls.listCommits({
owner: repo.owner.login,
repo: repo.name,
pull_number: pr.number,
});
const reports = await Promise.all(commits.data.map(commit => lint(commit.commit.message, ruleSet)));

const reports = await Promise.all(commits.data.map(commit => lint(commit.commit.message, ruleSet)));
let countErrors = 0;
let countWarnings = 0;
reports.forEach((report, i) => {
const meta = commits.data[i];
const { sha, commit } = meta;
core.startGroup(`Commit "${commit.message}" ${sha.substring(0, 7)} (${commit.author.name} <${commit.author.email}> on ${commit.author.date})`);
if (!report.valid) {
report.errors.forEach(err => {
report.errors.forEach((err) => {
core.error(`Rule '${err.name}': ${err.message} ("${commit.message}")`);
countErrors++;
});
report.warnings.forEach(err => {
report.warnings.forEach((err) => {
core.warning(`Rule '${err.name}': ${err.message} ("${commit.message}")`);
countWarnings++;
});
Expand All @@ -1584,7 +1596,6 @@ async function run() {
if (countErrors) {
core.setFailed(`Action failed with ${countErrors} errors (and ${countWarnings} warnings)`);
}

} catch (error) {
core.setFailed(error.message);
}
Expand Down
37 changes: 21 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,55 @@ const defaultConfig = require('@commitlint/config-conventional');
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const path = require('path');

const lint = lintLib.default;
const rules = config.rules;
const defaultConfigRules = defaultConfig.rules;

const validEvent = ['pull_request'];

async function run() {
try {
const token = core.getInput('token', { required: true });{
const token = core.getInput('token', { required: true });

// load rules from file, if there
const configPath = core.getInput('config_path', { required: true });
const config = fs.existsSync(configPath) ? require(configPath) : {};
// relative to dist/index.js
const filename = path.join(__dirname, '/../', configPath);
const config = fs.existsSync(filename) ? JSON.parse(fs.readFileSync(filename, 'utf8')) : {};
const fileRules = config.rules || {};

// load raw rules from action, if there
const rulesRaw = core.getInput('rules');
const rules = rulesRaw ? JSON.parse(rulesRaw) : {};

const ruleSet = {
...defaultConfigRules,
...fileRules,
...rules,
};

const octokit = new github.getOctokit(token);

const {
eventName,
payload: {
repository: repo,
pull_request: pr
}
pull_request: pr,
},
} = github.context;

if (validEvent.indexOf(eventName) < 0) {
core.error(`Invalid event: ${eventName}`);
return;
}

const ruleSet = {
...defaultConfig.rules,
...config.rules,
...rules
};
console.log('Rules:', ruleSet);

const commits = await octokit.rest.pulls.listCommits({
owner: repo.owner.login,
repo: repo.name,
pull_number: pr.number,
});

const reports = await Promise.all(commits.data.map(commit => lint(commit.commit.message, ruleSet)));
let countErrors = 0;
let countWarnings = 0;
Expand All @@ -56,11 +62,11 @@ async function run() {
const { sha, commit } = meta;
core.startGroup(`Commit "${commit.message}" ${sha.substring(0, 7)} (${commit.author.name} <${commit.author.email}> on ${commit.author.date})`);
if (!report.valid) {
report.errors.forEach(err => {
report.errors.forEach((err) => {
core.error(`Rule '${err.name}': ${err.message} ("${commit.message}")`);
countErrors++;
});
report.warnings.forEach(err => {
report.warnings.forEach((err) => {
core.warning(`Rule '${err.name}': ${err.message} ("${commit.message}")`);
countWarnings++;
});
Expand All @@ -71,7 +77,6 @@ async function run() {
if (countErrors) {
core.setFailed(`Action failed with ${countErrors} errors (and ${countWarnings} warnings)`);
}

} catch (error) {
core.setFailed(error.message);
}
Expand Down
Loading

0 comments on commit ff0991c

Please sign in to comment.