Skip to content

Instantly share code, notes, and snippets.

@GregHib
Created December 14, 2020 10:04
Show Gist options
  • Save GregHib/5d18b88e19c9b5d99d27237ee4e190fb to your computer and use it in GitHub Desktop.
Save GregHib/5d18b88e19c9b5d99d27237ee4e190fb to your computer and use it in GitHub Desktop.
GithubIssueCloner.kt
import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.util.stream.Collectors
object GithubIssueCloner {
@JvmStatic
fun main(args: Array<String>) {
val fromOrg = ""
val fromRepo = ""
val toOrg = ""
val toRepo = ""
val personalAccessToken = ""
val mapper = ObjectMapper(JsonFactory())
val writer = mapper.writerWithDefaultPrettyPrinter()
val file = File("./issues.json")
val data = run("curl -X \"GET\" \"https://api.github.com/repos/$fromOrg/$fromRepo/issues?state=all&per_page=100&page=1\"")
file.writeText(data)
val input = File("./issue.json")
val tree = mapper.readTree(file)
tree.forEach {
if (it is ObjectNode) {
it.remove("assignee")
it.remove("assignees")
val milestone = it.get("milestone")
if (milestone != null && !milestone.isNull) {
it.remove("milestone")
}
}
writer.writeValue(input, it)
run("curl -X \"POST\" \"https://api.github.com/repos/$toOrg/$toRepo/issues\" -H \"Cookie: logged_in=no\" -H \"Authorization: token $personalAccessToken\" -H \"Content-Type: text/plain; charset=utf-8\" -d @issue.json")
}
}
fun run(command: String): String {
val pr = Runtime.getRuntime().exec(command)
val result = BufferedReader(
InputStreamReader(pr.inputStream))
.lines()
.collect(Collectors.joining("\n"))
return result.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment