Skip to content

Commit 5c7728d

Browse files
authored
Merge pull request #7 from matmar10/options-rules
feat: allow specifying rules in file
2 parents d292160 + b82a9e0 commit 5c7728d

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.github/prclintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
"body-max-line-length": [0, "always", 100],
4+
"references-empty": [2, "always"]
5+
}
6+
}

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ jobs:
1616
uses: ./
1717
with:
1818
token: ${{ secrets.GITHUB_TOKEN }}
19-
rules: '{ "body-max-line-length": [0, "always", 100] }'

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ inputs:
77
token:
88
description: A token with access to your repository scoped in as a secret
99
required: true
10+
config_path:
11+
description: Path to configuration file
12+
default: './github/prclintrc.json'
1013
rules:
1114
description: 'Rule set for commit linter. For examples, see https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/index.js'
1215

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22

33
const lintLib = require('@commitlint/lint');
4-
const config = require('@commitlint/config-conventional');
4+
const defaultConfig = require('@commitlint/config-conventional');
55
const core = require('@actions/core');
66
const github = require('@actions/github');
7+
const fs = require('fs');
78

89
const lint = lintLib.default;
910
const rules = config.rules;
@@ -12,7 +13,10 @@ const validEvent = ['pull_request'];
1213

1314
async function run() {
1415
try {
15-
const token = core.getInput('token', { required: true });
16+
const token = core.getInput('token', { required: true });{
17+
const configPath = core.getInput('config_path', { required: true });
18+
const config = fs.existsSync(configPath) ? require(configPath) : {};
19+
1620
const rulesRaw = core.getInput('rules');
1721
const rules = rulesRaw ? JSON.parse(rulesRaw) : {};
1822

@@ -32,6 +36,7 @@ async function run() {
3236
}
3337

3438
const ruleSet = {
39+
...defaultConfig.rules,
3540
...config.rules,
3641
...rules
3742
};

0 commit comments

Comments
 (0)