Skip to content

Commit

Permalink
Fix issue with jenkins job names with special characters not being en…
Browse files Browse the repository at this point in the history
…coded
  • Loading branch information
AMeng committed Dec 17, 2015
1 parent 411b9c4 commit e5593d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.util.UriUtils
import retrofit.RetrofitError

@CompileStatic
Expand All @@ -36,6 +37,10 @@ class BuildService {
@Autowired(required = false)
IgorService igorService

private String encode(uri) {
return UriUtils.encodeFragment(uri.toString(), "UTF-8")
}

List<String> getBuildMasters() {
if (!igorService) {
return []
Expand Down Expand Up @@ -69,7 +74,7 @@ class BuildService {
}
HystrixFactory.newMapCommand(GROUP, "jobConfig") {
try {
igorService.getJobConfig(buildMaster, job)
igorService.getJobConfig(buildMaster, encode(job))
} catch (RetrofitError e) {
if (e.response?.status == 404) {
throw new BuildMasterNotFound("Build master '${buildMaster}' not found")
Expand All @@ -86,7 +91,7 @@ class BuildService {
}
HystrixFactory.newListCommand(GROUP, "buildsForJob") {
try {
igorService.getBuilds(buildMaster, job)
igorService.getBuilds(buildMaster, encode(job))
} catch (RetrofitError e) {
if (e.response?.status == 404) {
throw new BuildMasterNotFound("Build master '${buildMaster}' not found")
Expand All @@ -103,7 +108,7 @@ class BuildService {
}
HystrixFactory.newMapCommand(GROUP, "buildDetails") {
try {
igorService.getBuild(buildMaster, job, number)
igorService.getBuild(buildMaster, encode(job), number)
} catch (RetrofitError e) {
if (e.response?.status == 404) {
throw new BuildMasterNotFound("Build master '${buildMaster}' not found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class BuildControllerSpec extends Specification {

final MASTER = 'MASTER'
final BUILD_NUMBER = 123
final JOB_NAME = "name/with/slashes"
final JOB_NAME = "name/with/slashes and spaces"
final JOB_NAME_ENCODED = "name/with/slashes%20and%20spaces"

void cleanup() {
server.shutdown()
Expand Down Expand Up @@ -77,7 +78,7 @@ class BuildControllerSpec extends Specification {

void 'should get a list of builds for a job'() {
given:
1 * igorService.getBuilds(MASTER, JOB_NAME) >> [["building":false, "number":111], ["building":false, "number":222]]
1 * igorService.getBuilds(MASTER, JOB_NAME_ENCODED) >> [["building":false, "number":111], ["building":false, "number":222]]

when:
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds/${MASTER}/builds/${JOB_NAME}")
Expand All @@ -89,7 +90,7 @@ class BuildControllerSpec extends Specification {

void 'should get a job config'() {
given:
1 * igorService.getJobConfig(MASTER, JOB_NAME) >> ['name': JOB_NAME, 'url': "http://test.com/job/${JOB_NAME}".toString()]
1 * igorService.getJobConfig(MASTER, JOB_NAME_ENCODED) >> ['name': JOB_NAME, 'url': "http://test.com/job/${JOB_NAME}".toString()]

when:
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds/${MASTER}/jobs/${JOB_NAME}")
Expand All @@ -101,7 +102,7 @@ class BuildControllerSpec extends Specification {

void 'should get a build'() {
given:
1 * igorService.getBuild(MASTER, JOB_NAME, BUILD_NUMBER.toString()) >> ["building":false, "number":BUILD_NUMBER]
1 * igorService.getBuild(MASTER, JOB_NAME_ENCODED, BUILD_NUMBER.toString()) >> ["building":false, "number":BUILD_NUMBER]

when:
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds/${MASTER}/build/${BUILD_NUMBER}/${JOB_NAME}")
Expand Down

0 comments on commit e5593d2

Please sign in to comment.