Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter regex #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ See [action.yml](action.yml)
# Can be 'space-delimited', 'csv', or 'json'.
# Default: 'space-delimited'
format: ''
# Filter files using a regex
filter: '*'
```

# Scenarios
Expand All @@ -36,6 +38,8 @@ Consider using one of the other formats if that's the case.
```yaml
- id: files
uses: jitterbit/get-changed-files@v1
with:
filter: '*.php'
- run: |
for changed_file in ${{ steps.files.outputs.all }}; do
echo "Do something with this ${changed_file}."
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3517,6 +3517,7 @@ function run() {
// Create GitHub client with the API token.
const client = new github_1.GitHub(core.getInput('token', { required: true }));
const format = core.getInput('format', { required: true });
const filter = core.getInput('filter', { required: true }) || '*';
// Ensure that the format parameter is set properly.
if (format !== 'space-delimited' && format !== 'csv' && format !== 'json') {
core.setFailed(`Format must be one of 'string-delimited', 'csv', or 'json', got '${format}'.`);
Expand Down Expand Up @@ -3570,8 +3571,9 @@ function run() {
core.setFailed(`The head commit for this ${github_1.context.eventName} event is not ahead of the base commit. ` +
"Please submit an issue on this action's GitHub repo.");
}
const regex = new RegExp(`/${filter}\\b`, 'g');
// Get the changed files from the response payload.
const files = response.data.files;
const files = response.data.files.filter(file => file.filename.match(regex));
const all = [], added = [], modified = [], removed = [], renamed = [], addedModified = [];
for (const file of files) {
const filename = file.filename;
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function run(): Promise<void> {
// Create GitHub client with the API token.
const client = new GitHub(core.getInput('token', {required: true}))
const format = core.getInput('format', {required: true}) as Format
const filter = core.getInput('filter', {required: true}) || '*'

// Ensure that the format parameter is set properly.
if (format !== 'space-delimited' && format !== 'csv' && format !== 'json') {
Expand Down Expand Up @@ -82,8 +83,9 @@ async function run(): Promise<void> {
)
}

const regex = new RegExp(`/${filter}\\b`, 'g')
// Get the changed files from the response payload.
const files = response.data.files
const files = response.data.files.filter(file => file.filename.match(regex))
const all = [] as string[],
added = [] as string[],
modified = [] as string[],
Expand Down