Commit 0ab7816f authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added base tool to fetch issues from gitlab

parent 2727f142
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
<artifactId>BiopetTools</artifactId> <artifactId>BiopetTools</artifactId>
<dependencies> <dependencies>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-ws_2.10</artifactId>
<version>2.4.8</version>
</dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <artifactId>testng</artifactId>
......
package nl.lumc.sasc.biopet.tools
import java.io.File
import java.net.URI
import argonaut.Argonaut._
import argonaut.Json._
import argonaut._
import nl.lumc.sasc.biopet.utils.{ConfigUtils, ToolCommand}
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import play.api.libs.ws.ning.NingWSClient
import scala.concurrent.ExecutionContext.Implicits.global
/**
* Created by pjvan_thof on 10-10-16.
*/
object GitlabIssueToJira extends ToolCommand {
case class Args(gitlabUrl: String = null,
gitlabProject: String = null,
gitlabToken: String = null) extends AbstractArgs
class OptParser extends AbstractOptParser {
opt[String]("gitlabUrl") required () maxOccurs 1 valueName "<url>" action { (x, c) =>
c.copy(gitlabUrl = x)
}
opt[String]("gitlabProject") required () maxOccurs 1 valueName "<string>" action { (x, c) =>
c.copy(gitlabProject = x)
}
opt[String]("gitlabToken") required () maxOccurs 1 valueName "<string>" action { (x, c) =>
c.copy(gitlabToken = x)
}
}
def main(args: Array[String]): Unit = {
val argsParser = new OptParser
val cmdArgs = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
// Instantiation of the client
// In a real-life application, you would instantiate one, share it everywhere,
// and call wsClient.close() when you're done
val url = s"${cmdArgs.gitlabUrl}/api/v3/projects/${cmdArgs.gitlabProject.replace("/", "%2F")}/issues"
val wsClient = NingWSClient()
val bla = wsClient
.url(url)
//.withQueryString("page" -> "1")
.withHeaders("PRIVATE-TOKEN" -> cmdArgs.gitlabToken)
.get()
.map { wsResponse =>
if (! (200 to 299).contains(wsResponse.status)) {
logger.error(s"Received unexpected status ${wsResponse.status} : ${wsResponse.body}")
}
println(s"OK, received ${wsResponse.body}")
//println(s"The response header PRIVATE-TOKEN was ${wsResponse.header("PRIVATE-TOKEN")}")
ConfigUtils.textToJson(wsResponse.body)
}
Await.ready(bla, Duration.Inf)
println(bla.value.get.get.array.get.size)
bla.value.get.get match {
case a:JsonArray => println(a.size)
case a => println(a.getClass.getName)
}
println(bla.value.get.get.spaces2)
wsClient.close()
logger.info(url)
}
}
...@@ -117,11 +117,17 @@ object ConfigUtils extends Logging { ...@@ -117,11 +117,17 @@ object ConfigUtils extends Logging {
def fileToJson(configFile: File): Json = { def fileToJson(configFile: File): Json = {
logger.debug("Jsonfile: " + configFile) logger.debug("Jsonfile: " + configFile)
val jsonText = scala.io.Source.fromFile(configFile).mkString val jsonText = scala.io.Source.fromFile(configFile).mkString
textToJson(jsonText)
}
/** Make json aboject from a file */
def textToJson(jsonText: String): Json = {
logger.debug("jsonText: " + jsonText)
val json = Parse.parseOption(jsonText) val json = Parse.parseOption(jsonText)
logger.debug(json) logger.debug(json)
json getOrElse { json getOrElse {
throw new IllegalStateException("The config JSON file is either not properly formatted or not a JSON file, file: " + configFile) throw new IllegalStateException("The config JSON file is either not properly formatted or not a JSON file, file: " + jsonText)
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment