|
1 | | -def shouldCreateStatuses() { |
2 | | - return !githubPr.isPr() && buildState.get('checkoutInfo') |
| 1 | +def defaultCommit() { |
| 2 | + if (buildState.has('checkoutInfo')) { |
| 3 | + return buildState.get('checkoutInfo').commit |
| 4 | + } |
3 | 5 | } |
4 | 6 |
|
5 | | -def onStart() { |
| 7 | +def onStart(commit = defaultCommit(), context = 'kibana-ci') { |
6 | 8 | catchError { |
7 | | - if (!shouldCreateStatuses()) { |
| 9 | + if (githubPr.isPr() || !commit) { |
8 | 10 | return |
9 | 11 | } |
10 | 12 |
|
11 | | - def checkoutInfo = buildState.get('checkoutInfo') |
12 | | - create(checkoutInfo.commit, 'pending', 'Build started.') |
| 13 | + create(commit, 'pending', 'Build started.', context) |
13 | 14 | } |
14 | 15 | } |
15 | 16 |
|
16 | | -def onFinish() { |
| 17 | +def onFinish(commit = defaultCommit(), context = 'kibana-ci') { |
17 | 18 | catchError { |
18 | | - if (!shouldCreateStatuses()) { |
| 19 | + if (githubPr.isPr() || !commit) { |
19 | 20 | return |
20 | 21 | } |
21 | 22 |
|
22 | | - def checkoutInfo = buildState.get('checkoutInfo') |
23 | 23 | def status = buildUtils.getBuildStatus() |
24 | 24 |
|
25 | 25 | if (status == 'SUCCESS' || status == 'UNSTABLE') { |
26 | | - create(checkoutInfo.commit, 'success', 'Build completed successfully.') |
| 26 | + create(commit, 'success', 'Build completed successfully.', context) |
27 | 27 | } else if(status == 'ABORTED') { |
28 | | - create(checkoutInfo.commit, 'error', 'Build aborted or timed out.') |
| 28 | + create(commit, 'error', 'Build aborted or timed out.', context) |
29 | 29 | } else { |
30 | | - create(checkoutInfo.commit, 'error', 'Build failed.') |
| 30 | + create(commit, 'error', 'Build failed.', context) |
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
34 | 34 |
|
| 35 | +def trackBuild(commit, context, Closure closure) { |
| 36 | + onStart(commit, context) |
| 37 | + catchError { |
| 38 | + closure() |
| 39 | + } |
| 40 | + onFinish(commit, context) |
| 41 | +} |
| 42 | + |
35 | 43 | // state: error|failure|pending|success |
36 | | -def create(sha, state, description, context = 'kibana-ci') { |
| 44 | +def create(sha, state, description, context) { |
37 | 45 | withGithubCredentials { |
38 | 46 | return githubApi.post("repos/elastic/kibana/statuses/${sha}", [ |
39 | 47 | state: state, |
|
0 commit comments