Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Fix pathfilter (#33)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by openai -->
### Summary by OpenAI

**Bug fix:** Fixed issues with the `PathFilter` class. Refactored the
class to ensure that if there are no inclusion rules, all paths are
included by default. Additionally, the code now correctly handles cases
where both inclusion and exclusion rules exist for a given path. These
changes should improve the reliability of the code.
<!-- end of auto-generated comment: release notes by openai -->
  • Loading branch information
harjotgill authored Mar 15, 2023
1 parent c95e4f3 commit 42c873d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
28 changes: 15 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ inputs:
- https://github.com/isaacs/minimatch
default: |
!dist/**
!**/*.pb.go
!**/*.lock
!**/*.yaml
!**/*.yml
!**/*.cfg
!**/*.ini
!**/*.mod
!**/*.sum
!**/*.json
!**/*.mmd
!**/*.svg
!**/*.png
!**/*.dot
!*.pb.go
!*.lock
!*.yaml
!*.yml
!*.cfg
!*.toml
!*.ini
!*.mod
!*.sum
!*.json
!*.mmd
!*.svg
!*.png
!*.dot
!**/gen/**
!**/_gen/**
!**/vendor/**
system_message:
required: false
Expand Down
28 changes: 14 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,27 @@ export class PathFilter {
}

check(path: string): boolean {
let include_all = this.rules.length === 0
let matched = false
if (this.rules.length === 0) {
return true
}

let included = false
let excluded = false
let inclusionRuleExists = false

for (const [rule, exclude] of this.rules) {
if (exclude) {
if (minimatch(path, rule)) {
return false
}
include_all = true
} else {
if (minimatch(path, rule)) {
matched = true
include_all = false
if (minimatch(path, rule)) {
if (exclude) {
excluded = true
} else {
return false
included = true
}
}
if (!exclude) {
inclusionRuleExists = true
}
}
return include_all || matched

return (!inclusionRuleExists || included) && !excluded
}
}

0 comments on commit 42c873d

Please sign in to comment.