diff --git a/CHANGELOG.md b/CHANGELOG.md index af506aa..2fece35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- In addition to `GRGIT_USER`, `GRGIT_PASS`, and `gh_token`, we also now look for: + - `GH_TOKEN`, `GITHUB_TOKEN` ([#53](https://github.com/diffplug/spotless-changelog/pull/53)) ## [3.1.1] - 2024-07-06 ### Fixed diff --git a/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java index ec40aad..a746890 100644 --- a/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java +++ b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java @@ -19,6 +19,7 @@ import com.jcraft.jsch.Session; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -41,6 +42,7 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory; import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig; +import pl.tlinkowski.annotation.basic.NullOr; /** API for doing the commit, tag, and push operations. See {@link GitCfg#withChangelog(File, ChangelogAndNext)}. */ public class GitActions implements AutoCloseable { @@ -200,7 +202,7 @@ protected void configure(OpenSshConfig.Host host, Session session) { } // similar to https://github.com/ajoberstar/grgit/blob/5766317fbe67ec39faa4632e2b80c2b056f5c124/grgit-core/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy - private static CredentialsProvider creds() { + private static @NullOr CredentialsProvider creds() { String username = System.getenv(GRGIT_USERNAME_ENV_VAR); if (username != null) { String password = System.getenv(GRGIT_PASSWORD_ENV_VAR); @@ -209,18 +211,25 @@ private static CredentialsProvider creds() { } return new UsernamePasswordCredentialsProvider(username, password); } - username = System.getenv(GH_TOKEN_ENV_VAR); - if (username != null) { - return new UsernamePasswordCredentialsProvider(username, ""); + String githubToken = GITHUB_VARS.stream() + .map(System::getenv) + .filter(Objects::nonNull) + .findFirst().orElse(null); + if (githubToken != null) { + return new UsernamePasswordCredentialsProvider(githubToken, ""); } return null; } private static final String GRGIT_USERNAME_ENV_VAR = "GRGIT_USER"; private static final String GRGIT_PASSWORD_ENV_VAR = "GRGIT_PASS"; - private static final String GH_TOKEN_ENV_VAR = "gh_token"; + private static final List GITHUB_VARS = Arrays.asList("GH_TOKEN", "GITHUB_TOKEN", "gh_token"); private static List envVars() { - return Arrays.asList(GRGIT_USERNAME_ENV_VAR, GRGIT_PASSWORD_ENV_VAR, GH_TOKEN_ENV_VAR); + var list = new ArrayList(); + list.addAll(GITHUB_VARS); + list.add(GRGIT_USERNAME_ENV_VAR); + list.add(GRGIT_PASSWORD_ENV_VAR); + return list; } }