Skip to content

Commit

Permalink
Resolve Yaml Parser exception (#877)
Browse files Browse the repository at this point in the history
Fixes #876
  • Loading branch information
sourabhsparkala authored Sep 8, 2022
1 parent d64600b commit 837c8de
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.sap.oss.phosphor</groupId>
<artifactId>fosstars-rating-core</artifactId>
<version>1.12.0-SNAPSHOT</version>
<version>1.11.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Fosstars Rating Core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ public OssSecurityGithubAdvisor() {
new SnykAdvisor(AdviceForGitHubContextFactory.INSTANCE),
new GoSecAdvisor(AdviceForGitHubContextFactory.INSTANCE));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public static class Visitor extends AbstractGitHubVisitor {
@Override
public void visitPreCommitHook(LocalRepository repository,
Map<String, Predicate<String>> matchers, Set<Location> locations) throws IOException {
Optional<InputStream> content = repository.fileStream(PRE_COMMIT_HOOK_CONFIG);
Optional<InputStream> content = repository.read(PRE_COMMIT_HOOK_CONFIG);
if (!content.isPresent()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,37 +213,6 @@ public Optional<String> 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<InputStream> 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<InputStream> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ private boolean hasSnykPolicy(LocalRepository repository) throws IOException {
List<Path> snykPolicyFilePaths = repository.files(SNYK_FILE_PREDICATE);
return !snykPolicyFilePaths.isEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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/"]

0 comments on commit 837c8de

Please sign in to comment.