Skip to content

Commit

Permalink
Merge branch 'master' into story/JENKINS-42791-editor-prompt-github-t…
Browse files Browse the repository at this point in the history
…oken

# Conflicts:
#	src/main/js/EditorPage.jsx
#	src/main/js/SaveApi.js
  • Loading branch information
Cliff Meyers committed Aug 11, 2017
2 parents d427b47 + 7f4e0e3 commit 5a9d0c2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -16,7 +16,7 @@

<groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean-pipeline-editor</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.3.0-beta-3-SNAPSHOT</version>
<packaging>hpi</packaging>

<properties>
Expand Down
26 changes: 12 additions & 14 deletions src/main/js/EditorPage.jsx
Expand Up @@ -129,7 +129,7 @@ class PipelineLoader extends React.Component {
sha: null,
};
}

componentWillMount() {
pipelineStore.setPipeline(null); // reset any previous loaded pipeline
this.loadPipeline();
Expand Down Expand Up @@ -223,18 +223,13 @@ class PipelineLoader extends React.Component {

loadPipelineMetadata() {
const { organization, pipeline } = this.props.params;
this.href = Paths.rest.pipeline(organization, pipeline);
const split = pipeline.split('/');
const team = split[0];
this.href = Paths.rest.pipeline(organization, team);
return pipelineService.fetchPipeline(this.href, { useCache: true })
.then(pipeline => this._savePipelineMetadata(pipeline))
.catch(err => {
// No pipeline, use org folder
const team = pipeline.split('/')[0];
this.href = Paths.rest.pipeline(organization, team);
pipelineService.fetchPipeline(this.href, { useCache: true })
.then(pipeline => this._savePipelineMetadata(pipeline))
.catch(err => {
this.showErrorDialog(err);
});
this.showErrorDialog(err);
});
}

Expand All @@ -246,6 +241,7 @@ class PipelineLoader extends React.Component {
const team = split[0];
const repo = split.length > 1 ? split[1] : team;
const { id: scmId, apiUrl } = this.state.scmSource;
// TODO: bitbucket isn't passing the pipeline as "orgname/reponame" so this request 404's
let repositoryUrl = `${getRestUrl({organization})}scm/${scmId}/organizations/${team}/repositories/${repo}/`;
if (apiUrl) {
repositoryUrl += `?apiUrl=${apiUrl}`;
Expand Down Expand Up @@ -493,9 +489,7 @@ class PipelineLoader extends React.Component {
);
} else {
//other scms, which are always MBP
RunApi.startRun({ _links: { self: { href: this.href + '/' }}})
.then(() => this.goToActivity())
.catch(err => errorHandler(err, body));
saveApi.indexMbp(this.href, () => this.goToActivity(), err => errorHandler(err));
}
}
this.setState({ sha: data.sha, isSaved: true });
Expand All @@ -514,12 +508,16 @@ class PipelineLoader extends React.Component {
const { pipelineScript } = this.state;
const pipeline = pipelineService.getPipeline(this.href);
const repo = pipelineName && pipelineName.split('/')[1];
let title = pipeline ? decodeURIComponent(pipeline.fullDisplayName.replace('/', ' / ')) : pipelineName;
if (branch || repo){
title += ' / ' + (branch || repo);
}
return (<div className="pipeline-page">
<Extensions.Renderer extensionPoint="pipeline.editor.css"/>
<ContentPageHeader>
<div className="u-flex-grow">
<h1>
{pipeline && (decodeURIComponent(pipeline.fullDisplayName.replace('/', ' / ')) + ' / ' + (branch || repo))}
{pipeline && title}
</h1>
</div>
<div className="editor-page-header-controls">
Expand Down
73 changes: 47 additions & 26 deletions src/main/js/SaveApi.js
@@ -1,9 +1,33 @@
// @flow

import { Fetch, getRestUrl, sseService, loadingIndicator } from '@jenkins-cd/blueocean-core-js';
import { Fetch, getRestUrl, sseService, loadingIndicator, RunApi } from '@jenkins-cd/blueocean-core-js';

const TIMEOUT = 60*1000;

export class SaveApi {

_cleanup(sseId, timeoutId, onComplete, onError, err) {
sseService.removeHandler(sseId);
clearTimeout(timeoutId);
loadingIndicator.hide();
if (err && onError) {
onError(err);
} else {
onComplete();
}
}

_registerSse(timeoutId, onComplete, onError) {
const sseId = sseService.registerHandler(event => {
if (event.job_multibranch_indexing_result === 'SUCCESS') {
this._cleanup(sseId, timeoutId, onComplete, onError);
}
if (event.job_multibranch_indexing_result === 'FAILURE') {
this._cleanup(sseId, timeoutId, onComplete, onError, { message: 'Indexing failed' });
}
});
}

indexRepo(organization, teamName, repoName, scmId, apiUrl) {
const createUrl = `${getRestUrl({organization})}/pipelines/`;

Expand Down Expand Up @@ -31,37 +55,34 @@ export class SaveApi {
return Fetch.fetchJSON(createUrl, { fetchOptions });
}

index(organization, folder, repo, apiUrl, credentialId, complete, onError, progress) {
const cleanup = err => {
sseService.removeHandler(sseId);
clearTimeout(timeoutId);
loadingIndicator.hide();
if (err && onError) {
onError(err);
} else {
complete();
}
};

index(organization, folder, repo, scmId, apiUrl, complete, onError, progress) {
loadingIndicator.show();

const timeoutId = setTimeout(() => {
cleanup();
}, 60*1000);

const sseId = sseService.registerHandler(event => {
if (event.job_multibranch_indexing_result === 'SUCCESS') {
cleanup();
}
if (event.job_multibranch_indexing_result === 'FAILURE') {
cleanup({ message: 'Indexing failed' });
}
});
this._cleanup(timeoutId, complete, onError);
}, TIMEOUT);
this._registerSse(timeoutId, complete, onError);
this.indexRepo(organization, folder, repo, scmId, apiUrl);
}

this.indexRepo(organization, folder, repo, apiUrl, credentialId);
/**
* Indexes Multibranch pipeline
* @param href URL of MBP pipeline
* @param onComplete on success callback
* @param onError on error callback
*/
indexMbp(href, onComplete, onError) {
loadingIndicator.show();
const timeoutId = setTimeout(() => {
this._cleanup(timeoutId, onComplete, onError);
}, TIMEOUT);
this._registerSse(timeoutId, onComplete, onError);
RunApi.startRun({ _links: { self: { href: href + '/' }}})
.catch(err => onError);
}
}



const saveApi = new SaveApi();

export default saveApi;

0 comments on commit 5a9d0c2

Please sign in to comment.