Skip to content

Commit

Permalink
Merge branch 'master' into #1201-add-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloox authored Oct 13, 2020
2 parents 249ba1c + 425e668 commit b6acff1
Showing 1 changed file with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
package flank.scripts.testartifacts.core

import com.jcabi.github.Repo
import java.io.File

fun Context.resolveArtifacts(repo: Repo = testArtifactsRepo()) {
resolveRemotelyOrFallback(
repo = repo,
fallback = { resolveFallback(repo) }
)
}

private fun Context.resolveRemotelyOrFallback(repo: Repo, fallback: () -> Unit) {
fun Context.resolveArtifacts(
repo: Repo = testArtifactsRepo()
) {
if (isNewVersionAvailable(repo)) {
downloadFixtures()
unzipTestArtifacts()
linkArtifacts()
} else fallback()
}

private fun Context.resolveFallback(repo: Repo) {
projectRoot.testArtifacts(branch).run {
} else projectRoot.testArtifacts(branch).run {
if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath")
else tryResolveForMaster(repo)
else copy(branch = "master").run {
if (isNewVersionAvailable(repo)) {
downloadFixtures()
unzipTestArtifacts()
linkArtifacts()
} else projectRoot.testArtifacts(branch).run {
if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath")
else throw Exception("Cannot resolve test artifacts")
}
}
}
}

private fun Context.tryResolveForMaster(repo: Repo) {
copy(branch = "master").resolveRemotelyOrFallback(
repo = repo,
fallback = { projectRoot.testArtifacts(branch).resolveLocallyOrThrow(branch) }
)
}

private fun File.resolveLocallyOrThrow(branch: String) {
if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath")
else throw Exception("Cannot resolve test artifacts")
}

0 comments on commit b6acff1

Please sign in to comment.