Skip to content

Commit

Permalink
Make repository name configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sjohnr committed Oct 17, 2023
1 parent d29c1b2 commit 487ef26
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Here is an example configuration that releases on Thursdays following the 2nd Mo
----
springRelease {
repositoryOwner = "spring-projects"
repositoryName = "spring-framework"
weekOfMonth = 2
dayOfWeek = 4
referenceDocUrl = "https://docs.spring.io/spring-framework/reference/{version}/index.html"
Expand All @@ -40,6 +41,7 @@ springRelease {
== `springRelease` Property Reference

* `repositoryOwner`: GitHub user or organization name (optional, defaults to `spring-projects`)
* `repositoryName`: GitHub repository name (optional, defaults to `project.name`)
* `weekOfMonth`: The week of the month when releases for this project are scheduled; valid values are 1 - 3 where 1 is the first week with a Monday (required)
* `dayOfWeek`: The day of the week when releases for this project are scheduled; valid values are 1 - 5 where 1 is Monday and 5 is Friday (required)
* `referenceDocUrl`: The template URL for a version of the reference documentation; can contain the variable `{version}` which is automatically substituted based on the current version (required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void register(Project project) {
// @formatter:on

var owner = springRelease.getRepositoryOwner().get();
var name = project.getRootProject().getName();
var name = springRelease.getRepositoryName().get();
task.getRepository().set(new Repository(owner, name));
task.getVersion().set(versionProvider);
task.getGitHubAccessToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void register(Project project) {
// @formatter:on

var owner = springRelease.getRepositoryOwner().get();
var name = project.getRootProject().getName();
var name = springRelease.getRepositoryName().get();
task.getRepository().set(new Repository(owner, name));
task.getVersion().set(versionProvider);
task.getGitHubAccessToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void register(Project project) {
// @formatter:on

var owner = springRelease.getRepositoryOwner().get();
var name = project.getRootProject().getName();
var name = springRelease.getRepositoryName().get();
task.getRepository().set(new Repository(owner, name));
task.getVersion().set(versionProvider);
task.getReleaseNotes().set(releaseNotesProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void register(Project project) {
// @formatter:on

var owner = springRelease.getRepositoryOwner().get();
var name = project.getRootProject().getName();
var name = springRelease.getRepositoryName().get();
task.getGitHubAccessToken()
.set(ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY));
task.getRepository().set(new Repository(owner, name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;

import org.springframework.util.Assert;

public abstract class DeleteSaganReleaseTask extends DefaultTask {

public static final String TASK_NAME = "deleteSaganRelease";
Expand Down Expand Up @@ -54,6 +56,9 @@ public void deleteRelease() {
}

public static void register(Project project) {
var springRelease = project.getExtensions().findByType(SpringReleasePluginExtension.class);
Assert.notNull(springRelease, "Cannot find " + SpringReleasePluginExtension.class);

project.getTasks().register(TASK_NAME, DeleteSaganReleaseTask.class, (task) -> {
task.setGroup(SpringReleasePlugin.TASK_GROUP);
task.setDescription("Delete a version for the specified project on spring.io.");
Expand All @@ -66,9 +71,10 @@ public static void register(Project project) {
.map(RegularFileUtils::readString));
// @formatter:on

var name = springRelease.getRepositoryName().get();
task.getGitHubAccessToken()
.set(ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY));
task.getProjectName().set(project.getRootProject().getName());
task.getProjectName().set(name);
task.getVersion().set(versionProvider);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void register(Project project) {
.orElse(project.getRootProject().getVersion().toString());

var owner = springRelease.getRepositoryOwner().get();
var name = project.getRootProject().getName();
var name = springRelease.getRepositoryName().get();
task.getRepository().set(new Repository(owner, name));
task.getVersion().set(versionProvider);
task.getGitHubAccessToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

import org.springframework.util.Assert;

/**
* @author Steve Riesenberg
*/
Expand Down Expand Up @@ -68,16 +70,20 @@ public void getPreviousReleaseMilestone() {
}

public static void register(Project project) {
var springRelease = project.getExtensions().findByType(SpringReleasePluginExtension.class);
Assert.notNull(springRelease, "Cannot find " + SpringReleasePluginExtension.class);

project.getTasks().register(TASK_NAME, GetPreviousReleaseMilestoneTask.class, (task) -> {
task.setGroup(SpringReleasePlugin.TASK_GROUP);
task.setDescription("Finds the previous release version based on the current version.");

var versionProvider = ProjectUtils.getProperty(project, SpringReleasePlugin.CURRENT_VERSION_PROPERTY)
.orElse(project.getRootProject().getVersion().toString());

var name = springRelease.getRepositoryName().get();
task.getGitHubAccessToken()
.set(ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY));
task.getProjectName().set(project.getRootProject().getName());
task.getProjectName().set(name);
task.getVersion().set(versionProvider);
task.getPreviousReleaseMilestoneFile()
.set(project.getLayout().getBuildDirectory().file(OUTPUT_VERSION_PATH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void register(Project project) {
// @formatter:on

var owner = springRelease.getRepositoryOwner().get();
var name = project.getRootProject().getName();
var name = springRelease.getRepositoryName().get();
task.getRepository().set(new Repository(owner, name));
task.getGitHubAccessToken()
.set(ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void apply(Project project) {
// Register springRelease extension for DSL usage
var springRelease = project.getExtensions().create(EXTENSION_NAME, SpringReleasePluginExtension.class);
springRelease.getRepositoryOwner().convention("spring-projects");
springRelease.getRepositoryName().convention(project.getRootProject().getName());
springRelease.getReplaceSnapshotVersionInReferenceDocUrl().convention(false);

// Calculate the GitHub username for the provided access token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface SpringReleasePluginExtension {

Property<String> getRepositoryOwner();

Property<String> getRepositoryName();

Property<Integer> getWeekOfMonth();

Property<Integer> getDayOfWeek();
Expand Down

0 comments on commit 487ef26

Please sign in to comment.