cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.65.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/git/filter.go

51lines · modecode

1package git
2
3import (
4 "log/slog"
5 "regexp"
6)
7
8func NewPathFilter(include, exclude, relaxed []*regexp.Regexp) PathFilter {
9 return PathFilter{
10 include: include,
11 exclude: exclude,
12 relaxed: relaxed,
13 }
14}
15
16type PathFilter struct {
17 include []*regexp.Regexp
18 exclude []*regexp.Regexp
19 relaxed []*regexp.Regexp
20}
21
22func (pf PathFilter) IsPathAllowed(path string) bool {
23 if len(pf.include) == 0 && len(pf.exclude) == 0 {
24 return true
25 }
26
27 for _, pattern := range pf.exclude {
28 if pattern.MatchString(path) {
29 slog.Debug("File path is in the exclude list", slog.String("path", path), slog.Any("exclude", pf.exclude))
30 return false
31 }
32 }
33
34 for _, pattern := range pf.include {
35 if pattern.MatchString(path) {
36 slog.Debug("File path is in the include list", slog.String("path", path), slog.Any("include", pf.include))
37 return true
38 }
39 }
40
41 return len(pf.include) == 0
42}
43
44func (pf PathFilter) IsRelaxed(path string) bool {
45 for _, r := range pf.relaxed {
46 if v := r.MatchString(path); v {
47 return true
48 }
49 }
50 return false
51}
52