Skip to content

Commit

Permalink
refactor: rename output deleted to removed
Browse files Browse the repository at this point in the history
'removed' is the official name used by GitHub's API. 'deleted' will still be supported for backwards-compatibility, but not mentioned in the docs.
  • Loading branch information
Sean Krail committed Apr 8, 2020
1 parent c6ae66a commit b17fbb0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ jobs:
echo 'steps.files.outputs.all=${{ steps.files.outputs.all }}'
echo 'steps.files.outputs.added=${{ steps.files.outputs.added }}'
echo 'steps.files.outputs.modified=${{ steps.files.outputs.modified }}'
echo 'steps.files.outputs.deleted=${{ steps.files.outputs.deleted }}'
echo 'steps.files.outputs.removed=${{ steps.files.outputs.removed }}'
echo 'steps.files.outputs.renamed=${{ steps.files.outputs.renamed }}'
echo 'steps.files.outputs.added_modified=${{ steps.files.outputs.added_modified }}'
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Get All Changed Files

Get all of the files changed/modified in a pull request or push's commits.
You can choose to get all changed files, only added files, only modified files, only deleted files, or all added and modified files.
You can choose to get all changed files, only added files, only modified files, only removed files, only renamed files, or all added and modified files.
These outputs are available via the `steps` output context.
The `steps` output context exposes the output names `all`, `added`, `modified`, `deleted`, `renamed`, and `added_modified`.
The `steps` output context exposes the output names `all`, `added`, `modified`, `removed`, `renamed`, and `added_modified`.

# Usage

Expand All @@ -26,7 +26,7 @@ See [action.yml](action.yml)
- [Get all changed files as space-delimited](#get-all-changed-files-as-space-delimited)
- [Get all added and modified files as CSV](#get-all-added-and-modified-files-as-csv)
- [Get all deleted files as JSON](#get-all-deleted-files-as-json)
- [Get all removed files as JSON](#get-all-removed-files-as-json)
## Get all changed files as space-delimited
Expand Down Expand Up @@ -56,17 +56,17 @@ Consider using one of the other formats if that's the case.
done
```
## Get all deleted files as JSON
## Get all removed files as JSON
```yaml
- id: files
uses: jitterbit/get-changed-files@v1
with:
format: 'json'
- run: |
readarray -t deleted_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.deleted }}')"
for deleted_file in ${deleted_files[@]}; do
echo "Do something with this ${deleted_file}."
readarray -t removed_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.removed }}')"
for removed_file in ${removed_files[@]}; do
echo "Do something with this ${removed_file}."
done
```
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ outputs:
modified:
description: >
Array of modified files.
deleted:
removed:
description: >
Array of deleted files.
Array of removed files.
renamed:
description: >
Array of renamed files.
added_modified:
description: >
Array of all added and modified files.
# For backwards-compatibility
deleted:
description: >
Array of deleted files.
20 changes: 11 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3572,7 +3572,7 @@ function run() {
}
// Get the changed files from the response payload.
const files = response.data.files;
const all = [], added = [], modified = [], deleted = [], renamed = [], addedModified = [];
const all = [], added = [], modified = [], removed = [], renamed = [], addedModified = [];
for (const file of files) {
const filename = file.filename;
// If we're using the 'space-delimited' format and any of the filenames have a space in them,
Expand All @@ -3592,17 +3592,17 @@ function run() {
addedModified.push(filename);
break;
case 'removed':
deleted.push(filename);
removed.push(filename);
break;
case 'renamed':
renamed.push(filename);
break;
default:
core.setFailed(`One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', or 'removed'.`);
core.setFailed(`One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', 'removed', or 'renamed'.`);
}
}
// Format the arrays of changed files.
let allFormatted, addedFormatted, modifiedFormatted, deletedFormatted, renamedFormatted, addedModifiedFormatted;
let allFormatted, addedFormatted, modifiedFormatted, removedFormatted, renamedFormatted, addedModifiedFormatted;
switch (format) {
case 'space-delimited':
// If any of the filenames have a space in them, then fail the step.
Expand All @@ -3613,23 +3613,23 @@ function run() {
allFormatted = all.join(' ');
addedFormatted = added.join(' ');
modifiedFormatted = modified.join(' ');
deletedFormatted = deleted.join(' ');
removedFormatted = removed.join(' ');
renamedFormatted = renamed.join(' ');
addedModifiedFormatted = addedModified.join(' ');
break;
case 'csv':
allFormatted = all.join(',');
addedFormatted = added.join(',');
modifiedFormatted = modified.join(',');
deletedFormatted = deleted.join(',');
removedFormatted = removed.join(',');
renamedFormatted = renamed.join(',');
addedModifiedFormatted = addedModified.join(',');
break;
case 'json':
allFormatted = JSON.stringify(all);
addedFormatted = JSON.stringify(added);
modifiedFormatted = JSON.stringify(modified);
deletedFormatted = JSON.stringify(deleted);
removedFormatted = JSON.stringify(removed);
renamedFormatted = JSON.stringify(renamed);
addedModifiedFormatted = JSON.stringify(addedModified);
break;
Expand All @@ -3638,16 +3638,18 @@ function run() {
core.info(`All: ${allFormatted}`);
core.info(`Added: ${addedFormatted}`);
core.info(`Modified: ${modifiedFormatted}`);
core.info(`Deleted: ${deletedFormatted}`);
core.info(`Removed: ${removedFormatted}`);
core.info(`Renamed: ${renamedFormatted}`);
core.info(`Added or modified: ${addedModifiedFormatted}`);
// Set step output context.
core.setOutput('all', allFormatted);
core.setOutput('added', addedFormatted);
core.setOutput('modified', modifiedFormatted);
core.setOutput('deleted', deletedFormatted);
core.setOutput('removed', removedFormatted);
core.setOutput('renamed', renamedFormatted);
core.setOutput('added_modified', addedModifiedFormatted);
// For backwards-compatibility
core.setOutput('deleted', removedFormatted);
}
catch (error) {
core.setFailed(error.message);
Expand Down
21 changes: 12 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function run(): Promise<void> {
const all = [] as string[],
added = [] as string[],
modified = [] as string[],
deleted = [] as string[],
removed = [] as string[],
renamed = [] as string[],
addedModified = [] as string[]
for (const file of files) {
Expand All @@ -111,14 +111,14 @@ async function run(): Promise<void> {
addedModified.push(filename)
break
case 'removed':
deleted.push(filename)
removed.push(filename)
break
case 'renamed':
renamed.push(filename)
break
default:
core.setFailed(
`One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', or 'removed'.`
`One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', 'removed', or 'renamed'.`
)
}
}
Expand All @@ -127,7 +127,7 @@ async function run(): Promise<void> {
let allFormatted: string,
addedFormatted: string,
modifiedFormatted: string,
deletedFormatted: string,
removedFormatted: string,
renamedFormatted: string,
addedModifiedFormatted: string
switch (format) {
Expand All @@ -142,23 +142,23 @@ async function run(): Promise<void> {
allFormatted = all.join(' ')
addedFormatted = added.join(' ')
modifiedFormatted = modified.join(' ')
deletedFormatted = deleted.join(' ')
removedFormatted = removed.join(' ')
renamedFormatted = renamed.join(' ')
addedModifiedFormatted = addedModified.join(' ')
break
case 'csv':
allFormatted = all.join(',')
addedFormatted = added.join(',')
modifiedFormatted = modified.join(',')
deletedFormatted = deleted.join(',')
removedFormatted = removed.join(',')
renamedFormatted = renamed.join(',')
addedModifiedFormatted = addedModified.join(',')
break
case 'json':
allFormatted = JSON.stringify(all)
addedFormatted = JSON.stringify(added)
modifiedFormatted = JSON.stringify(modified)
deletedFormatted = JSON.stringify(deleted)
removedFormatted = JSON.stringify(removed)
renamedFormatted = JSON.stringify(renamed)
addedModifiedFormatted = JSON.stringify(addedModified)
break
Expand All @@ -168,17 +168,20 @@ async function run(): Promise<void> {
core.info(`All: ${allFormatted}`)
core.info(`Added: ${addedFormatted}`)
core.info(`Modified: ${modifiedFormatted}`)
core.info(`Deleted: ${deletedFormatted}`)
core.info(`Removed: ${removedFormatted}`)
core.info(`Renamed: ${renamedFormatted}`)
core.info(`Added or modified: ${addedModifiedFormatted}`)

// Set step output context.
core.setOutput('all', allFormatted)
core.setOutput('added', addedFormatted)
core.setOutput('modified', modifiedFormatted)
core.setOutput('deleted', deletedFormatted)
core.setOutput('removed', removedFormatted)
core.setOutput('renamed', renamedFormatted)
core.setOutput('added_modified', addedModifiedFormatted)

// For backwards-compatibility
core.setOutput('deleted', removedFormatted)
} catch (error) {
core.setFailed(error.message)
}
Expand Down

0 comments on commit b17fbb0

Please sign in to comment.