Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw an error when GitHub API call fails #110

Merged
merged 1 commit into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/test/groovy/GithubApiCallStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,23 @@ class GithubApiCallStepTests extends BasePipelineTest {
void testRequestError() throws Exception {
helper.registerAllowedMethod("httpRequest", [Map.class], {
return """{
"Code": "404",
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}"""
})
def script = loadScript("vars/githubApiCall.groovy")
def ret = script.call(token: "dummy", url: "http://error")
try {
script.call(token: "dummy", url: "http://error")
} catch(e) {
println e.toString()
}
printCallStack()
assertTrue(ret instanceof Map)
assertJobStatusSuccess()
assertTrue(helper.callStack.findAll { call ->
call.methodName == "error"
}.any { call ->
callArgsToString(call).contains('makeGithubApiCall: The REST API call http://error return the message : Not Found')
})
}

@Test
Expand All @@ -139,10 +147,17 @@ class GithubApiCallStepTests extends BasePipelineTest {
throw new Exception('Failure')
})
def script = loadScript("vars/githubApiCall.groovy")
def ret = script.call(token: "dummy", url: "http://error")
try{
script.call(token: "dummy", url: "http://error")
} catch(e) {
println e.toString()
}
printCallStack()
assertTrue(ret.message == "java.lang.Exception: Failure")
assertJobStatusSuccess()
assertTrue(helper.callStack.findAll { call ->
call.methodName == "error"
}.any { call ->
callArgsToString(call).contains('makeGithubApiCall: The REST API call http://error return the message : java.lang.Exception: Failure')
})
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion vars/githubApiCall.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def call(Map params = [:]){
if(ret instanceof List && ret.size() == 0){
log(level: 'WARN', text: "makeGithubApiCall: The REST API call ${url} return 0 elements")
} else if(ret instanceof Map && ret.containsKey('message')){
log(level: 'WARN', text: "makeGithubApiCall: The REST API call ${url} return the message : ${ret.message}")
error("makeGithubApiCall: The REST API call ${url} return the message : ${ret.message}")
}
return ret
}
Expand Down