Systematic Architecture [EN]
The blog on systems development/architecture, to be a beautiful, artistic one.
Showing posts with label
JIRA
.
Show all posts
Showing posts with label
JIRA
.
Show all posts
Friday, 25 December 2015
Scala JIRA
Scala JIRA ============ JIRA, an issue tracker can do a bunch of data import/export and operations - via CSV - via REST However neither of them responses 1000 items per request. So REST is better for a lot of data or complex operations. Atlassian provide Java library for JIRA REST, [JIRA REST Java Client (JRJC)](https://ecosystem.atlassian.net/wiki/display/JRJC/Home) When you program for JIRA REST, you would use it but I don't feel like using Java in this programming era. Thus I created a scaffold for JIRA REST with Scala. Why I create it and show here is there is no specific documentation for the latest JRJC somehow. - classes and their structures are changed. - its sbt configuration (Maven dependencies) not written anywhere. Let's show my scaffold. Here is dependencies in build.sbt. ```scala libraryDependencies += "com.atlassian.jira" % "jira-rest-java-client-api" % "3.0.0" libraryDependencies += "com.atlassian.jira" % "jira-rest-java-client-core" % "3.0.0" resolvers += "spring-milestones" at "http://repo.spring.io/libs-milestone/" ``` Here is my sample app, which needs more dependencies than the above. ```scala import java.net.URI import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory import org.joda.time.DateTime import org.joda.time.format._ import scala.collection.JavaConverters._ /** * Created on 2015/12/02. */ object Auth { def main(args: Array[String]) { val restClientFactory = new AsynchronousJiraRestClientFactory() // http://host:port/context/rest/api-name/api-version/resource-name import com.typesafe.config.ConfigFactory val conf = ConfigFactory.load("account.conf") //val JIRA_BASE_URL = "http://[team name].atlassian.net/plugins/servlet/oauth/request-token" val jiraBaseURL = conf.getString("baseurl") // JIRA_BASE_URL + "/plugins/servlet/oauth/request-token" val uri = new URI(jiraBaseURL) val username = conf.getString("username") val password = conf.getString("password") val client = restClientFactory.createWithBasicHttpAuthentication(uri, username, password) // Invoke the JRJC Client val promise = client.getUserClient().getUser(username) val user = promise.claim() client.getProjectClient().getAllProjects().claim().iterator().asScala.map(project => { println(project.getKey() + ": " + project.getName()) }) val dateTime = DateTime.now() val dateString = DateTimeFormat.forPattern("yyyy-MM-dd").print(dateTime) println("dateString=" + dateString) // up to 1000 items even if you specify more. val maxResults = 10 val searchJqlPromise = client.getSearchClient().searchJql(s"due=$dateString ORDER BY assignee", maxResults, null, null) searchJqlPromise.claim().getIssues.asScala.map(issue => { println(issue.getKey + ": " + issue.getSummary) }) // Print the result println(String.format("Your admin user's email address is: %s\r\n", user.getEmailAddress())); // Done println("Example complete. Now exiting."); System.exit(0); } } ``` The whole source codes are [HERE](https://github.com/lamusique/ScalaJIRA).
Older Posts
Home
Subscribe to:
Posts (Atom)