Skip to content

Commit 79656a4

Browse files
Merge branch 'master' into fix-legacy-links
2 parents ef64821 + 1ad1879 commit 79656a4

77 files changed

Lines changed: 1066 additions & 294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ci/pipeline-library/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
implementation 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.19@jar'
2121
testImplementation 'com.lesfurets:jenkins-pipeline-unit:1.4'
2222
testImplementation 'junit:junit:4.12'
23+
testImplementation 'org.mockito:mockito-core:2.+'
2324
testImplementation 'org.assertj:assertj-core:3.15+' // Temporary https://github.com/jenkinsci/JenkinsPipelineUnit/issues/209
2425
}
2526

.ci/pipeline-library/src/test/KibanaBasePipelineTest.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class KibanaBasePipelineTest extends BasePipelineTest {
1919
env.BUILD_DISPLAY_NAME = "#${env.BUILD_ID}"
2020

2121
env.JENKINS_URL = 'http://jenkins.localhost:8080'
22-
env.BUILD_URL = "${env.JENKINS_URL}/job/elastic+kibana+${env.BRANCH_NAME}/${env.BUILD_ID}/"
22+
env.BUILD_URL = "${env.JENKINS_URL}/job/elastic+kibana+${env.BRANCH_NAME}/${env.BUILD_ID}/".toString()
2323

24-
env.JOB_BASE_NAME = "elastic / kibana # ${env.BRANCH_NAME}"
24+
env.JOB_BASE_NAME = "elastic / kibana # ${env.BRANCH_NAME}".toString()
2525
env.JOB_NAME = env.JOB_BASE_NAME
2626

2727
env.WORKSPACE = 'WS'
@@ -31,6 +31,9 @@ class KibanaBasePipelineTest extends BasePipelineTest {
3131
getBuildStatus: { 'SUCCESS' },
3232
printStacktrace: { ex -> print ex },
3333
],
34+
githubPr: [
35+
isPr: { false },
36+
],
3437
jenkinsApi: [ getFailedSteps: { [] } ],
3538
testUtils: [ getFailures: { [] } ],
3639
])
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import org.junit.*
2+
import static groovy.test.GroovyAssert.*
3+
4+
class BuildStateTest extends KibanaBasePipelineTest {
5+
def buildState
6+
7+
@Before
8+
void setUp() {
9+
super.setUp()
10+
11+
buildState = loadScript("vars/buildState.groovy")
12+
}
13+
14+
@Test
15+
void 'get() returns existing data'() {
16+
buildState.add('test', 1)
17+
def actual = buildState.get('test')
18+
assertEquals(1, actual)
19+
}
20+
21+
@Test
22+
void 'get() returns null for missing data'() {
23+
def actual = buildState.get('missing_key')
24+
assertEquals(null, actual)
25+
}
26+
27+
@Test
28+
void 'add() does not overwrite existing keys'() {
29+
assertTrue(buildState.add('test', 1))
30+
assertFalse(buildState.add('test', 2))
31+
32+
def actual = buildState.get('test')
33+
34+
assertEquals(1, actual)
35+
}
36+
37+
@Test
38+
void 'set() overwrites existing keys'() {
39+
assertFalse(buildState.has('test'))
40+
buildState.set('test', 1)
41+
assertTrue(buildState.has('test'))
42+
buildState.set('test', 2)
43+
44+
def actual = buildState.get('test')
45+
46+
assertEquals(2, actual)
47+
}
48+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import org.junit.*
2+
import static org.mockito.Mockito.*;
3+
4+
class GithubCommitStatusTest extends KibanaBasePipelineTest {
5+
def githubCommitStatus
6+
def githubApiMock
7+
def buildStateMock
8+
9+
def EXPECTED_STATUS_URL = 'repos/elastic/kibana/statuses/COMMIT_HASH'
10+
def EXPECTED_CONTEXT = 'kibana-ci'
11+
def EXPECTED_BUILD_URL = 'http://jenkins.localhost:8080/job/elastic+kibana+master/1/'
12+
13+
interface BuildState {
14+
Object get(String key)
15+
}
16+
17+
interface GithubApi {
18+
Object post(String url, Map data)
19+
}
20+
21+
@Before
22+
void setUp() {
23+
super.setUp()
24+
25+
buildStateMock = mock(BuildState)
26+
githubApiMock = mock(GithubApi)
27+
28+
when(buildStateMock.get('checkoutInfo')).thenReturn([ commit: 'COMMIT_HASH', ])
29+
when(githubApiMock.post(any(), any())).thenReturn(null)
30+
31+
props([
32+
buildState: buildStateMock,
33+
githubApi: githubApiMock,
34+
])
35+
36+
githubCommitStatus = loadScript("vars/githubCommitStatus.groovy")
37+
}
38+
39+
void verifyStatusCreate(String state, String description) {
40+
verify(githubApiMock).post(
41+
EXPECTED_STATUS_URL,
42+
[
43+
'state': state,
44+
'description': description,
45+
'context': EXPECTED_CONTEXT,
46+
'target_url': EXPECTED_BUILD_URL,
47+
]
48+
)
49+
}
50+
51+
@Test
52+
void 'onStart() should create a pending status'() {
53+
githubCommitStatus.onStart()
54+
verifyStatusCreate('pending', 'Build started.')
55+
}
56+
57+
@Test
58+
void 'onFinish() should create a success status'() {
59+
githubCommitStatus.onFinish()
60+
verifyStatusCreate('success', 'Build completed successfully.')
61+
}
62+
63+
@Test
64+
void 'onFinish() should create an error status for failed builds'() {
65+
mockFailureBuild()
66+
githubCommitStatus.onFinish()
67+
verifyStatusCreate('error', 'Build failed.')
68+
}
69+
70+
@Test
71+
void 'onStart() should exit early for PRs'() {
72+
prop('githubPr', [ isPr: { true } ])
73+
74+
githubCommitStatus.onStart()
75+
verifyZeroInteractions(githubApiMock)
76+
}
77+
78+
@Test
79+
void 'onFinish() should exit early for PRs'() {
80+
prop('githubPr', [ isPr: { true } ])
81+
82+
githubCommitStatus.onFinish()
83+
verifyZeroInteractions(githubApiMock)
84+
}
85+
}

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
library 'kibana-pipeline-library'
44
kibanaLibrary.load()
55

6-
kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true) {
6+
kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true, setCommitStatus: true) {
77
githubPr.withDefaultPrComments {
88
ciStats.trackBuild {
99
catchError {

src/plugins/dashboard/public/application/dashboard_app_controller.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import { getDashboardTitle } from './dashboard_strings';
7575
import { DashboardAppScope } from './dashboard_app';
7676
import { convertSavedDashboardPanelToPanelState } from './lib/embeddable_saved_object_converters';
7777
import { RenderDeps } from './application';
78-
import { IKbnUrlStateStorage, removeQueryParam, unhashUrl } from '../../../kibana_utils/public';
78+
import { IKbnUrlStateStorage, unhashUrl } from '../../../kibana_utils/public';
7979
import {
8080
addFatalError,
8181
AngularHttpError,
@@ -132,6 +132,7 @@ export class DashboardAppController {
132132
embeddable,
133133
share,
134134
dashboardCapabilities,
135+
scopedHistory,
135136
embeddableCapabilities: { visualizeCapabilities, mapsCapabilities },
136137
data: { query: queryService },
137138
core: {
@@ -425,15 +426,13 @@ export class DashboardAppController {
425426
refreshDashboardContainer();
426427
});
427428

428-
// This code needs to be replaced with a better mechanism for adding new embeddables of
429-
// any type from the add panel. Likely this will happen via creating a visualization "inline",
430-
// without navigating away from the UX.
431-
if ($routeParams[DashboardConstants.ADD_EMBEDDABLE_TYPE]) {
432-
const type = $routeParams[DashboardConstants.ADD_EMBEDDABLE_TYPE];
433-
const id = $routeParams[DashboardConstants.ADD_EMBEDDABLE_ID];
434-
container.addNewEmbeddable<SavedObjectEmbeddableInput>(type, { savedObjectId: id });
435-
removeQueryParam(history, DashboardConstants.ADD_EMBEDDABLE_TYPE);
436-
removeQueryParam(history, DashboardConstants.ADD_EMBEDDABLE_ID);
429+
const incomingState = embeddable
430+
.getStateTransfer(scopedHistory())
431+
.getIncomingEmbeddablePackage();
432+
if (incomingState) {
433+
container.addNewEmbeddable<SavedObjectEmbeddableInput>(incomingState.type, {
434+
savedObjectId: incomingState.id,
435+
});
437436
}
438437
}
439438

src/plugins/dashboard/public/application/embeddable/dashboard_container.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
} from '../../../../kibana_react/public';
4747
import { PLACEHOLDER_EMBEDDABLE } from './placeholder';
4848
import { PanelPlacementMethod, IPanelPlacementArgs } from './panel/dashboard_panel_placement';
49+
import { EmbeddableStateTransfer } from '../../../../embeddable/public';
4950

5051
export interface DashboardContainerInput extends ContainerInput {
5152
viewMode: ViewMode;
@@ -98,9 +99,12 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
9899

99100
public renderEmpty?: undefined | (() => React.ReactNode);
100101

102+
private embeddablePanel: EmbeddableStart['EmbeddablePanel'];
103+
101104
constructor(
102105
initialInput: DashboardContainerInput,
103106
private readonly options: DashboardContainerOptions,
107+
stateTransfer?: EmbeddableStateTransfer,
104108
parent?: Container
105109
) {
106110
super(
@@ -111,6 +115,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
111115
options.embeddable.getEmbeddableFactory,
112116
parent
113117
);
118+
this.embeddablePanel = options.embeddable.getEmbeddablePanel(stateTransfer);
114119
}
115120

116121
protected createNewPanelState<
@@ -186,7 +191,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
186191
<DashboardViewport
187192
renderEmpty={this.renderEmpty}
188193
container={this}
189-
PanelComponent={this.options.embeddable.EmbeddablePanel}
194+
PanelComponent={this.embeddablePanel}
190195
/>
191196
</KibanaContextProvider>
192197
</I18nProvider>,

src/plugins/dashboard/public/application/embeddable/dashboard_container_factory.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import { i18n } from '@kbn/i18n';
2121
import { UiActionsStart } from 'src/plugins/ui_actions/public';
22-
import { CoreStart } from 'src/core/public';
22+
import { CoreStart, ScopedHistory } from 'src/core/public';
2323
import { Start as InspectorStartContract } from 'src/plugins/inspector/public';
2424
import { EmbeddableFactory, EmbeddableStart } from '../../../../embeddable/public';
2525
import {
@@ -54,7 +54,10 @@ export class DashboardContainerFactoryDefinition
5454
public readonly isContainerType = true;
5555
public readonly type = DASHBOARD_CONTAINER_TYPE;
5656

57-
constructor(private readonly getStartServices: () => Promise<StartServices>) {}
57+
constructor(
58+
private readonly getStartServices: () => Promise<StartServices>,
59+
private getHistory: () => ScopedHistory
60+
) {}
5861

5962
public isEditable = async () => {
6063
const { capabilities } = await this.getStartServices();
@@ -81,6 +84,7 @@ export class DashboardContainerFactoryDefinition
8184
parent?: Container
8285
): Promise<DashboardContainer | ErrorEmbeddable> => {
8386
const services = await this.getStartServices();
84-
return new DashboardContainer(initialInput, services, parent);
87+
const stateTransfer = services.embeddable.getStateTransfer(this.getHistory());
88+
return new DashboardContainer(initialInput, services, stateTransfer, parent);
8589
};
8690
}

src/plugins/dashboard/public/application/embeddable/grid/dashboard_grid.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function prepare(props?: Partial<DashboardGridProps>) {
6464
embeddable: {
6565
getTriggerCompatibleActions: (() => []) as any,
6666
getEmbeddableFactories: start.getEmbeddableFactories,
67+
getEmbeddablePanel: jest.fn(),
6768
getEmbeddableFactory,
6869
} as any,
6970
notifications: {} as any,

src/plugins/dashboard/public/application/embeddable/viewport/dashboard_viewport.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function getProps(
5454
application: applicationServiceMock.createStartContract(),
5555
embeddable: {
5656
getTriggerCompatibleActions: (() => []) as any,
57+
getEmbeddablePanel: jest.fn(),
5758
getEmbeddableFactories: start.getEmbeddableFactories,
5859
getEmbeddableFactory: start.getEmbeddableFactory,
5960
} as any,

0 commit comments

Comments
 (0)