Skip to content

Commit

Permalink
allow empty github username within plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
evanc-mfw committed Nov 25, 2024
1 parent 831b44c commit 8e20d48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class PrivateRepositoryPlugin : Plugin<Any> {
propertyDelegate: PropertyDelegate,
configuration: PrivateRepositoryConfiguration
) {
var emptyUsername = false
configuration.repositories.forEach { repository ->
logger?.debug("Getting credentials for repository {}, provider = {}",
repository.url, repository.credentialProvider::class.simpleName)
Expand All @@ -70,6 +71,7 @@ class PrivateRepositoryPlugin : Plugin<Any> {
maven { maven ->
maven.url = repository.url
if (githubCredentials != null) {
emptyUsername = emptyUsername || githubCredentials.username.isBlank()
maven.credentials { credentials ->
credentials.username = githubCredentials.username
credentials.password = githubCredentials.token
Expand All @@ -78,6 +80,10 @@ class PrivateRepositoryPlugin : Plugin<Any> {
}
logger?.debug("Registered new maven dependency: {}", repository.url)
}
if (emptyUsername) {
logger?.warn("Detected usage of unset or empty GitHub username for at least one repository. This may" +
" result in an authorization issue depending on the token used.")
}
logger?.info("Configured ${PROJECT_PLUGIN_DATA.repositories.size} private repositories")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ open class PropertyGitHubCredentialProvider internal constructor(
override fun getCredentials(propertyDelegate: PropertyDelegate): GitHubRepositoryCredentials? {
try {
return GitHubRepositoryCredentials(
requireNotNullOrEmpty(propertyDelegate.resolveTo(usernameProperty)),
propertyDelegate.resolveTo<String>(usernameProperty) ?: "",
requireNotNullOrEmpty(propertyDelegate.resolveTo(tokenProperty))
)
} catch (ex: IllegalArgumentException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ abstract class StoreGitHubCredentialsTask : DefaultTask() {

val newLines = mutableListOf<String>()

if ((checkFlags and USERNAME_FLAG) > 0) {
if (username.isNullOrEmpty()) {
throw NullPointerException("GitHub username cannot be null or empty. " +
"Please check your environment variables or configure the task to use the correct username!")
}
if ((checkFlags and USERNAME_FLAG) > 0 && username != null) {
newLines.add("${entry.usernameProperty}=$username")
}
if ((checkFlags and TOKEN_FLAG) > 0) {
Expand Down

0 comments on commit 8e20d48

Please sign in to comment.