Skip to content

Commit

Permalink
Use token-based authentication
Browse files Browse the repository at this point in the history
Closes gh-27
  • Loading branch information
sjohnr committed Mar 20, 2024
1 parent cd7a1a5 commit 500ad3e
Showing 1 changed file with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,24 @@ public abstract class GenerateChangelogTask extends JavaExec {

@Input
@Optional
public abstract Property<String> getUsername();

@Input
@Optional
public abstract Property<String> getPassword();
public abstract Property<String> getGitHubAccessToken();

@OutputFile
public abstract RegularFileProperty getReleaseNotesFile();

@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()) {
throw new IllegalStateException("Unable to create " + outputFile);
}

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();
Expand All @@ -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));
});
}
Expand Down

0 comments on commit 500ad3e

Please sign in to comment.