Last active
May 3, 2017 22:16
-
-
Save kdeenanauth/76297e0ef98b205f9c3c8d70376659cb to your computer and use it in GitHub Desktop.
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
class NexusRepo { | |
static def getPyPiAssetVersions(String baseUrl, String repository, String filter) { | |
if (filter == null) { | |
filter = '' | |
} | |
def post = new URL(baseUrl + "/service/extdirect").openConnection(); | |
def message = '{"action":"coreui_Component","method":"readAssets","data":[{"page":1,"start":0,"limit":10000,"sort":[{"property":"name","direction":"ASC"}],"filter":[{"property":"repositoryName","value":"' + | |
repository +'"},{"property":"filter","value":"' + | |
filter + '"}]}],"type":"rpc","tid":35}' | |
post.setRequestMethod("POST") | |
post.setDoOutput(true) | |
post.setRequestProperty("Content-Type", "application/json") | |
post.getOutputStream().write(message.getBytes("UTF-8")); | |
def postRC = post.getResponseCode(); | |
if(postRC.equals(200)) { | |
def jsonSlurper = new groovy.json.JsonSlurper() | |
def object = jsonSlurper.parseText(post.getInputStream().getText()) | |
assert object instanceof Map | |
assert object.result instanceof Map | |
def items = [] | |
for (int i=0; i < object.result.data.size(); i++) { | |
items.add(object.result.data[i].attributes.pypi.name + '==' + object.result.data[i].attributes.pypi.version) | |
} | |
items.sort().reverse() | |
} | |
} | |
} | |
return NexusRepo.getPyPiAssetVersions('http://localhost:8081', 'pypi-internal', null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment