Skip to content

Commit

Permalink
Add exclude files to check
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Apr 15, 2024
1 parent 61d1e2f commit f214634
Show file tree
Hide file tree
Showing 10 changed files with 2,388 additions and 80 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,4 @@ jobs:
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: e9e9b061034f705ecaaabf5ec30ad36f828603c2
head: main
use-output: true

- name: Print Added TODOs
id: output-new
run: echo "${{ steps.test-action.outputs.added-todos }}"

- name: Print Removed TODOs
id: output-old
run: echo "${{ steps.test-action.outputs.removed-todos }}"
exclude: .github/*
39 changes: 7 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ comments found.
You can configure the action further by providing inputs:
- `token`: The GitHub token to use for commenting on the PR. This is required.
- `exclude`: A list of glob patterns to exclude from the search. This is
optional.

```yaml
steps:
- name: Checkout
Expand All @@ -54,36 +58,7 @@ steps:
uses: phntmxyz/todo-finder-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main # PR base by default but you can use any git reference
head: pr-head # PR head by default but you can use any git reference
```
## Output
The action outputs a comment with the list of new and removed TODOs in the pull
request where the action was run. You can access this output in subsequent steps
like so:
```yaml
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Test Local Action
id: test-action
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: e9e9b061034f705ecaaabf5ec30ad36f828603c2
head: main
use-output: true

- name: Print Added TODOs
id: output-new
run: echo "${{ steps.test-action.outputs.added-todos }}"

- name: Print Removed TODOs
id: output-old
run: echo "${{ steps.test-action.outputs.removed-todos }}"
exclude: |
*.md
**/config/*.yml
```
121 changes: 105 additions & 16 deletions __test__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ const __diff = `@@ -22,6 +22,14 @@ any text';
- removed non todo line
+ added non todo line`

const __prDiff = [
{
sha: 'sha',
filename: 'filename',
status: 'modified',
additions: 8,
deletions: 2,
changes: 0,
blob_url: 'blob_url',
raw_url: 'raw_url',
contents_url: 'contents_url',
patch: __diff,
previous_filename: undefined
}
] as PrDiff

describe('extractTodos', () => {
it('should correctly extract todos', () => {
const __prDiff = [
{
sha: 'sha',
filename: 'filename.js',
status: 'modified',
additions: 8,
deletions: 2,
changes: 0,
blob_url: 'blob_url',
raw_url: 'raw_url',
contents_url: 'contents_url',
patch: __diff,
previous_filename: undefined
}
] as PrDiff

const fileTodos = findTodos(__prDiff)

const expectedTodos: FileTodos[] = [
Expand All @@ -56,4 +56,93 @@ describe('extractTodos', () => {
]
expect(fileTodos).toEqual(expectedTodos)
})

it('should correctly exclude files', () => {
const __prDiff = [
{
sha: 'sha',
filename: 'filename.js',
status: 'modified',
additions: 1,
deletions: 0,
changes: 0,
blob_url: 'blob_url',
raw_url: 'raw_url',
contents_url: 'contents_url',
patch: `@@ -22,6 +22,14 @@ any text';
+ // TODO - in filename js`,
previous_filename: undefined
},
{
sha: 'sha',
filename: 'filename.yml',
status: 'modified',
additions: 1,
deletions: 0,
changes: 0,
blob_url: 'blob_url',
raw_url: 'raw_url',
contents_url: 'contents_url',
patch: `@@ -22,6 +22,14 @@ any text';
+ // TODO - in filename yml`,
previous_filename: undefined
},
{
sha: 'sha',
filename: 'excluded/filename.js',
status: 'modified',
additions: 1,
deletions: 0,
changes: 0,
blob_url: 'blob_url',
raw_url: 'raw_url',
contents_url: 'contents_url',
patch: `@@ -22,6 +22,14 @@ any text';
+ // TODO - in excluded directory`,
previous_filename: undefined
},
{
sha: 'sha',
filename: 'included/other.txt',
status: 'modified',
additions: 1,
deletions: 0,
changes: 0,
blob_url: 'blob_url',
raw_url: 'raw_url',
contents_url: 'contents_url',
patch: `@@ -22,6 +22,14 @@ any text';
+ // TODO - in included directory`,
previous_filename: undefined
}
] as PrDiff

const exclude = ['**/*.yml', '**/excluded/*']

const fileTodos = findTodos(__prDiff, exclude)

const expectedTodos: FileTodos[] = [
{
filename: 'filename.js',
todos: [
{
line: 22,
content: 'TODO - in filename js',
isNew: true
}
]
},
{
filename: 'included/other.txt',
todos: [
{
line: 22,
content: 'TODO - in included directory',
isNew: true
}
]
}
]
expect(fileTodos).toEqual(expectedTodos)
})
})
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
token:
description: 'GitHub token'
required: true
exclude:
description:
'Exclude file patterns. User list of globs separated by new line.'
required: false

runs:
using: 'node20'
Expand Down
Loading

0 comments on commit f214634

Please sign in to comment.