35
35
import io .spring .projectapi .github .ProjectDocumentation .Status ;
36
36
import org .apache .maven .artifact .versioning .ComparableVersion ;
37
37
import org .jetbrains .annotations .NotNull ;
38
+ import org .slf4j .Logger ;
39
+ import org .slf4j .LoggerFactory ;
38
40
39
41
import org .springframework .boot .web .client .RestTemplateBuilder ;
40
42
import org .springframework .cache .annotation .Cacheable ;
@@ -64,6 +66,8 @@ public class GithubOperations {
64
66
65
67
private static final Comparator <ProjectDocumentation > VERSION_COMPARATOR = GithubOperations ::compare ;
66
68
69
+ private static final Logger logger = LoggerFactory .getLogger (GithubOperations .class );
70
+
67
71
private final RestTemplate restTemplate ;
68
72
69
73
private final ObjectMapper objectMapper ;
@@ -74,6 +78,8 @@ public class GithubOperations {
74
78
75
79
private static final String CONFIG_COMMIT_MESSAGE = "Update Spring Boot Config" ;
76
80
81
+ private static final String DEFAULT_SUPPORT_POLICY = "UPSTREAM" ;
82
+
77
83
private static final ParameterizedTypeReference <Map <String , Object >> STRING_OBJECT_MAP = new ParameterizedTypeReference <>() {
78
84
};
79
85
@@ -212,6 +218,8 @@ private ResponseEntity<Map<String, Object>> getFile(String projectSlug, String f
212
218
return this .restTemplate .exchange (request , STRING_OBJECT_MAP );
213
219
}
214
220
catch (HttpClientErrorException ex ) {
221
+ logger .info ("*** Exception thrown for " + projectSlug + " and file " + fileName + " due to "
222
+ + ex .getMessage () + " with status " + ex .getStatusCode ());
215
223
HttpStatusCode statusCode = ex .getStatusCode ();
216
224
if (statusCode .value () == 404 ) {
217
225
throwIfProjectDoesNotExist (projectSlug );
@@ -257,7 +265,10 @@ public List<Project> getProjects() {
257
265
body .forEach ((project ) -> {
258
266
String projectSlug = (String ) project .get ("name" );
259
267
try {
260
- projects .add (getProject (projectSlug ));
268
+ Project fetchedProject = getProject (projectSlug );
269
+ if (fetchedProject != null ) {
270
+ projects .add (fetchedProject );
271
+ }
261
272
}
262
273
catch (Exception ex ) {
263
274
// Ignore project without an index file
@@ -281,6 +292,9 @@ public Project getProject(String projectSlug) {
281
292
282
293
public List <ProjectDocumentation > getProjectDocumentations (String projectSlug ) {
283
294
ResponseEntity <Map <String , Object >> response = getFile (projectSlug , "documentation.json" );
295
+ if (response == null ) {
296
+ return Collections .emptyList ();
297
+ }
284
298
String content = getFileContents (response );
285
299
return List .copyOf (convertToProjectDocumentation (content ));
286
300
}
@@ -304,9 +318,11 @@ private <T> T readValue(String contents, TypeReference<T> type) {
304
318
}
305
319
}
306
320
307
- @ Cacheable (value = "support_policy" , key = "#projectSlug" )
308
321
public String getProjectSupportPolicy (String projectSlug ) {
309
322
ResponseEntity <Map <String , Object >> indexResponse = getFile (projectSlug , "index.md" );
323
+ if (indexResponse == null ) {
324
+ return DEFAULT_SUPPORT_POLICY ;
325
+ }
310
326
String indexContents = getFileContents (indexResponse );
311
327
Map <String , String > frontMatter = MarkdownUtils .getFrontMatter (indexContents );
312
328
InvalidGithubProjectIndexException .throwIfInvalid (Objects ::nonNull , frontMatter , projectSlug );
0 commit comments