mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Convert github-milestone-report.groovy to main.kts (#2777)
* Convert milestore-report to main.kts * Fix Detekt failures * Move CLI parsing to CLIKT
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
#!/usr/bin/env groovy
|
||||
import groovy.cli.commons.CliBuilder
|
||||
@groovy.lang.Grab('org.kohsuke:github-api:1.112')
|
||||
import org.kohsuke.github.*
|
||||
|
||||
// arguments parsing
|
||||
|
||||
def cli = new CliBuilder().tap {
|
||||
user(type: String, "Github user or organization. Default: detekt")
|
||||
project(type: String, "Github project. Default: detekt")
|
||||
milestone(type: int, "Milestone number. Default: latest milestone.")
|
||||
h(longOpt: 'help', "Prints this usage.")
|
||||
}
|
||||
|
||||
def options = cli.parse(args)
|
||||
|
||||
if (options.h) {
|
||||
cli.usage()
|
||||
System.exit(0)
|
||||
}
|
||||
|
||||
// formatting helpers
|
||||
|
||||
static def entry(issue) {
|
||||
entry(issue.title.trim(), issue.number, issue.getHtmlUrl())
|
||||
}
|
||||
|
||||
static def entry(content, issueId, issueUrl) {
|
||||
"- $content - [#$issueId]($issueUrl)"
|
||||
}
|
||||
|
||||
static def formatIssues(issues) {
|
||||
issues.collect { entry(it) }.join("\n") + "\n"
|
||||
}
|
||||
|
||||
static def footer(footer, url) {
|
||||
"See all issues at: [$footer]($url)"
|
||||
}
|
||||
|
||||
static def header(name) {
|
||||
"#### $name\n"
|
||||
}
|
||||
|
||||
static def section(name) {
|
||||
"##### $name\n"
|
||||
}
|
||||
|
||||
// connect to GitHub
|
||||
|
||||
def user = options.user ?: "detekt"
|
||||
def project = options.project ?: "detekt"
|
||||
def github = GitHub.connectAnonymously()
|
||||
def repository = github.getUser(user).getRepository(project)
|
||||
def milestones = repository
|
||||
.listMilestones(GHIssueState.OPEN)
|
||||
.sort { it.number }
|
||||
def milestoneId = options.milestone ?: milestones.last().number
|
||||
|
||||
// get milestone and issue data
|
||||
|
||||
def milestone = repository.getMilestone(milestoneId)
|
||||
def issues = repository.getIssues(GHIssueState.ALL, milestone)
|
||||
|
||||
def milestoneTitle = milestone.title.trim()
|
||||
def groups = issues.groupBy { it.labels.find { it.name == "housekeeping" } == null }
|
||||
def (issuesForUsers, issuesForDevs) = [true, false].collect { groups[it] }
|
||||
|
||||
// print report
|
||||
|
||||
def content = new StringBuilder().tap {
|
||||
append(header(milestoneTitle))
|
||||
append("\n")
|
||||
append(section("Notable Changes"))
|
||||
append("\n")
|
||||
append(section("Migration"))
|
||||
append("\n")
|
||||
append(section("Changelog"))
|
||||
append("\n")
|
||||
append(formatIssues(issuesForUsers))
|
||||
append("\n")
|
||||
append(section("Housekeeping & Refactorings"))
|
||||
append("\n")
|
||||
append(formatIssues(issuesForDevs))
|
||||
append("\n")
|
||||
append(footer(milestoneTitle, milestone.getHtmlUrl()))
|
||||
}.toString()
|
||||
|
||||
println(content)
|
||||
|
||||
// write report to disk
|
||||
|
||||
def tempFile = File.createTempFile(project, "_$milestone.title")
|
||||
tempFile.write(content)
|
||||
|
||||
println("\nContent saved to $tempFile.path")
|
||||
98
scripts/github-milestone-report.main.kts
Executable file
98
scripts/github-milestone-report.main.kts
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/bin/sh
|
||||
//bin/true; exec kotlinc -script "$0" -- "$@"
|
||||
|
||||
/**
|
||||
* Script to prepare release notes for the upcoming Detekt release
|
||||
*
|
||||
* You need kotlin 1.3.70+ installed on your machine
|
||||
*/
|
||||
|
||||
@file:DependsOn("org.kohsuke:github-api:1.112")
|
||||
@file:DependsOn("com.github.ajalt:clikt:2.7.1")
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.parameters.options.default
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.types.int
|
||||
import org.kohsuke.github.GitHub
|
||||
import org.kohsuke.github.GHIssue
|
||||
import org.kohsuke.github.GHIssueState
|
||||
import org.kohsuke.github.GHMilestone
|
||||
import org.kohsuke.github.GHRepository
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
||||
class GithubMilestoneReport : CliktCommand() {
|
||||
|
||||
// arguments parsing
|
||||
val user : String by option("-u", help = "Github user or organization. Default: detekt").default("detekt")
|
||||
val project : String by option("-p", help = "Github project. Default: detekt").default("detekt")
|
||||
val milestone : Int? by option("-m", help = "Milestone number. Default: latest milestone.").int()
|
||||
|
||||
override fun run() {
|
||||
|
||||
// connect to GitHub
|
||||
val github: GitHub = GitHub.connectAnonymously()
|
||||
val ghRepository: GHRepository = github.getUser(user).getRepository(project)
|
||||
val milestones = ghRepository.listMilestones(GHIssueState.OPEN).toMutableList()
|
||||
milestones.sortBy { it.number }
|
||||
val milestoneId = milestone ?: milestones.last().number
|
||||
|
||||
// get milestone and issue data
|
||||
|
||||
val ghMilestone: GHMilestone = ghRepository.getMilestone(milestoneId)
|
||||
val ghIssues: MutableList<GHIssue> = ghRepository.getIssues(GHIssueState.ALL, ghMilestone)
|
||||
|
||||
val milestoneTitle = ghMilestone.title.trim()
|
||||
val groups = ghIssues.groupBy { issue ->
|
||||
issue.labels.any { it.name == "housekeeping" }
|
||||
}
|
||||
val (issuesForUsers, issuesForDevs) = groups[false] to groups[true]
|
||||
|
||||
// print report
|
||||
|
||||
val content = StringBuilder().apply {
|
||||
append(header(milestoneTitle))
|
||||
append("\n")
|
||||
append(section("Notable Changes"))
|
||||
append("\n")
|
||||
append(section("Migration"))
|
||||
append("\n")
|
||||
append(section("Changelog"))
|
||||
append("\n")
|
||||
append(formatIssues(issuesForUsers))
|
||||
append("\n")
|
||||
append(section("Housekeeping & Refactorings"))
|
||||
append("\n")
|
||||
append(formatIssues(issuesForDevs))
|
||||
append("\n")
|
||||
append(footer(milestoneTitle, ghMilestone.htmlUrl))
|
||||
}.toString()
|
||||
|
||||
println(content)
|
||||
|
||||
// write report to disk
|
||||
|
||||
val tempFile: File = File.createTempFile(project, "_$milestoneId.title")
|
||||
tempFile.writeText(content)
|
||||
|
||||
println("\nContent saved to ${tempFile.path}")
|
||||
}
|
||||
|
||||
// formatting helpers
|
||||
|
||||
private fun formatIssues(issues: List<GHIssue>?) =
|
||||
issues?.joinToString(separator = "\n", postfix = "\n") { entry(it) } ?: ""
|
||||
|
||||
private fun entry(issue: GHIssue) = entry(issue.title.trim(), issue.number, issue.htmlUrl)
|
||||
|
||||
private fun entry(content: String, issueId: Int, issueUrl: URL) = "- $content - [#$issueId]($issueUrl)"
|
||||
|
||||
private fun footer(footer: String, url: URL) = "See all issues at: [$footer]($url)"
|
||||
|
||||
private fun header(name: String) = "#### $name\n"
|
||||
|
||||
private fun section(name: String) = "##### $name\n"
|
||||
}
|
||||
|
||||
GithubMilestoneReport().main(args)
|
||||
Reference in New Issue
Block a user