Skip to content

Commit 9ff5142

Browse files
authored
Merge pull request #4525 from adityasharad/js/autobuild-github-hidden-folder
JavaScript: Include .github hidden folders in autobuild
2 parents a6abee9 + f7bd835 commit 9ff5142

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
* or "metadata" becomes an exclude path. Note that there are no implicit exclude paths.
118118
*
119119
* <p>The walking phase starts at each include path in turn and recursively traverses folders and
120-
* files. Symlinks and hidden folders are skipped, but not hidden files. If it encounters a
120+
* files. Symlinks and most hidden folders are skipped, but not hidden files. If it encounters a
121121
* sub-folder whose path is excluded, traversal stops. If it encounters a file, that file becomes a
122122
* candidate, unless its path is excluded. If the path of a file is both an include path and an
123123
* exclude path, the inclusion takes precedence, and the file becomes a candidate after all.
@@ -1010,10 +1010,19 @@ && isFileIncluded(file)) {
10101010
return super.visitFile(file, attrs);
10111011
}
10121012

1013+
/**
1014+
* Returns {@code true} if {@code dir} is a hidden directory
1015+
* that should be skipped by default.
1016+
*/
1017+
private boolean isSkippedHiddenDirectory(Path dir) {
1018+
// Allow .github folders as they may contain YAML files relevant to GitHub repositories.
1019+
return dir.toFile().isHidden() && !dir.getFileName().toString().equals(".github");
1020+
}
1021+
10131022
@Override
10141023
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
10151024
throws IOException {
1016-
if (!dir.equals(currentRoot[0]) && (excludes.contains(dir) || dir.toFile().isHidden()))
1025+
if (!dir.equals(currentRoot[0]) && (excludes.contains(dir) || isSkippedHiddenDirectory(dir)))
10171026
return FileVisitResult.SKIP_SUBTREE;
10181027
if (Files.exists(dir.resolve("codeql-database.yml"))) {
10191028
return FileVisitResult.SKIP_SUBTREE;

javascript/extractor/src/com/semmle/js/extractor/test/AutoBuildTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,19 @@ public void skipCodeQLDatabases() throws IOException {
608608
addFile(false, LGTM_SRC, "db/foo.js");
609609
runTest();
610610
}
611+
612+
@Test
613+
public void hiddenGitHubFoldersAreIncluded() throws IOException {
614+
Path tst_yml = addFile(true, LGTM_SRC, ".github", "workflows", "test.yml");
615+
hide(tst_yml.getParent().getParent());
616+
runTest();
617+
}
618+
619+
@Test
620+
public void hiddenGitHubFoldersCanBeExcluded() throws IOException {
621+
envVars.put("LGTM_INDEX_FILTERS", "exclude:**/.github");
622+
Path tst_yml = addFile(false, LGTM_SRC, ".github", "workflows", "test.yml");
623+
hide(tst_yml.getParent().getParent());
624+
runTest();
625+
}
611626
}

0 commit comments

Comments
 (0)