Add Versioning without grab

This commit is contained in:
Jim Nicholson 2024-02-07 20:24:39 -08:00
parent d2d4e5b6f9
commit c0f2e31b97

View File

@ -1,19 +1,32 @@
#!/usr/bin/env groovy
import groovyx.net.http.URIBuilder
import java.net.URLEncoder
Map call(Map config = [:]) {
Map defaults = [
nexusBase: 'https://repo.thejimnicholson.com',
searchAPI: 'service/rest/v1/search',
repositoryName: 'tools'
queryParams: [
'repository': 'tools',
'sort': 'name',
'name': 'test.something'
]
]
Map runConfig = defaults + config
nexusSearch = new URIBuilder(runConfig.nexusBase)
/* groovylint-disable-next-line UnnecessarySetter */
nexusSearch.setPath(runConfig.searchAPI)
nexusSearch.addQueryParam('repository', runConfig.repositoryName)
nexusSearch = buildUrlWithQueryParams(runConfig.nexusBase, runConfig.queryParams)
runConfig.nexusQuery = nexusSearch
return runConfig
}
def buildUrlWithQueryParams(baseUrl, queryParams) {
def url = baseUrl
if (!queryParams.empty) {
def queryParamsString = queryParams.collect { key, value ->
"${URLEncoder.encode(key, 'UTF-8')}=${URLEncoder.encode(value, 'UTF-8')}"
}.join('&')
url += '?' + queryParamsString
}
return url
}