diff --git a/src/main/java/io/spring/projectapi/github/GithubOperations.java b/src/main/java/io/spring/projectapi/github/GithubOperations.java index 14d8ede..83a3565 100644 --- a/src/main/java/io/spring/projectapi/github/GithubOperations.java +++ b/src/main/java/io/spring/projectapi/github/GithubOperations.java @@ -35,6 +35,8 @@ import io.spring.projectapi.github.ProjectDocumentation.Status; import org.apache.maven.artifact.versioning.ComparableVersion; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.cache.annotation.Cacheable; @@ -64,6 +66,8 @@ public class GithubOperations { private static final Comparator VERSION_COMPARATOR = GithubOperations::compare; + private static final Logger logger = LoggerFactory.getLogger(GithubOperations.class); + private final RestTemplate restTemplate; private final ObjectMapper objectMapper; @@ -74,6 +78,8 @@ public class GithubOperations { private static final String CONFIG_COMMIT_MESSAGE = "Update Spring Boot Config"; + private static final String DEFAULT_SUPPORT_POLICY = "UPSTREAM"; + private static final ParameterizedTypeReference> STRING_OBJECT_MAP = new ParameterizedTypeReference<>() { }; @@ -212,6 +218,8 @@ private ResponseEntity> getFile(String projectSlug, String f return this.restTemplate.exchange(request, STRING_OBJECT_MAP); } catch (HttpClientErrorException ex) { + logger.info("*** Exception thrown for " + projectSlug + " and file " + fileName + " due to " + + ex.getMessage() + " with status " + ex.getStatusCode()); HttpStatusCode statusCode = ex.getStatusCode(); if (statusCode.value() == 404) { throwIfProjectDoesNotExist(projectSlug); @@ -257,7 +265,10 @@ public List getProjects() { body.forEach((project) -> { String projectSlug = (String) project.get("name"); try { - projects.add(getProject(projectSlug)); + Project fetchedProject = getProject(projectSlug); + if (fetchedProject != null) { + projects.add(fetchedProject); + } } catch (Exception ex) { // Ignore project without an index file @@ -281,6 +292,9 @@ public Project getProject(String projectSlug) { public List getProjectDocumentations(String projectSlug) { ResponseEntity> response = getFile(projectSlug, "documentation.json"); + if (response == null) { + return Collections.emptyList(); + } String content = getFileContents(response); return List.copyOf(convertToProjectDocumentation(content)); } @@ -304,9 +318,11 @@ private T readValue(String contents, TypeReference type) { } } - @Cacheable(value = "support_policy", key = "#projectSlug") public String getProjectSupportPolicy(String projectSlug) { ResponseEntity> indexResponse = getFile(projectSlug, "index.md"); + if (indexResponse == null) { + return DEFAULT_SUPPORT_POLICY; + } String indexContents = getFileContents(indexResponse); Map frontMatter = MarkdownUtils.getFrontMatter(indexContents); InvalidGithubProjectIndexException.throwIfInvalid(Objects::nonNull, frontMatter, projectSlug);