diff --git a/pom.xml b/pom.xml index d9f708462..e6f45ab8a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sap.oss.phosphor fosstars-rating-core - 1.12.0-SNAPSHOT + 1.11.1-SNAPSHOT jar Fosstars Rating Core diff --git a/src/main/java/com/sap/oss/phosphor/fosstars/advice/oss/github/OssSecurityGithubAdvisor.java b/src/main/java/com/sap/oss/phosphor/fosstars/advice/oss/github/OssSecurityGithubAdvisor.java index a9bad12a2..295b88ef5 100644 --- a/src/main/java/com/sap/oss/phosphor/fosstars/advice/oss/github/OssSecurityGithubAdvisor.java +++ b/src/main/java/com/sap/oss/phosphor/fosstars/advice/oss/github/OssSecurityGithubAdvisor.java @@ -42,4 +42,4 @@ public OssSecurityGithubAdvisor() { new SnykAdvisor(AdviceForGitHubContextFactory.INSTANCE), new GoSecAdvisor(AdviceForGitHubContextFactory.INSTANCE)); } -} +} \ No newline at end of file diff --git a/src/main/java/com/sap/oss/phosphor/fosstars/data/AbstractStaticScanToolsDataProvider.java b/src/main/java/com/sap/oss/phosphor/fosstars/data/AbstractStaticScanToolsDataProvider.java index 357cd95ef..26d2ac863 100644 --- a/src/main/java/com/sap/oss/phosphor/fosstars/data/AbstractStaticScanToolsDataProvider.java +++ b/src/main/java/com/sap/oss/phosphor/fosstars/data/AbstractStaticScanToolsDataProvider.java @@ -432,7 +432,7 @@ public static class Visitor extends AbstractGitHubVisitor { @Override public void visitPreCommitHook(LocalRepository repository, Map> matchers, Set locations) throws IOException { - Optional content = repository.fileStream(PRE_COMMIT_HOOK_CONFIG); + Optional content = repository.read(PRE_COMMIT_HOOK_CONFIG); if (!content.isPresent()) { return; } diff --git a/src/main/java/com/sap/oss/phosphor/fosstars/data/github/LocalRepository.java b/src/main/java/com/sap/oss/phosphor/fosstars/data/github/LocalRepository.java index f5bc53d31..03536f2cb 100644 --- a/src/main/java/com/sap/oss/phosphor/fosstars/data/github/LocalRepository.java +++ b/src/main/java/com/sap/oss/phosphor/fosstars/data/github/LocalRepository.java @@ -213,37 +213,6 @@ public Optional file(Path file) throws IOException { return Optional.of(IOUtils.toString(is, UTF_8)); } } - - /** - * Returns a content of a file if it exists. - * - * @param file The file name. - * @return A inputstream of the file. - * @throws IOException If something went wrong. - */ - public Optional fileStream(String file) throws IOException { - Objects.requireNonNull(file, "On no! File name is null!"); - return fileStream(Paths.get(file)); - } - - /** - * Returns a content of a file if it exists. - * - * @param file The file name. - * @return A inputstream of the file. - * @throws IOException If something went wrong. - */ - public Optional fileStream(Path file) throws IOException { - Objects.requireNonNull(file, "On no! File name is null!"); - Path path = info.path().resolve(file); - if (!Files.isRegularFile(path)) { - return Optional.empty(); - } - - try (InputStream is = Files.newInputStream(path)) { - return Optional.ofNullable(is); - } - } /** * Checks if the repository has a specified directory. diff --git a/src/main/java/com/sap/oss/phosphor/fosstars/data/github/UsesSnyk.java b/src/main/java/com/sap/oss/phosphor/fosstars/data/github/UsesSnyk.java index 98f8fb85d..8f79c5879 100644 --- a/src/main/java/com/sap/oss/phosphor/fosstars/data/github/UsesSnyk.java +++ b/src/main/java/com/sap/oss/phosphor/fosstars/data/github/UsesSnyk.java @@ -103,4 +103,4 @@ private boolean hasSnykPolicy(LocalRepository repository) throws IOException { List snykPolicyFilePaths = repository.files(SNYK_FILE_PREDICATE); return !snykPolicyFilePaths.isEmpty(); } -} +} \ No newline at end of file diff --git a/src/test/java/com/sap/oss/phosphor/fosstars/data/github/MyPyDataProviderTest.java b/src/test/java/com/sap/oss/phosphor/fosstars/data/github/MyPyDataProviderTest.java index d3fd20eff..6ed371c6e 100644 --- a/src/test/java/com/sap/oss/phosphor/fosstars/data/github/MyPyDataProviderTest.java +++ b/src/test/java/com/sap/oss/phosphor/fosstars/data/github/MyPyDataProviderTest.java @@ -126,7 +126,7 @@ private void testPylintFileStreamCheck(String filename, InputStream content, Files.createDirectories(file.getParent()); when(localRepository.hasDirectory(any(Path.class))).thenReturn(true); IOUtils.copy(content, Files.newOutputStream(file)); - when(localRepository.fileStream(any(String.class))) + when(localRepository.read(any(String.class))) .thenReturn(Optional.of(Files.newInputStream(file))); MyPyDataProvider provider = new MyPyDataProvider(fetcher); diff --git a/src/test/java/com/sap/oss/phosphor/fosstars/data/github/PylintDataProviderTest.java b/src/test/java/com/sap/oss/phosphor/fosstars/data/github/PylintDataProviderTest.java index 22b3e44ab..38245fa39 100644 --- a/src/test/java/com/sap/oss/phosphor/fosstars/data/github/PylintDataProviderTest.java +++ b/src/test/java/com/sap/oss/phosphor/fosstars/data/github/PylintDataProviderTest.java @@ -199,7 +199,7 @@ private void testPylintFileStreamCheck(String filename, InputStream content, Files.createDirectories(file.getParent()); when(localRepository.hasDirectory(any(Path.class))).thenReturn(true); IOUtils.copy(content, Files.newOutputStream(file)); - when(localRepository.fileStream(any(String.class))) + when(localRepository.read(any(String.class))) .thenReturn(Optional.of(Files.newInputStream(file))); PylintDataProvider provider = new PylintDataProvider(fetcher); diff --git a/src/test/resources/com/sap/oss/phosphor/fosstars/data/github/mypy-analysis-with-pre-commit-hook.yml b/src/test/resources/com/sap/oss/phosphor/fosstars/data/github/mypy-analysis-with-pre-commit-hook.yml index c774807f3..0a9142e26 100644 --- a/src/test/resources/com/sap/oss/phosphor/fosstars/data/github/mypy-analysis-with-pre-commit-hook.yml +++ b/src/test/resources/com/sap/oss/phosphor/fosstars/data/github/mypy-analysis-with-pre-commit-hook.yml @@ -1,21 +1,59 @@ -fail_fast: true - +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# repos: - - repo: https://github.com/ambv/black + - repo: https://github.com/PyCQA/isort + rev: 5.9.3 + hooks: + - id: isort + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.941 + hooks: + - id: mypy + additional_dependencies: [types-all] + - repo: https://github.com/peterdemin/pip-compile-multi + rev: v2.4.1 + hooks: + - id: pip-compile-multi-verify + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: check-docstring-first + - id: check-added-large-files + exclude: \.(geojson)$ + - id: check-yaml + exclude: ^helm/superset/templates/ + - id: debug-statements + - id: end-of-file-fixer + - id: trailing-whitespace + args: ["--markdown-linebreak-ext=md"] + - repo: https://github.com/psf/black rev: 22.3.0 hooks: - id: black - args: [--diff, --check] - - - repo: https://github.com/pre-commit/mirrors-pylint - rev: v3.0.0a3 + language_version: python3 + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.4.1 # Use the sha or tag you want to point at hooks: - - id: pylint - args: [--disable=all, --enable=unused-import] - - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.902 + - id: prettier + args: ['--ignore-path=./superset-frontend/.prettierignore'] + files: 'superset-frontend' + # blacklist unsafe functions like make_url (see #19526) + - repo: https://github.com/skorokithakis/blacklist-pre-commit-hook + rev: e2f070289d8eddcaec0b580d3bde29437e7c8221 hooks: - - id: mypy - exclude: ^tests/ - args: [--strict] + - id: blacklist + args: ["--blacklisted-names=make_url", "--ignore=tests/"] \ No newline at end of file