Skip to content

Commit

Permalink
Merge branch 'master' into fix-legacy-links
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jun 23, 2020
2 parents ef64821 + 1ad1879 commit 79656a4
Show file tree
Hide file tree
Showing 77 changed files with 1,066 additions and 294 deletions.
1 change: 1 addition & 0 deletions .ci/pipeline-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
implementation 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.19@jar'
testImplementation 'com.lesfurets:jenkins-pipeline-unit:1.4'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.+'
testImplementation 'org.assertj:assertj-core:3.15+' // Temporary https://github.com/jenkinsci/JenkinsPipelineUnit/issues/209
}

Expand Down
7 changes: 5 additions & 2 deletions .ci/pipeline-library/src/test/KibanaBasePipelineTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class KibanaBasePipelineTest extends BasePipelineTest {
env.BUILD_DISPLAY_NAME = "#${env.BUILD_ID}"

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

env.JOB_BASE_NAME = "elastic / kibana # ${env.BRANCH_NAME}"
env.JOB_BASE_NAME = "elastic / kibana # ${env.BRANCH_NAME}".toString()
env.JOB_NAME = env.JOB_BASE_NAME

env.WORKSPACE = 'WS'
Expand All @@ -31,6 +31,9 @@ class KibanaBasePipelineTest extends BasePipelineTest {
getBuildStatus: { 'SUCCESS' },
printStacktrace: { ex -> print ex },
],
githubPr: [
isPr: { false },
],
jenkinsApi: [ getFailedSteps: { [] } ],
testUtils: [ getFailures: { [] } ],
])
Expand Down
48 changes: 48 additions & 0 deletions .ci/pipeline-library/src/test/buildState.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import org.junit.*
import static groovy.test.GroovyAssert.*

class BuildStateTest extends KibanaBasePipelineTest {
def buildState

@Before
void setUp() {
super.setUp()

buildState = loadScript("vars/buildState.groovy")
}

@Test
void 'get() returns existing data'() {
buildState.add('test', 1)
def actual = buildState.get('test')
assertEquals(1, actual)
}

@Test
void 'get() returns null for missing data'() {
def actual = buildState.get('missing_key')
assertEquals(null, actual)
}

@Test
void 'add() does not overwrite existing keys'() {
assertTrue(buildState.add('test', 1))
assertFalse(buildState.add('test', 2))

def actual = buildState.get('test')

assertEquals(1, actual)
}

@Test
void 'set() overwrites existing keys'() {
assertFalse(buildState.has('test'))
buildState.set('test', 1)
assertTrue(buildState.has('test'))
buildState.set('test', 2)

def actual = buildState.get('test')

assertEquals(2, actual)
}
}
85 changes: 85 additions & 0 deletions .ci/pipeline-library/src/test/githubCommitStatus.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import org.junit.*
import static org.mockito.Mockito.*;

class GithubCommitStatusTest extends KibanaBasePipelineTest {
def githubCommitStatus
def githubApiMock
def buildStateMock

def EXPECTED_STATUS_URL = 'repos/elastic/kibana/statuses/COMMIT_HASH'
def EXPECTED_CONTEXT = 'kibana-ci'
def EXPECTED_BUILD_URL = 'http://jenkins.localhost:8080/job/elastic+kibana+master/1/'

interface BuildState {
Object get(String key)
}

interface GithubApi {
Object post(String url, Map data)
}

@Before
void setUp() {
super.setUp()

buildStateMock = mock(BuildState)
githubApiMock = mock(GithubApi)

when(buildStateMock.get('checkoutInfo')).thenReturn([ commit: 'COMMIT_HASH', ])
when(githubApiMock.post(any(), any())).thenReturn(null)

props([
buildState: buildStateMock,
githubApi: githubApiMock,
])

githubCommitStatus = loadScript("vars/githubCommitStatus.groovy")
}

void verifyStatusCreate(String state, String description) {
verify(githubApiMock).post(
EXPECTED_STATUS_URL,
[
'state': state,
'description': description,
'context': EXPECTED_CONTEXT,
'target_url': EXPECTED_BUILD_URL,
]
)
}

@Test
void 'onStart() should create a pending status'() {
githubCommitStatus.onStart()
verifyStatusCreate('pending', 'Build started.')
}

@Test
void 'onFinish() should create a success status'() {
githubCommitStatus.onFinish()
verifyStatusCreate('success', 'Build completed successfully.')
}

@Test
void 'onFinish() should create an error status for failed builds'() {
mockFailureBuild()
githubCommitStatus.onFinish()
verifyStatusCreate('error', 'Build failed.')
}

@Test
void 'onStart() should exit early for PRs'() {
prop('githubPr', [ isPr: { true } ])

githubCommitStatus.onStart()
verifyZeroInteractions(githubApiMock)
}

@Test
void 'onFinish() should exit early for PRs'() {
prop('githubPr', [ isPr: { true } ])

githubCommitStatus.onFinish()
verifyZeroInteractions(githubApiMock)
}
}
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
library 'kibana-pipeline-library'
kibanaLibrary.load()

kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true) {
kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true, setCommitStatus: true) {
githubPr.withDefaultPrComments {
ciStats.trackBuild {
catchError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import { getDashboardTitle } from './dashboard_strings';
import { DashboardAppScope } from './dashboard_app';
import { convertSavedDashboardPanelToPanelState } from './lib/embeddable_saved_object_converters';
import { RenderDeps } from './application';
import { IKbnUrlStateStorage, removeQueryParam, unhashUrl } from '../../../kibana_utils/public';
import { IKbnUrlStateStorage, unhashUrl } from '../../../kibana_utils/public';
import {
addFatalError,
AngularHttpError,
Expand Down Expand Up @@ -132,6 +132,7 @@ export class DashboardAppController {
embeddable,
share,
dashboardCapabilities,
scopedHistory,
embeddableCapabilities: { visualizeCapabilities, mapsCapabilities },
data: { query: queryService },
core: {
Expand Down Expand Up @@ -425,15 +426,13 @@ export class DashboardAppController {
refreshDashboardContainer();
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
} from '../../../../kibana_react/public';
import { PLACEHOLDER_EMBEDDABLE } from './placeholder';
import { PanelPlacementMethod, IPanelPlacementArgs } from './panel/dashboard_panel_placement';
import { EmbeddableStateTransfer } from '../../../../embeddable/public';

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

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

private embeddablePanel: EmbeddableStart['EmbeddablePanel'];

constructor(
initialInput: DashboardContainerInput,
private readonly options: DashboardContainerOptions,
stateTransfer?: EmbeddableStateTransfer,
parent?: Container
) {
super(
Expand All @@ -111,6 +115,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
options.embeddable.getEmbeddableFactory,
parent
);
this.embeddablePanel = options.embeddable.getEmbeddablePanel(stateTransfer);
}

protected createNewPanelState<
Expand Down Expand Up @@ -186,7 +191,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
<DashboardViewport
renderEmpty={this.renderEmpty}
container={this}
PanelComponent={this.options.embeddable.EmbeddablePanel}
PanelComponent={this.embeddablePanel}
/>
</KibanaContextProvider>
</I18nProvider>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { i18n } from '@kbn/i18n';
import { UiActionsStart } from 'src/plugins/ui_actions/public';
import { CoreStart } from 'src/core/public';
import { CoreStart, ScopedHistory } from 'src/core/public';
import { Start as InspectorStartContract } from 'src/plugins/inspector/public';
import { EmbeddableFactory, EmbeddableStart } from '../../../../embeddable/public';
import {
Expand Down Expand Up @@ -54,7 +54,10 @@ export class DashboardContainerFactoryDefinition
public readonly isContainerType = true;
public readonly type = DASHBOARD_CONTAINER_TYPE;

constructor(private readonly getStartServices: () => Promise<StartServices>) {}
constructor(
private readonly getStartServices: () => Promise<StartServices>,
private getHistory: () => ScopedHistory
) {}

public isEditable = async () => {
const { capabilities } = await this.getStartServices();
Expand All @@ -81,6 +84,7 @@ export class DashboardContainerFactoryDefinition
parent?: Container
): Promise<DashboardContainer | ErrorEmbeddable> => {
const services = await this.getStartServices();
return new DashboardContainer(initialInput, services, parent);
const stateTransfer = services.embeddable.getStateTransfer(this.getHistory());
return new DashboardContainer(initialInput, services, stateTransfer, parent);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function prepare(props?: Partial<DashboardGridProps>) {
embeddable: {
getTriggerCompatibleActions: (() => []) as any,
getEmbeddableFactories: start.getEmbeddableFactories,
getEmbeddablePanel: jest.fn(),
getEmbeddableFactory,
} as any,
notifications: {} as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function getProps(
application: applicationServiceMock.createStartContract(),
embeddable: {
getTriggerCompatibleActions: (() => []) as any,
getEmbeddablePanel: jest.fn(),
getEmbeddableFactories: start.getEmbeddableFactories,
getEmbeddableFactory: start.getEmbeddableFactory,
} as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { context } from '../../../../../kibana_react/public';

export interface DashboardViewportProps {
container: DashboardContainer;
renderEmpty?: () => React.ReactNode;
PanelComponent: EmbeddableStart['EmbeddablePanel'];
renderEmpty?: () => React.ReactNode;
}

interface State {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ export class DashboardPlugin
};
};

const factory = new DashboardContainerFactoryDefinition(getStartServices);
const factory = new DashboardContainerFactoryDefinition(
getStartServices,
() => this.currentHistory!
);
embeddable.registerEmbeddableFactory(factory.type, factory);

const placeholderFactory = new PlaceholderEmbeddableFactory();
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/embeddable/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import './index.scss';
import { PluginInitializerContext } from 'src/core/public';
import { EmbeddablePublicPlugin } from './plugin';

export { EMBEDDABLE_ORIGINATING_APP_PARAM } from './types';
export {
ACTION_ADD_PANEL,
ACTION_APPLY_FILTER,
Expand Down Expand Up @@ -69,6 +68,9 @@ export {
isSavedObjectEmbeddableInput,
isRangeSelectTriggerContext,
isValueClickTriggerContext,
EmbeddableStateTransfer,
EmbeddableOriginatingAppState,
EmbeddablePackageState,
EmbeddableRenderer,
EmbeddableRendererProps,
} from './lib';
Expand All @@ -82,4 +84,5 @@ export {
EmbeddableStart,
EmbeddableSetupDependencies,
EmbeddableStartDependencies,
EmbeddablePanelHOC,
} from './plugin';
Loading

0 comments on commit 79656a4

Please sign in to comment.