Skip to content

Commit

Permalink
Merge pull request #7 from matmar10/options-rules
Browse files Browse the repository at this point in the history
feat: allow specifying rules in file
  • Loading branch information
matmar10 authored Oct 19, 2021
2 parents d292160 + b82a9e0 commit 5c7728d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/prclintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": {
"body-max-line-length": [0, "always", 100],
"references-empty": [2, "always"]
}
}
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ jobs:
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}
rules: '{ "body-max-line-length": [0, "always", 100] }'
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
token:
description: A token with access to your repository scoped in as a secret
required: true
config_path:
description: Path to configuration file
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
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const lintLib = require('@commitlint/lint');
const config = require('@commitlint/config-conventional');
const defaultConfig = require('@commitlint/config-conventional');
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');

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

async function run() {
try {
const token = core.getInput('token', { required: true });
const token = core.getInput('token', { required: true });{
const configPath = core.getInput('config_path', { required: true });
const config = fs.existsSync(configPath) ? require(configPath) : {};

const rulesRaw = core.getInput('rules');
const rules = rulesRaw ? JSON.parse(rulesRaw) : {};

Expand All @@ -32,6 +36,7 @@ async function run() {
}

const ruleSet = {
...defaultConfig.rules,
...config.rules,
...rules
};
Expand Down

0 comments on commit 5c7728d

Please sign in to comment.