Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [Eyes] Ignore pattern doesn't work for cmake-build-* when it is intended to be a folder #9560

Closed
2 of 3 tasks
tisonkun opened this issue Sep 4, 2022 · 5 comments
Closed
2 of 3 tasks
Assignees
Labels
bug Something isn't working and you are sure it's a bug! license eye

Comments

@tisonkun
Copy link
Member

tisonkun commented Sep 4, 2022

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

License Tools (apache/skywalking-eyes)

What happened

If a pattern with * is added to paths or paths-ignore when it's intended to be a folder, it doesn't work as expected. Because doublestar module only treat patterns end with / as folder.

For example, specifying cmake-build-* doesn't exclude cmake-build-debug folder.

➜  incubator-kvrocks git: ~/go/bin/license-eye -c tools/ci/licenserc.yml header check
INFO Loading configuration from file: tools/ci/licenserc.yml 
INFO Totally checked 4279 files, valid: 212, invalid: 2045, ignored: 2022, fixed: 0 
INFO GITHUB_TOKEN is not set, license-eye won't comment on the pull request 
ERROR the following files don't have a valid license header: 
cmake-build-debug/_deps/gtest-src/googletest/scripts/test/Makefile
cmake-build-debug/_deps/luajit-src/src/Makefile
...
cmake-build-debug/_deps/lz4-src/contrib/snap/snapcraft.yaml 
ERROR one or more files does not have a valid license header

What you expected to happen

Files are properly included or excluded.

How to reproduce

go install github.com/apache/skywalking-eyes/cmd/[email protected]
gh repo clone apache/incubator-kvrocks
cd incubator-kvrocks
./x.py build --ninja cmake-build-debug
~/go/bin/license-eye -c tools/ci/licenserc.yml header check

Anything else

I think these lines of code are related:

	for _, ignorePattern := range config.PathsIgnore {
		if matched, err := doublestar.Match(ignorePattern, path); matched || err != nil {
			return matched, err
		}
	}

	if stat, err := os.Stat(path); err == nil {
		for _, ignorePattern := range config.PathsIgnore {
			ignorePattern = strings.TrimRight(ignorePattern, "/")
			if strings.HasPrefix(path, ignorePattern+"/") || stat.Name() == ignorePattern {
				return true, nil
			}
		}
	}

	return false, nil

It seems that if the pattern is intended to be a folder while with *, the stat workaround has a hole. We may write:

doublestar.Match(ignorePattern + "/", path)

instead. But it may has other corner cases. I don't think of it deeply, though.

cc @kezhenxu94 @fgksgf

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@tisonkun tisonkun added the bug Something isn't working and you are sure it's a bug! label Sep 4, 2022
@wu-sheng wu-sheng added this to the license-eye 0.5.0 milestone Sep 4, 2022
@tisonkun
Copy link
Member Author

tisonkun commented Sep 4, 2022

It's fair enough that we just follow how glob works and if users want to refer to a folder, use folder/ and folder/**. But the workaround that exists is a bit inconsistent with this assumption. I'm willing to learn some design purposes here.

More related code snippet for paths matches:

func glob(pattern string) (matches []string, err error) {
	if pattern == "." {
		return doublestar.Glob("./")
	}

	return doublestar.Glob(pattern)
}

@wu-sheng
Copy link
Member

Is there any update for this?

@tisonkun
Copy link
Member Author

@wu-sheng This is more like a new feature suggestion that I don't have time to implement :)

I'm OK if it's closed as workaround provided:

cmake-build-*/**

@wu-sheng
Copy link
Member

I am going to close until someone is willing pick it back to work.

@wu-sheng wu-sheng closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2023
@tisonkun
Copy link
Member Author

tisonkun commented Apr 1, 2023

For anyone who comes here, I implement this logic for my own tool korandoru/hawkeye#65 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working and you are sure it's a bug! license eye
Projects
None yet
Development

No branches or pull requests

3 participants