Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit d8f347f

Browse files
committed
fix: perform another API call to fetch PR data
We need a second API request, as the issue_comment API does not retrieve data about the pull request. See https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issue_comment
1 parent 18dc7e7 commit d8f347f

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

.ci/e2eKibana.groovy

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pipeline {
77
environment {
88
REPO = 'kibana'
99
BASE_DIR = "src/github.com/elastic/${env.REPO}"
10+
GITHUB_APP_SECRET = 'secret/observability-team/ci/github-app'
1011
GITHUB_CHECK_E2E_TESTS_NAME = 'E2E Tests'
1112
PIPELINE_LOG_LEVEL = "INFO"
1213
}
@@ -25,17 +26,15 @@ pipeline {
2526
GenericTrigger(
2627
genericVariables: [
2728
[key: 'GT_REPO', value: '$.repository.full_name'],
28-
[key: 'GT_BASE_REF', value: '$.pull_request.base.ref'],
2929
[key: 'GT_PR', value: '$.issue.number'],
30-
[key: 'GT_HEAD_SHA', value: '$.pull_request.head.sha'],
3130
[key: 'GT_BODY', value: '$.comment.body'],
3231
[key: 'GT_COMMENT_ID', value: '$.comment.id']
3332
[key: 'GT_PAYLOAD', value: '$']
3433
],
3534
genericHeaderVariables: [
3635
[key: 'x-github-event', regexpFilter: 'comment']
3736
],
38-
causeString: 'Triggered on #$GT_PR (baseRef:$GT_BASE_REF - sha:$GT_HEAD_SHA), via comment: $GT_BODY',
37+
causeString: 'Triggered on #$GT_PR via comment: $GT_BODY',
3938
printContributedVariables: false,
4039
printPostContent: false,
4140
silentResponse: true,
@@ -78,29 +77,40 @@ def checkPermissions(){
7877
}
7978

8079
def getBranch(){
80+
return "PR/" + getID()
81+
}
82+
83+
def getID(){
8184
if(env.GT_PR){
82-
return "PR/${env.GT_PR}"
85+
return "${env.GT_PR}"
8386
}
8487

85-
return "PR/${params.kibana_pr}"
88+
return "${params.kibana_pr}"
8689
}
8790

88-
def getDockerTag(){
91+
def runE2ETests(String suite) {
92+
// we need a second API request, as the issue_comment API does not retrieve data about the pull request
93+
// See https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issue_comment
94+
def prID = getID()
95+
def token = githubAppToken(secret: "${env.GITHUB_APP_SECRET}")
96+
97+
def pullRequest = githubApiCall(token: token, url: "https://api.github.com/repos/${env.$GT_REPO}/pulls/${prID}")
98+
def baseRef = pullRequest?.base?.ref
99+
def headSha = pullRequest?.head?.sha
100+
101+
// we are going to use the 'pr12345' tag as default
102+
def dockerTag = "pr${params.kibana_pr}"
89103
if(env.GT_PR){
90-
return "${env.GT_HEAD_SHA}"
104+
// it's a PR: we are going to use its head SHA as tag
105+
dockerTag = headSha
91106
}
92107

93-
// we are going to use the 'pr12345' tag
94-
return "pr${params.kibana_pr}"
95-
}
96-
97-
def runE2ETests(String suite) {
98-
log(level: 'DEBUG', text: "Triggering '${suite}' E2E tests for PR-${env.GT_PR}.")
108+
log(level: 'DEBUG', text: "Triggering '${suite}' E2E tests for PR-${prID} using '${dockerTag}' as Docker tag")
99109

100110
// Kibana's maintenance branches follow the 7.11, 7.12 schema.
101-
def branchName = "${env.GT_BASE_REF}"
102-
if (env.GT_BASE_REF != "master") {
103-
branchName = "${env.GT_BASE_REF}.x"
111+
def branchName = "${baseRef}"
112+
if (branchName != "master") {
113+
branchName += ".x"
104114
}
105115
def e2eTestsPipeline = "e2e-tests/e2e-testing-mbp/${branchName}"
106116

@@ -112,7 +122,7 @@ def runE2ETests(String suite) {
112122
string(name: 'runTestsSuites', value: suite),
113123
string(name: 'GITHUB_CHECK_NAME', value: env.GITHUB_CHECK_E2E_TESTS_NAME),
114124
string(name: 'GITHUB_CHECK_REPO', value: env.REPO),
115-
string(name: 'KIBANA_VERSION', value: getDockerTag()),
125+
string(name: 'KIBANA_VERSION', value: dockerTag),
116126
]
117127

118128
build(job: "${e2eTestsPipeline}",

0 commit comments

Comments
 (0)