Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import org.gradle.api.provider.Property

internal inline fun <reified T : Any> ObjectFactory.property(): Property<T> = property(T::class.javaObjectType)

internal fun <T> Property<T>.orEmpty() = orNull ?: ""
internal fun <T : Any> Property<T>.orEmpty() = orNull ?: ""
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ package com.emergetools.android.gradle.util.providers
import com.emergetools.android.gradle.util.Git
import com.emergetools.android.gradle.util.GitHub
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters.None
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class GitBaseShaValueSource : ValueSource<String?, None> {
abstract class GitBaseShaValueSource : ValueSource<String, EmptyParameters> {
@get:Inject
abstract val execOperations: ExecOperations

override fun obtain(): String? {
override fun obtain(): String {
val git = Git(execOperations)
val gitHub = GitHub(execOperations)

var baseSha: String? = null
// GitHub workflows for pull_requests are invoked on a merge commit rather than branch commit.
if (gitHub.isSupportedGitHubEvent()) {
gitHub.baseSha()?.let { baseSha = it }
return if (gitHub.isSupportedGitHubEvent()) {
gitHub.baseSha() ?: ""
} else {
baseSha = git.baseSha()
git.baseSha() ?: ""
}

return baseSha
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package com.emergetools.android.gradle.util.providers

import com.emergetools.android.gradle.util.Git
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters.None
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class GitCurrentBranchValueSource : ValueSource<String?, None> {
abstract class GitCurrentBranchValueSource : ValueSource<String, EmptyParameters> {
@get:Inject
abstract val execOperations: ExecOperations

override fun obtain(): String? {
override fun obtain(): String {
val git = Git(execOperations)
return git.currentBranch()
return git.currentBranch() ?: ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package com.emergetools.android.gradle.util.providers

import com.emergetools.android.gradle.util.GitHub
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters.None
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class GitHubPrNumberValueSource : ValueSource<String?, None> {
abstract class GitHubPrNumberValueSource : ValueSource<String, EmptyParameters> {
@get:Inject
abstract val execOperations: ExecOperations

override fun obtain(): String? {
override fun obtain(): String {
val gitHub = GitHub(execOperations)
return gitHub.prNumber()?.toString()
return gitHub.prNumber()?.toString() ?: ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package com.emergetools.android.gradle.util.providers

import com.emergetools.android.gradle.util.GitHub
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters.None
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class GitHubRepoNameValueSource : ValueSource<String?, None> {
abstract class GitHubRepoNameValueSource : ValueSource<String, EmptyParameters> {
@get:Inject
abstract val execOperations: ExecOperations

override fun obtain(): String? {
override fun obtain(): String {
val gitHub = GitHub(execOperations)
return gitHub.repoName()
return gitHub.repoName() ?: ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package com.emergetools.android.gradle.util.providers

import com.emergetools.android.gradle.util.GitHub
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters.None
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class GitHubRepoOwnerValueSource : ValueSource<String?, None> {
abstract class GitHubRepoOwnerValueSource : ValueSource<String, EmptyParameters> {
@get:Inject
abstract val execOperations: ExecOperations

override fun obtain(): String? {
override fun obtain(): String {
val gitHub = GitHub(execOperations)
return gitHub.repoOwner()
return gitHub.repoOwner() ?: ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ package com.emergetools.android.gradle.util.providers
import com.emergetools.android.gradle.util.Git
import com.emergetools.android.gradle.util.GitHub
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters.None
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class GitPreviousShaValueSource : ValueSource<String?, None> {
abstract class GitPreviousShaValueSource : ValueSource<String, EmptyParameters> {
@get:Inject
abstract val execOperations: ExecOperations

override fun obtain(): String? {
override fun obtain(): String {
val git = Git(execOperations)
val gitHub = GitHub(execOperations)

var previousSha: String? = null
// GitHub workflows for pull_requests are invoked on a merge commit rather than branch commit.
if (gitHub.isSupportedGitHubEvent()) {
gitHub.previousSha()?.let { previousSha = it }
return if (gitHub.isSupportedGitHubEvent()) {
gitHub.previousSha() ?: ""
} else {
previousSha = git.previousSha()
git.previousSha() ?: ""
}

return previousSha
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ package com.emergetools.android.gradle.util.providers
import com.emergetools.android.gradle.util.Git
import com.emergetools.android.gradle.util.GitHub
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters.None
import org.gradle.api.provider.ValueSourceParameters
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class GitShaValueSource : ValueSource<String?, None> {
interface EmptyParameters : ValueSourceParameters

abstract class GitShaValueSource : ValueSource<String, EmptyParameters> {
@get:Inject
abstract val execOperations: ExecOperations

override fun obtain(): String? {
override fun obtain(): String {
val git = Git(execOperations)
val gitHub = GitHub(execOperations)

var sha: String? = null
// GitHub workflows for pull_requests are invoked on a merge commit rather than branch commit.
if (gitHub.isSupportedGitHubEvent()) {
gitHub.sha()?.let { sha = it }
return if (gitHub.isSupportedGitHubEvent()) {
gitHub.sha() ?: ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, I couldn't figure out how to re-use the orEmpty() function here and have it compile in the integration test. I will give it another pass tomorrow or in another PR.

} else {
sha = git.currentSha()
git.currentSha() ?: ""
}

return sha
}
}