mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Implement script to download given analysis projects
This commit is contained in:
69
scripts/get_analysis_projects.groovy
Normal file
69
scripts/get_analysis_projects.groovy
Normal file
@@ -0,0 +1,69 @@
|
||||
@Grab('org.vcsreader:vcsreader:1.1.0')
|
||||
import org.vcsreader.VcsProject
|
||||
import org.vcsreader.vcs.VcsError
|
||||
import org.vcsreader.vcs.git.GitVcsRoot
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
HELP_MESSAGE = """
|
||||
Usage: groovy get_analysis_projects.groovy [/path/to/storing/folder]
|
||||
"""
|
||||
|
||||
def projects = [
|
||||
"git@github.com:arrow-kt/arrow.git",
|
||||
"git@github.com:shyiko/ktlint.git"
|
||||
]
|
||||
|
||||
if (args.size() == 0) {
|
||||
println(HELP_MESSAGE)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
def storingFolder = Paths.get(args[0])
|
||||
|
||||
if (Files.notExists(storingFolder)) {
|
||||
Files.createDirectories(storingFolder)
|
||||
}
|
||||
|
||||
def gits = projects.collect { asGitRepo(storingFolder, it) }
|
||||
new VcsProject(gits) // sets observers, prevents NPE
|
||||
gits.parallelStream().forEach { handleProject(it) }
|
||||
|
||||
static asGitRepo(root, gitUrl) {
|
||||
def index = gitUrl.indexOf("/") + 1
|
||||
def name = gitUrl.substring(index)
|
||||
index = name.indexOf(".")
|
||||
name = name.substring(0, index)
|
||||
new GitVcsRoot(root.resolve(name).toString(), gitUrl)
|
||||
}
|
||||
|
||||
static handleProject(git) {
|
||||
def filePath = Paths.get(git.repoFolder())
|
||||
def fileName = filePath.fileName.toString()
|
||||
|
||||
try {
|
||||
if (Files.exists(filePath)) {
|
||||
def result = git.update()
|
||||
if (!result.isSuccessful()) {
|
||||
throw new IllegalStateException(extractVcsErrors(result.exceptions()))
|
||||
}
|
||||
println("Updated existing repo $fileName")
|
||||
} else {
|
||||
def cloneResult = git.cloneIt()
|
||||
if (!cloneResult.isSuccessful()) {
|
||||
throw new IllegalStateException(extractVcsErrors(cloneResult.exceptions()))
|
||||
}
|
||||
println("Finished cloning $fileName")
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
println("Error while handling $fileName: \n$ex.message")
|
||||
}
|
||||
}
|
||||
|
||||
static String extractVcsErrors(exceptions) {
|
||||
exceptions.stream()
|
||||
.filter { VcsError.isInstance(it) }
|
||||
.collect { it.message }
|
||||
.join("\n")
|
||||
}
|
||||
45
scripts/github-milestone-report.groovy
Normal file
45
scripts/github-milestone-report.groovy
Normal file
@@ -0,0 +1,45 @@
|
||||
@groovy.lang.Grab('org.kohsuke:github-api:1.85')
|
||||
import org.kohsuke.github.*
|
||||
|
||||
class Report {
|
||||
static def section(header) {
|
||||
"#### $header"
|
||||
}
|
||||
|
||||
static def entry(content, issueId, issueUrl) {
|
||||
"- $content - [#$issueId]($issueUrl)"
|
||||
}
|
||||
|
||||
static def footer(footer, url) {
|
||||
"See all issues at: [$footer]($url)"
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() > 3) throw new IllegalArgumentException("Usage: [userId] [repositoryId] [milestoneId]")
|
||||
|
||||
def user = args.size() > 0 ? args[0] : "arturbosch"
|
||||
def repo = args.size() > 1 ? args[1] : "detekt"
|
||||
|
||||
def github = GitHub.connectAnonymously()
|
||||
def repository = github.getUser(user).getRepository(repo)
|
||||
|
||||
def milestones = repository.listMilestones(GHIssueState.OPEN)
|
||||
def sortedMilestones = milestones.sort { it.number }
|
||||
def mId = args.size() > 2 ? args[2].toInteger() : sortedMilestones.last().number
|
||||
def milestone = repository.getMilestone(mId)
|
||||
def issues = repository.getIssues(GHIssueState.ALL, milestone)
|
||||
|
||||
def section = Report.section(milestone.title.trim()) + "\n"
|
||||
def issuesString = issues.collect {
|
||||
(Report.entry(it.title.trim(), it.number, it.getHtmlUrl()))
|
||||
}.join("\n") + "\n"
|
||||
def footer = Report.footer(milestone.title.trim(), milestone.getHtmlUrl())
|
||||
|
||||
println(section)
|
||||
println(issuesString)
|
||||
println(footer)
|
||||
|
||||
println()
|
||||
def tempFile = File.createTempFile(repo, "_$milestone.title")
|
||||
tempFile.write("$section\n$issuesString\n$footer")
|
||||
println("Content saved to $tempFile.path")
|
||||
Reference in New Issue
Block a user