Hi guys,
I've been playing around with the JSON export/import functionality. It seems like a great way to go, except it seems to lack Attachment file location in the JSON.
Here is my question. I was thinking about using groovy's jsonSlurper to slurp the JSON in, modify the attachment(s) in the map, and then rebuild json via jsonBuilder.
Anyone do this before? I am relatively new to Groovy.. having a hard time trying to edit attachments in place.
For example, here is example issue (note -- I know the json may be borked -- I removed sections to make example smaller):
{ "links" : [ ], "projects" : [ { "externalName" : "Test Queue", "name" : "Test Queue", "key" : "TEST", "lead" : "TEST_triage", "description" : "This is a test.\n\n", "projectCategoryName" : "EXAMPLE", "assigneeType" : 2, "versions" : [ ], "components" : [ { "name" : "Foo", "lead" : "Foo Lead" } ], "issues" : [ { "key" : "TEST-10748", "summary" : "this is a test - please disregard.", "reporter" : "bryank", "assignee" : "bryank", "description" : "test", "issueType" : "Work Item", "status" : "Open", "priority" : "P3", "created" : 1401119754000, "updated" : 1401119754000, "labels" : [ ], "worklogs" : [ ], "voters" : [ ], "watchers" : [ "bryank" ], "subtasks" : [ ], "attachments" : [ ], "history" : [ ], "comments" : [ ], "customFieldValues" : [ ] } ] } ], "users" : [ { "name" : "test_triage", "fullname" : "Test Triage", "email" : "test@int.test.com", "groups" : [ "jira-users"], "active" : true }] }
If I slurp the json in, I can access sections like so:
import groovy.json.* def inputFile = new File("C:\\Users\\bryank\\Desktop\\ticket.json") def InputJSON = new JsonSlurper().parseText(inputFile.text) List issues = InputJSON.projects.issues issues.each { issue -> println(issue.key) }
I basically want to add attachment path information to each of the issues in the json dump file (note -- size of file, number of issues unknown). I read I should be using collect with the closure.. but I can't get the syntax down right.
When done, I want to rebuild into json, and test importing into jira.
I totally realize there may be much easier ways to go about this (csv attachment upload, jira cli, etc) -- this is more out of curiousity. File this under ("I'd really like to know how to modify json files prior to upload"))
Got this example from Cedric Champeau at nabble.com-- works like a charm:
import groovy.json.* def inputFile = new File("C:\\Users\\bryank\\Desktop\\ticket.json") def outputFile = new File("C:\\Users\\bryank\\Desktop\\ticket-out.json") def json = new JsonSlurper().parseText(inputFile.text) json.projects.each { p -> p.issues.each { issue -> issue.attachments = [[ name: "battarang.jpg", attacher: "admin", created: "2012-08-31T17:59:02.161+0100", uri: "http://optimus-prime/~batman/images/battarang.jpg", description: "This is optimus prime" ]] } } def builder = new JsonBuilder(json) println builder.toPrettyString() outputFile.withWriter { builder.writeTo(it) }
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.