Skip to content

Commit

Permalink
Update net.wooga.github plugin to 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Feb 16, 2023
1 parent 9d8be63 commit f594319
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 113 deletions.
2 changes: 1 addition & 1 deletion gradle/build-logic/build-logic.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dependencyAnalysis {
}
bundle("net.wooga.github.gradle.plugin") {
includeDependency("net.wooga.github:net.wooga.github.gradle.plugin")
includeDependency("gradle.plugin.net.wooga.gradle:atlas-github")
includeDependency("net.wooga.gradle:github")
}
bundle("org.ajoberstar.grgit.service.gradle.plugin") {
includeDependency("org.ajoberstar.grgit.service:org.ajoberstar.grgit.service.gradle.plugin")
Expand Down
194 changes: 86 additions & 108 deletions gradle/build-logic/src/main/kotlin/net/kautler/publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import net.kautler.util.updateVersion
import net.researchgate.release.ReleasePlugin
import org.gradle.tooling.GradleConnector
import org.kohsuke.github.GHIssueState.OPEN
import org.kohsuke.github.GitHub
import wooga.gradle.github.base.tasks.Github
import wooga.gradle.github.publish.PublishMethod.update
import wooga.gradle.github.publish.tasks.GithubPublish
import java.awt.GraphicsEnvironment.isHeadless
Expand Down Expand Up @@ -59,7 +59,6 @@ apply(plugin = "net.researchgate.release")
extra["release.useAutomaticVersion"] = boolean(project, "release.useAutomaticVersion").getValue()
extra["release.releaseVersion"] = optionalString(project, "release.releaseVersion").getValue()
extra["release.newVersion"] = optionalString(project, "release.newVersion").getValue()
extra["github.token"] = optionalString(project, "github.token").getValue()

val majorVersion: String by project

Expand All @@ -71,30 +70,6 @@ release {
}
}

val githubRepositoryName by lazy(NONE) {
grgitService
.service
.get()
.grgit
.remote
.list()
.find { it.name == "origin" }
?.let { remote ->
Regex(
"""(?x)
(?:
://([^@]++@)?+github\.com(?::\d++)?+/ |
([^@]++@)?+github\.com:
)
(?<repositoryName>.*)
\.git
"""
)
.find(remote.url)
?.let { it.groups["repositoryName"]!!.value }
} ?: "Vampire/setup-wsl"
}

val releasePlugin by lazy(NONE) {
plugins.findPlugin(ReleasePlugin::class)!!
}
Expand All @@ -103,77 +78,6 @@ val releaseTagName by lazy(NONE) {
releasePlugin.tagName()!!
}

internal val github by lazy(NONE) {
GitHub.connectUsingOAuth(extra["github.token"] as String)!!
}

val releaseBody by lazy(NONE) {
val releaseBody = grgitService
.service
.get()
.grgit
.log {
includes.add(release.git.requireBranch)
github.getRepository(githubRepositoryName).latestRelease?.apply {
excludes.add(tagName)
}
}
.filter { commit ->
!commit.shortMessage.startsWith("[Gradle Release Plugin] ")
}
.asReversed()
.joinToString("\n") { commit ->
"- ${commit.shortMessage} [${commit.id}]"
}

if (isHeadless()) {
return@lazy releaseBody
}

val result = CompletableFuture<String>()

SwingUtilities.invokeLater {
val initialReleaseBody = """
# Highlights
-
# Details
""".trimIndent() + releaseBody

val textArea = JTextArea(initialReleaseBody)

val parentFrame = JFrame().apply {
isUndecorated = true
setLocationRelativeTo(null)
isVisible = true
}

val resetButton = JButton("Reset").apply {
addActionListener {
textArea.text = initialReleaseBody
}
}

result.complete(
try {
when (showOptionDialog(
parentFrame, JScrollPane(textArea), "Release Body",
DEFAULT_OPTION, QUESTION_MESSAGE, null,
arrayOf("OK", resetButton), null
)) {
OK_OPTION -> textArea.text!!
else -> releaseBody
}
} finally {
parentFrame.dispose()
}
)
}

result.join()!!
}

val releaseVersion get() = !"$version".endsWith("-SNAPSHOT")

val removeDistributionsFromGit by tasks.registering {
Expand All @@ -196,6 +100,12 @@ tasks.updateVersion {
dependsOn(removeDistributionsFromGit)
}

val gitHubToken by optionalString("github.token", project)

github {
token.set(provider { gitHubToken })
}

configure(listOf(tasks.release, tasks.runBuildTasks)) {
configure {
actions.clear()
Expand All @@ -222,29 +132,98 @@ configure(listOf(tasks.release, tasks.runBuildTasks)) {

tasks.withType<GithubPublish>().configureEach {
onlyIf { releaseVersion }
repositoryName(githubRepositoryName)
tagName(Callable { releaseTagName })
releaseName(Callable { releaseTagName })
tagName.set(provider { releaseTagName })
releaseName.set(provider { releaseTagName })
}

tasks.githubPublish {
// work-around for https://github.com/ajoberstar/grgit/pull/382
//usesService(grgitService.service)
body { releaseBody }
draft(true)
body.set(provider {
val releaseBody = grgitService
.service
.get()
.grgit
.log {
includes.add(release.git.requireBranch)
github
.clientProvider
.get()
.getRepository(github.repositoryName.get())
.latestRelease
?.apply {
excludes.add(tagName)
}
}
.filter { commit ->
!commit.shortMessage.startsWith("[Gradle Release Plugin] ")
}
.asReversed()
.joinToString("\n") { commit ->
"- ${commit.shortMessage} [${commit.id}]"
}

if (isHeadless()) {
return@provider releaseBody
}

val result = CompletableFuture<String>()

SwingUtilities.invokeLater {
val initialReleaseBody = """
# Highlights
-
# Details
""".trimIndent() + releaseBody

val textArea = JTextArea(initialReleaseBody)

val parentFrame = JFrame().apply {
isUndecorated = true
setLocationRelativeTo(null)
isVisible = true
}

val resetButton = JButton("Reset").apply {
addActionListener {
textArea.text = initialReleaseBody
}
}

result.complete(
try {
when (showOptionDialog(
parentFrame, JScrollPane(textArea), "Release Body",
DEFAULT_OPTION, QUESTION_MESSAGE, null,
arrayOf("OK", resetButton), null
)) {
OK_OPTION -> textArea.text!!
else -> releaseBody
}
} finally {
parentFrame.dispose()
}
)
}

return@provider result.join()!!
})
draft.set(true)
}

val undraftGithubRelease by tasks.registering(GithubPublish::class) {
publishMethod = update
publishMethod.set(update)
}

val finishMilestone by tasks.registering {
val finishMilestone by tasks.registering(Github::class) {
enabled = releaseVersion
// work-around for https://github.com/ajoberstar/grgit/pull/382
//usesService(grgitService.service)

doLast("finish milestone") {
github.getRepository(githubRepositoryName)!!.apply {
repository.apply {
listMilestones(OPEN)
.find { it.title == "Next Version" }!!
.apply {
Expand Down Expand Up @@ -312,14 +291,13 @@ tasks.updateVersion {
dependsOn(undraftGithubRelease)
}

val checkBranchProtectionCompatibility by tasks.registering {
val checkBranchProtectionCompatibility by tasks.registering(Github::class) {
// work-around for https://github.com/ajoberstar/grgit/pull/382
//usesService(grgitService.service)

doLast {
check(
!github
.getRepository(githubRepositoryName)!!
!repository
.getBranch(release.git.requireBranch)
.protection
.enforceAdmins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.gradle.api.Project
import org.gradle.api.Task
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
import kotlin.properties.PropertyDelegateProvider as KotlinPropertyDelegateProvider

sealed class Property<out T> constructor(
private val default: () -> T,
Expand Down Expand Up @@ -137,20 +138,19 @@ sealed class Property<out T> constructor(
}
}

//TODO: ": PropertyDelegateProvider" when Kotlin 1.4 is used in the build scripts
class PropertyDelegateProvider<out T>(
private val default: () -> T,
private val propertyName: String? = null,
private val project: Project? = null,
private val delegateFactory: (() -> T, String, Project) -> Property<T>
) {
) : KotlinPropertyDelegateProvider<Any?, Property<T>> {
operator fun provideDelegate(thisRef: Project, property: KProperty<*>) =
delegateFactory(default, propertyName ?: property.name, project ?: thisRef)

operator fun provideDelegate(thisRef: Task, property: KProperty<*>) =
provideDelegate(thisRef.project, property)

operator fun provideDelegate(thisRef: Any?, property: KProperty<*>) =
override operator fun provideDelegate(thisRef: Any?, property: KProperty<*>) =
project?.let {
provideDelegate(it, property)
} ?: error(
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[versions]
build-github-api = "1.313"
build-gradle-plugin-dependency-analysis = "1.19.0"
build-gradle-plugin-github = "1.4.0"
build-gradle-plugin-github = "3.0.0"
build-gradle-plugin-grgit = "5.0.0"
build-gradle-plugin-refresh-versions = "0.51.0"
build-gradle-plugin-release = "2.8.1"
Expand Down

0 comments on commit f594319

Please sign in to comment.