You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "jhult (via GitHub)" <gi...@apache.org> on 2026/02/18 02:55:27 UTC
[PR] fix: respect specified paths in git repository [skywalking-eyes]
jhult opened a new pull request, #263:
URL: https://github.com/apache/skywalking-eyes/pull/263
## Summary
- Fixed header check/fix commands to respect specified file paths even when in a git repository
- Previously, specifying paths in a git repo would incorrectly check all tracked files instead of just the specified paths
- Now supports individual files, directories, and glob patterns correctly in all contexts
## Changes
- Added `matchPaths()` function in `pkg/header/check.go` to filter files using glob pattern matching
- Updated `listFiles()` to respect configured paths when in git repositories
- Updated help text for `header check` and `header fix` commands to clarify accepted path types
- Added `TestMatchPaths()` to verify pattern matching behavior
## Testing
- All existing tests pass
- New `TestMatchPaths()` validates exact file matches, glob patterns, and double-star patterns
- Verified behavior with single files, multiple files, and glob patterns in git repositories
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#issuecomment-4189029574
@jhult Are you still working on this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "jhult (via GitHub)" <gi...@apache.org>.
jhult commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r3037339073
##########
commands/header_check.go:
##########
@@ -29,17 +29,28 @@ import (
)
var CheckCommand = &cobra.Command{
- Use: "check",
+ Use: "check [paths...]",
Aliases: []string{"c"},
- Long: "check command walks the specified paths recursively and checks if the specified files have the license header in the config file.",
+ Long: "check command walks the specified paths recursively and checks if the " +
+ "specified files have the license header in the config file. " +
+ "Accepts files, directories, and glob patterns. " +
+ "If no paths are specified, checks the current directory " +
+ "recursively as defined in the config file.",
RunE: func(_ *cobra.Command, args []string) error {
hasErrors := false
for _, h := range Config.Headers() {
var result header.Result
if len(args) > 0 {
+ // Filter args by the paths in this header config
+ var filteredArgs []string
+ for _, arg := range args {
+ if header.MatchPaths(arg, h.Paths) {
+ filteredArgs = append(filteredArgs, arg)
+ }
+ }
Review Comment:
Fixed. Both `check` and `fix` commands now do `h.Paths = args` without `MatchPaths` filtering.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "kezhenxu94 (via GitHub)" <gi...@apache.org>.
kezhenxu94 commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r2820121585
##########
commands/header_check.go:
##########
@@ -29,9 +29,9 @@ import (
)
var CheckCommand = &cobra.Command{
- Use: "check",
+ Use: "check [paths...]",
Review Comment:
Maybe revert this because `[paths...]` means the command accepts some paths arguments
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "kezhenxu94 (via GitHub)" <gi...@apache.org>.
kezhenxu94 commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r2825378774
##########
commands/header_check.go:
##########
@@ -29,17 +29,28 @@ import (
)
var CheckCommand = &cobra.Command{
- Use: "check",
+ Use: "check [paths...]",
Aliases: []string{"c"},
- Long: "check command walks the specified paths recursively and checks if the specified files have the license header in the config file.",
+ Long: "check command walks the specified paths recursively and checks if the " +
+ "specified files have the license header in the config file. " +
+ "Accepts files, directories, and glob patterns. " +
+ "If no paths are specified, checks the current directory " +
+ "recursively as defined in the config file.",
RunE: func(_ *cobra.Command, args []string) error {
hasErrors := false
for _, h := range Config.Headers() {
var result header.Result
if len(args) > 0 {
+ // Filter args by the paths in this header config
+ var filteredArgs []string
+ for _, arg := range args {
+ if header.MatchPaths(arg, h.Paths) {
+ filteredArgs = append(filteredArgs, arg)
+ }
+ }
Review Comment:
Hi, I think when we pass the paths to the CLI args we intend to check that files regardless of the config file. The args here should be highest priority even if they are not configured in config file
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r2820125228
##########
commands/header_fix.go:
##########
@@ -28,9 +28,9 @@ import (
)
var FixCommand = &cobra.Command{
- Use: "fix",
+ Use: "fix [paths...]",
Aliases: []string{"f"},
- Long: "fix command walks the specified paths recursively and fix the license header if the specified files don't have the license header.",
+ Long: "fix command walks the specified paths recursively and fixes the license header if the specified files don't have the license header. Accepts files, directories, and glob patterns. If no paths are specified, fixes the current directory recursively as defined in the config file.",
Review Comment:
The updated documentation states that the fix command "Accepts files, directories, and glob patterns" when command-line paths are provided. However, the implementation (lines 40-46, not shown in this diff) doesn't actually support directories or glob patterns when args are provided - it only passes the args directly to header.Fix which expects individual file paths.
This documentation is misleading. Either the implementation needs to be updated to support directories and glob patterns (similar to how check command handles args by setting h.Paths = args), or the documentation should clarify that directories and glob patterns are only supported through the config file, not command-line arguments.
##########
pkg/header/check.go:
##########
@@ -150,6 +153,19 @@ func listFiles(config *ConfigHeader) ([]string, error) {
return fileList, nil
}
+func matchPaths(file string, patterns []string) bool {
+ for _, pattern := range patterns {
+ if pattern == "." {
+ pattern = "./"
+ }
+ matched, err := doublestar.Match(pattern, file)
+ if err == nil && matched {
+ return true
+ }
Review Comment:
The matchPaths function doesn't handle directory patterns consistently with the existing tryMatchPatten function in config.go. When a user specifies a directory pattern like "pkg/header/", it should match files within that directory (e.g., "pkg/header/check.go"), but the current implementation using only doublestar.Match will return false.
The tryMatchPatten function (lines 132-153 in pkg/header/config.go) includes additional logic after doublestar.Match to handle directory patterns by checking if the file path has the pattern as a prefix. This same logic should be included in matchPaths to ensure consistent behavior between git and non-git repositories.
Without this, users who specify directory paths (with or without trailing slashes) will get different behavior in git vs non-git repositories.
```suggestion
}
// Fallback for directory patterns (e.g., "pkg/header/" or "pkg/header")
// to behave consistently with tryMatchPatten in config.go.
if err == nil {
dirPattern := pattern
// Ensure the pattern ends with a path separator so it clearly denotes a directory.
if !strings.HasSuffix(dirPattern, "/") && !strings.HasSuffix(dirPattern, string(os.PathSeparator)) {
dirPattern = dirPattern + "/"
}
// Normalize both paths to use '/' so prefix matching is consistent across platforms.
normalizedDir := strings.ReplaceAll(dirPattern, "\\", "/")
normalizedFile := strings.ReplaceAll(file, "\\", "/")
if strings.HasPrefix(normalizedFile, normalizedDir) {
return true
}
}
```
##########
pkg/header/check_test.go:
##########
@@ -273,3 +273,70 @@ func TestListFilesWithWorktreeDetachedHEAD(t *testing.T) {
t.Error("Expected to find files with valid commit")
}
}
+
+func TestMatchPaths(t *testing.T) {
+ tests := []struct {
+ name string
+ file string
+ patterns []string
+ expected bool
+ }{
+ {
+ name: "Exact file match",
+ file: "test.go",
+ patterns: []string{"test.go"},
+ expected: true,
+ },
+ {
+ name: "Glob pattern match",
+ file: "test.go",
+ patterns: []string{"*.go"},
+ expected: true,
+ },
+ {
+ name: "Double-star glob pattern match",
+ file: "pkg/header/check.go",
+ patterns: []string{"**/*.go"},
+ expected: true,
+ },
+ {
+ name: "Multiple patterns with match",
+ file: "test.go",
+ patterns: []string{"*.java", "*.go", "*.py"},
+ expected: true,
+ },
+ {
+ name: "Multiple patterns without match",
+ file: "test.go",
+ patterns: []string{"*.java", "*.py"},
+ expected: false,
+ },
+ {
+ name: "Directory pattern with trailing slash",
+ file: "pkg/header/check.go",
+ patterns: []string{"pkg/header/"},
+ expected: false,
Review Comment:
This test case expects that a directory pattern "pkg/header/" should NOT match the file "pkg/header/check.go". However, this is inconsistent with the existing tryMatchPatten function in pkg/header/config.go (lines 132-153), which includes logic to match files within a specified directory.
In the non-git code path, when a user specifies "pkg/header/" as a path, doublestar.Glob expands it to the directory, and walkFile recursively finds all files within it. For consistency, the git code path should behave the same way - files within "pkg/header/" should match the pattern "pkg/header/".
This test case should expect true, not false, and the matchPaths function should be updated to include directory prefix matching logic similar to tryMatchPatten.
```suggestion
expected: true,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "jhult (via GitHub)" <gi...@apache.org>.
jhult commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r3037322182
##########
commands/header_fix.go:
##########
@@ -28,9 +28,9 @@ import (
)
var FixCommand = &cobra.Command{
- Use: "fix",
+ Use: "fix [paths...]",
Aliases: []string{"f"},
- Long: "fix command walks the specified paths recursively and fix the license header if the specified files don't have the license header.",
+ Long: "fix command walks the specified paths recursively and fixes the license header if the specified files don't have the license header. Accepts files, directories, and glob patterns. If no paths are specified, fixes the current directory recursively as defined in the config file.",
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "jhult (via GitHub)" <gi...@apache.org>.
jhult commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r3037318588
##########
pkg/header/check_test.go:
##########
@@ -273,3 +273,70 @@ func TestListFilesWithWorktreeDetachedHEAD(t *testing.T) {
t.Error("Expected to find files with valid commit")
}
}
+
+func TestMatchPaths(t *testing.T) {
+ tests := []struct {
+ name string
+ file string
+ patterns []string
+ expected bool
+ }{
+ {
+ name: "Exact file match",
+ file: "test.go",
+ patterns: []string{"test.go"},
+ expected: true,
+ },
+ {
+ name: "Glob pattern match",
+ file: "test.go",
+ patterns: []string{"*.go"},
+ expected: true,
+ },
+ {
+ name: "Double-star glob pattern match",
+ file: "pkg/header/check.go",
+ patterns: []string{"**/*.go"},
+ expected: true,
+ },
+ {
+ name: "Multiple patterns with match",
+ file: "test.go",
+ patterns: []string{"*.java", "*.go", "*.py"},
+ expected: true,
+ },
+ {
+ name: "Multiple patterns without match",
+ file: "test.go",
+ patterns: []string{"*.java", "*.py"},
+ expected: false,
+ },
+ {
+ name: "Directory pattern with trailing slash",
+ file: "pkg/header/check.go",
+ patterns: []string{"pkg/header/"},
+ expected: false,
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "jhult (via GitHub)" <gi...@apache.org>.
jhult commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r3037320030
##########
pkg/header/check.go:
##########
@@ -150,6 +153,19 @@ func listFiles(config *ConfigHeader) ([]string, error) {
return fileList, nil
}
+func matchPaths(file string, patterns []string) bool {
+ for _, pattern := range patterns {
+ if pattern == "." {
+ pattern = "./"
+ }
+ matched, err := doublestar.Match(pattern, file)
+ if err == nil && matched {
+ return true
+ }
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "jhult (via GitHub)" <gi...@apache.org>.
jhult commented on PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#issuecomment-4189520683
@kezhenxu94 - this is ready for another review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "kezhenxu94 (via GitHub)" <gi...@apache.org>.
kezhenxu94 merged PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: respect specified paths in git repository [skywalking-eyes]
Posted by "kezhenxu94 (via GitHub)" <gi...@apache.org>.
kezhenxu94 commented on code in PR #263:
URL: https://github.com/apache/skywalking-eyes/pull/263#discussion_r2820121585
##########
commands/header_check.go:
##########
@@ -29,9 +29,9 @@ import (
)
var CheckCommand = &cobra.Command{
- Use: "check",
+ Use: "check [paths...]",
Review Comment:
Maybe revert this because `[paths...]` means the command accepts some paths arguments
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org