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

[APM-CI] if there are rejected reviews it fails #29

Merged
merged 3 commits into from
Jan 15, 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
35 changes: 35 additions & 0 deletions src/test/groovy/GithubPrCheckApprovedStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class GithubPrCheckApprovedStepTests extends BasePipelineTest {
}.any { call ->
callArgsToString(call).contains("githubPrCheckApproved: The PR is not approved yet")
})
assertJobStatusFailure()
}

@Test
Expand Down Expand Up @@ -132,6 +133,40 @@ class GithubPrCheckApprovedStepTests extends BasePipelineTest {
assertJobStatusSuccess()
}

@Test
void testIsRejected() throws Exception {
helper.registerAllowedMethod("githubRepoGetUserPermission", [Map.class], {
return []
})
helper.registerAllowedMethod("githubPrInfo", [Map.class], {
return [title: 'dummy PR', user: [login: 'username'], author_association: 'NONE']
})
helper.registerAllowedMethod("githubPrReviews", [Map.class], {
return [
[
"id": 80,
"node_id": "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3ODA=",
"user": [
"login": "octocat",
"id": 1,
"type": "User",
"site_admin": false
],
"body": "Here is the body for the review.",
"commit_id": "ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091",
"state": "REQUEST_CHANGES",
"author_association": "MEMBER",
]
]
})
def script = loadScript("vars/githubPrCheckApproved.groovy")
env.CHANGE_ID = 1
def ret = script.call()
printCallStack()
assertFalse(ret)
assertJobStatusFailure()
}

@Test
void testHasWritePermision() throws Exception {
helper.registerAllowedMethod("githubRepoGetUserPermission", [Map.class], {
Expand Down
5 changes: 4 additions & 1 deletion vars/githubPrCheckApproved.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def call(Map params = [:]){
Check reviews to find one approved by a MEMBER or COLLABORATOR.
*/
def isPrApproved(reviews){
def ret = false
if(reviews?.size() == 0){
log(level: 'INFO', text: "githubPrCheckApproved: There are no reviews yet")
return false
Expand All @@ -37,9 +38,11 @@ def isPrApproved(reviews){
reviews.each{ r ->
if(r?.state == 'APPROVED' && (r?.author_association == "MEMBER" || r?.author_association == "COLLABORATOR")){
log(level: 'INFO', text: "githubPrCheckApproved: User: ${r?.user.login} - Author Association: ${r.author_association} : ${r.state}")
return true
ret = true
return
}
}
return ret
}

/**
Expand Down