From bbcd18438e3085ecd3947ef856cd48bbc83646c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Fri, 23 Jun 2023 15:38:37 +0200 Subject: [PATCH] Reinstate Gradle 5 compatibility (#144) (#145) ## Description Reinstate Gradle 5 compatibility by working around a bug resolved in gradle/gradle@3f8ddc9a70fa8715dc28e3994bc65f07bc74740f Fixes #144 ## Changes * ![FIX] broken Gradle 5 compatibility [FIX]: https://resources.atlas.wooga.com/icons/icon_fix.svg "Fix" --- .../base/internal/GithubClientFactory.groovy | 13 ++++++----- .../base/internal/RepositoryInfo.groovy | 23 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/groovy/wooga/gradle/github/base/internal/GithubClientFactory.groovy b/src/main/groovy/wooga/gradle/github/base/internal/GithubClientFactory.groovy index 4f22cbb..6b842ec 100644 --- a/src/main/groovy/wooga/gradle/github/base/internal/GithubClientFactory.groovy +++ b/src/main/groovy/wooga/gradle/github/base/internal/GithubClientFactory.groovy @@ -12,14 +12,15 @@ class GithubClientFactory { Provider password, Provider token) { //a non-empty provider if any credentials are available - Provider hasCredsProvider = username.orElse(password).orElse(token).orElse(""). - map({ - return it == "" && !hasExternalCredentials()? null : true - }) - return hasCredsProvider.map({ + return username.orElse(password).orElse(token).orElse(""). + map { + def hasCreds = it == "" && !hasExternalCredentials()? null : true + if (hasCreds == null) { + return null + } return new GithubClientFactory(). createGithubClient(username.getOrNull(), password.getOrNull(), token.getOrNull()) - }) + } } private static boolean hasExternalCredentials() { diff --git a/src/main/groovy/wooga/gradle/github/base/internal/RepositoryInfo.groovy b/src/main/groovy/wooga/gradle/github/base/internal/RepositoryInfo.groovy index e6521e7..deb0464 100644 --- a/src/main/groovy/wooga/gradle/github/base/internal/RepositoryInfo.groovy +++ b/src/main/groovy/wooga/gradle/github/base/internal/RepositoryInfo.groovy @@ -24,8 +24,10 @@ class RepositoryInfo { Provider getRepositoryNameFromLocalGit() { return grgitProvider.map { git -> - git.remote.list().find {it.name == DEFAULT_REMOTE && it.url.contains(GITHUB_DOMAIN)}?: null - }.map{remote -> + def remote = git.remote.list().find {it.name == DEFAULT_REMOTE && it.url.contains(GITHUB_DOMAIN)}?: null + if (remote == null) { + return null + } def remoteURL = remote.url def domainIndex = remoteURL.indexOf(GITHUB_DOMAIN) def urlAfterDomain = remoteURL.substring(domainIndex + GITHUB_DOMAIN.length() + 1) @@ -34,11 +36,16 @@ class RepositoryInfo { } Provider getBranchNameFromLocalGit() { - return grgitProvider. - map { git -> git.branch.current() }. - map { currentBranch -> - currentBranch.trackingBranch != null ? currentBranch.trackingBranch : currentBranch - }. - map{branch -> branch.name } + return grgitProvider.map { git -> + def currentBranch = git.branch.current() + if (currentBranch == null) { + return null + } + def branch = currentBranch.trackingBranch != null ? currentBranch.trackingBranch : currentBranch + if (branch == null) { + return null + } + branch.name + } } }