From 500ad3eaf0c6ba5361751704e38cba172ed5708f Mon Sep 17 00:00:00 2001 From: Steve Riesenberg <5248162+sjohnr@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:39:16 -0500 Subject: [PATCH] Use token-based authentication Closes gh-27 --- .../plugin/release/GenerateChangelogTask.java | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/release-plugin/src/main/java/io/spring/gradle/plugin/release/GenerateChangelogTask.java b/release-plugin/src/main/java/io/spring/gradle/plugin/release/GenerateChangelogTask.java index 542b037..73ad59b 100644 --- a/release-plugin/src/main/java/io/spring/gradle/plugin/release/GenerateChangelogTask.java +++ b/release-plugin/src/main/java/io/spring/gradle/plugin/release/GenerateChangelogTask.java @@ -50,11 +50,7 @@ public abstract class GenerateChangelogTask extends JavaExec { @Input @Optional - public abstract Property getUsername(); - - @Input - @Optional - public abstract Property getPassword(); + public abstract Property getGitHubAccessToken(); @OutputFile public abstract RegularFileProperty getReleaseNotesFile(); @@ -62,8 +58,7 @@ public abstract class GenerateChangelogTask extends JavaExec { @Override public void exec() { var version = getVersion().get(); - var username = getUsername().getOrNull(); - var password = getPassword().getOrNull(); + var gitHubAccessToken = getGitHubAccessToken().getOrNull(); var outputFile = getReleaseNotesFile().getAsFile().get(); var parent = outputFile.getParentFile(); if (!parent.exists() && !parent.mkdirs()) { @@ -71,8 +66,8 @@ public void exec() { } args("--spring.config.location=scripts/release/release-notes-sections.yml"); - if (username != null && password != null) { - args("--github.username=" + username, "--github.password=" + password); + if (gitHubAccessToken != null) { + args("--github.token=" + gitHubAccessToken); } args(version, outputFile.toString()); super.exec(); @@ -96,17 +91,8 @@ public static void register(Project project) { // @formatter:on task.getVersion().set(versionProvider); - if (project.hasProperty(SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY)) { - // @formatter:off - var usernameProvider = ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_USER_NAME_PROPERTY) - .orElse(ProjectUtils.findTaskByType(project, GetGitHubUserNameTask.class) - .getUsernameFile() - .map(RegularFileUtils::readString)); - // @formatter:on - task.getUsername().set(usernameProvider); - task.getPassword() - .set(ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY)); - } + task.getGitHubAccessToken() + .set(ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY)); task.getReleaseNotesFile().set(project.getLayout().getBuildDirectory().file(GENERATE_CHANGELOG_PATH)); }); }