Last active
August 5, 2019 07:00
-
-
Save thatsk/0bd61635dc510660fa8f93975dbd8fc0 to your computer and use it in GitHub Desktop.
Groovy Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
import groovy.json.JsonOutput | |
import groovy.json.JsonBuilder | |
def content = ''' | |
{ | |
"version": "1.0", | |
"repos" : [{ | |
"name": "service-config", | |
"source_root": "/service-config", | |
"mountpoint": "test", | |
"url" : "http://test.example.com", | |
"include_branch_name" : "false", | |
"branches" : [""], | |
"hooks": [{ | |
"type": "polling", | |
"interval": "15" | |
}] | |
}] | |
}''' | |
def cout = new StringBuilder(), cerr = new StringBuilder() | |
def gitbranch = 'git name-rev --name-only HEAD'.execute() | |
gitbranch.consumeProcessOutput(cout, cerr) | |
gitbranch.waitForOrKill(1000) | |
println "Command Output" | |
def slurped = new JsonSlurper().parseText(content) | |
slurped.repos[0].branches = "${cout.toString().trim()}" //array because you have an array in original json | |
def builder = new JsonBuilder(slurped) | |
println(builder.toPrettyString()) |
Author
thatsk
commented
Aug 1, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment