From 40a19355b757bc2e20d94bef85c0eb076e8fda1f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 7 Jun 2024 15:53:30 +0100 Subject: [PATCH] Fix links to commercial project page and changelog --- .../github/GitHubReleaseScheduleSource.java | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/spring/calendar/github/GitHubReleaseScheduleSource.java b/src/main/java/io/spring/calendar/github/GitHubReleaseScheduleSource.java index 27b6634..3d7d2df 100644 --- a/src/main/java/io/spring/calendar/github/GitHubReleaseScheduleSource.java +++ b/src/main/java/io/spring/calendar/github/GitHubReleaseScheduleSource.java @@ -83,10 +83,7 @@ private Stream getRepositories(Organization organization) { } private Project asProject(Repository repository, Transform transform) { - if (transform == null) { - return new Project(repository); - } - return new Project(repository, transform); + return (transform != null) ? Project.from(repository, transform) : Project.from(repository); } private ReleaseSchedule createReleaseSchedule(Project project) { @@ -129,7 +126,7 @@ private Status getStatus(Milestone milestone) { return (milestone.getState() == State.OPEN) ? Status.OPEN : Status.CLOSED; } - private static class Project { + private static final class Project { private static final String COMMERCIAL_REPOSITORY_NAME_SUFFIX = "-commercial"; @@ -139,15 +136,7 @@ private static class Project { private final String commercialProjectId; - Project(Repository repository) { - this(repository, getName(repository), repository.getName()); - } - - Project(Repository repository, Transform transform) { - this(repository, transform.getDisplayName(), transform.getCommercialProjectId()); - } - - Project(Repository repository, String name, String commercialProjectId) { + private Project(Repository repository, String name, String commercialProjectId) { this.repository = repository; this.name = name; this.commercialProjectId = commercialProjectId; @@ -165,14 +154,6 @@ private String getName() { return this.name; } - private static String getName(Repository repository) { - String name = repository.getName(); - if (name.endsWith(COMMERCIAL_REPOSITORY_NAME_SUFFIX)) { - name = name.substring(0, name.length() - COMMERCIAL_REPOSITORY_NAME_SUFFIX.length()); - } - return capitalize(name.replace('-', ' ')); - } - private static String capitalize(String input) { StringWriter output = new StringWriter(); for (int i = 0; i < input.length(); i++) { @@ -206,6 +187,51 @@ private URL urlFor(Milestone milestone) { } } + static Project from(Repository repository) { + return from(repository, null); + } + + static Project from(Repository repository, Transform transform) { + return new Project(repository, getName(repository, transform), + getCommercialProjectId(repository, transform)); + } + + private static String getName(Repository repository, Transform transform) { + if (transform != null) { + String name = transform.getDisplayName(); + if (name != null) { + return name; + } + } + return getName(repository); + } + + private static String getName(Repository repository) { + String name = repository.getName(); + if (name.endsWith(COMMERCIAL_REPOSITORY_NAME_SUFFIX)) { + name = name.substring(0, name.length() - COMMERCIAL_REPOSITORY_NAME_SUFFIX.length()); + } + return capitalize(name.replace('-', ' ')); + } + + private static String getCommercialProjectId(Repository repository, Transform transform) { + if (transform != null) { + String id = transform.getCommercialProjectId(); + if (id != null) { + return id; + } + } + return getCommercialProjectId(repository); + } + + private static String getCommercialProjectId(Repository repository) { + String id = repository.getName(); + if (id.endsWith(COMMERCIAL_REPOSITORY_NAME_SUFFIX)) { + return id.substring(0, id.length() - COMMERCIAL_REPOSITORY_NAME_SUFFIX.length()); + } + return null; + } + } }