Skip to content
This repository was archived by the owner on Aug 2, 2024. It is now read-only.

Commit 11bc0e3

Browse files
authored
Regex string can now be an array (#23)
1 parent 9953995 commit 11bc0e3

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sourcemap-register.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample_workflow.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ jobs:
66
verify:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: aws-actions/pr-regex-exclude@<commit_sha>
9+
- uses: aws-actions/pr-regex-exclude@main
1010
with:
11-
exclude-regex: '<your JS RegEx syntax here>'
11+
# You will need to specify a regular expression in the syntax here:
12+
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
13+
#
14+
# This is a string pattern, not a RegExp literal.
15+
# GitHub does not support an array or list as inputs to actions, so
16+
# for multiple paths, either use the | (pipe) character, or specify
17+
# a JSON array of regular expressions:
18+
# '(dist/(.*)\.js)|(\.editorconfig)'
19+
# '["dist/(.*)\.js","\.editorconfig"]'
20+
exclude-regex: '<your RegExp here>'
1221
repo-token: ${{ secrets.GITHUB_TOKEN }}
1322
message: |
14-
Thank you for submitting this PR, but it appears that at least one file in this
15-
request is against a part of our codebase that does not accept pull requests.
23+
Thank you for submitting this PR, but it appears that at least one file in this request is against a part of our codebase that does not accept pull requests.
24+
1625
Please check the [contributing guide](./CONTRIBUTING.md) for more information.
26+
1727
I am a bot; this action was performed automatically.

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import * as core from '@actions/core';
22
import * as github from '@actions/github';
33
import {closeAndCommentPR} from './close-and-comment';
44
import {processDiffUrl} from './process-diff';
5+
import {parseRegex} from './regex';
56

67
async function run(): Promise<void> {
78
try {
8-
const exemptRegex = new RegExp(
9+
const exemptRegex = parseRegex(
910
core.getInput('exclude-regex', {required: true})
1011
);
1112
const token = core.getInput('repo-token');
1213
const message = core.getInput('message', {required: true});
1314

15+
core.debug(`Your regex is ${exemptRegex}`);
16+
1417
if (github.context.payload.pull_request === undefined) {
1518
core.setFailed('Trigger not a pull request');
1619
return;

src/regex.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function isJsonArray(token: string): boolean {
2+
try {
3+
if (Array.isArray(JSON.parse(token))) {
4+
return true;
5+
}
6+
} catch (err) {
7+
return false;
8+
}
9+
return false;
10+
}
11+
12+
export function parseRegex(token: string): RegExp {
13+
if (isJsonArray(token)) {
14+
return new RegExp(`(${JSON.parse(token).join(')|(')})`);
15+
} else {
16+
return new RegExp(token);
17+
}
18+
}

0 commit comments

Comments
 (0)