Skip to content

Commit

Permalink
Version the Jenkins API endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
AMeng committed Dec 3, 2015
1 parent 75fbaba commit 111e1aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.HandlerMapping

@CompileStatic
@RequestMapping("/builds")
@RequestMapping("/v2/builds")
@RestController
class BuildController {
/*
Expand All @@ -50,19 +50,19 @@ class BuildController {

@RequestMapping(value = "/{buildMaster}/jobs/**", method = RequestMethod.GET)
Map getJobConfig(@PathVariable("buildMaster") String buildMaster, HttpServletRequest request) {
def job = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString().split('/').drop(4).join('/')
def job = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString().split('/').drop(5).join('/')
buildService.getJobConfig(buildMaster, job)
}

@RequestMapping(value = "/{buildMaster}/builds/**", method = RequestMethod.GET)
List getBuilds(@PathVariable("buildMaster") String buildMaster, HttpServletRequest request) {
def job = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)toString().split('/').drop(4).join('/')
def job = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)toString().split('/').drop(5).join('/')
buildService.getBuilds(buildMaster, job)
}

@RequestMapping(value = "/{buildMaster}/build/{number}/**", method = RequestMethod.GET)
Map getBuild(@PathVariable("buildMaster") String buildMaster, @PathVariable("number") String number, HttpServletRequest request) {
def job = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)toString().split('/').drop(5).join('/')
def job = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)toString().split('/').drop(6).join('/')
buildService.getBuild(buildMaster, job, number)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BuildControllerSpec extends Specification {
1 * igorService.getBuildMasters() >> [MASTER, "master2"]

when:
MockHttpServletResponse response = mockMvc.perform(get("/builds")
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds")
.accept(MediaType.APPLICATION_JSON)).andReturn().response

then:
Expand All @@ -68,7 +68,7 @@ class BuildControllerSpec extends Specification {
1 * igorService.getJobsForBuildMaster(MASTER) >> [JOB_NAME, "another_job"]

when:
MockHttpServletResponse response = mockMvc.perform(get("/builds/${MASTER}/jobs")
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds/${MASTER}/jobs")
.accept(MediaType.APPLICATION_JSON)).andReturn().response

then:
Expand All @@ -80,7 +80,7 @@ class BuildControllerSpec extends Specification {
1 * igorService.getBuilds(MASTER, JOB_NAME) >> [["building":false, "number":111], ["building":false, "number":222]]

when:
MockHttpServletResponse response = mockMvc.perform(get("/builds/${MASTER}/builds/${JOB_NAME}")
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds/${MASTER}/builds/${JOB_NAME}")
.accept(MediaType.APPLICATION_JSON)).andReturn().response

then:
Expand All @@ -92,7 +92,7 @@ class BuildControllerSpec extends Specification {
1 * igorService.getJobConfig(MASTER, JOB_NAME) >> ['name': JOB_NAME, 'url': "http://test.com/job/${JOB_NAME}".toString()]

when:
MockHttpServletResponse response = mockMvc.perform(get("/builds/${MASTER}/jobs/${JOB_NAME}")
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds/${MASTER}/jobs/${JOB_NAME}")
.accept(MediaType.APPLICATION_JSON)).andReturn().response

then:
Expand All @@ -104,7 +104,7 @@ class BuildControllerSpec extends Specification {
1 * igorService.getBuild(MASTER, JOB_NAME, BUILD_NUMBER.toString()) >> ["building":false, "number":BUILD_NUMBER]

when:
MockHttpServletResponse response = mockMvc.perform(get("/builds/${MASTER}/build/${BUILD_NUMBER}/${JOB_NAME}")
MockHttpServletResponse response = mockMvc.perform(get("/v2/builds/${MASTER}/build/${BUILD_NUMBER}/${JOB_NAME}")
.accept(MediaType.APPLICATION_JSON)).andReturn().response

then:
Expand Down

0 comments on commit 111e1aa

Please sign in to comment.