Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
loadBranchMetadata() {
const { organization, pipeline, branch } = this.props.params;
if (!branch) {
const split = pipeline.split('/');
const team = split[0];
const repo = split.length > 1 ? split[1] : team;
const { id: scmId, apiUrl } = this.state.scmSource;
const orgRestUrl = UrlBuilder.buildRestUrl(organization);
let repositoryUrl = `${orgRestUrl}scm/${scmId}/organizations/${team}/repositories/${repo}/`;
if (apiUrl) {
repositoryUrl += `?apiUrl=${apiUrl}`;
}
return Fetch.fetchJSON(repositoryUrl)
.then(({ defaultBranch }) => {
this.defaultBranch = defaultBranch || 'master';
})
.catch(err => (this.defaultBranch = 'master'));
}
this.defaultBranch = branch;
return new Promise(resolve => resolve(null));
}
_getCredential(credentialId) {
const orgUrl = UrlBuilder.buildRestUrl(this.organization);
const credentialUrl = `${orgUrl}credentials/user/domains/blueocean-git-domain/credentials/${encodeURIComponent(credentialId)}/`;
return this._fetch(credentialUrl);
}
loadContent({ organization, pipeline, branch, path = 'Jenkinsfile' }) {
const pipelineUrl = UrlBuilder.buildRestUrl(organization, pipeline);
let contentUrl = `${pipelineUrl}scm/content?path=${path}`;
if (branch) {
contentUrl += `&branch=${encodeURIComponent(branch)}`;
}
return Fetch.fetchJSON(contentUrl)
.then(result => result)
.catch(error => this._loadContentErrorHandler(error));
}
saveContent({ organization, pipeline, repo, sourceBranch, targetBranch, sha, message, path = 'Jenkinsfile', content }) {
const contentUrl = `${UrlBuilder.buildRestUrl(organization, pipeline)}scm/content/`;
const body = this.buildSaveContentRequest({
organization,
pipeline,
repo,
sourceBranch,
targetBranch,
sha,
message,
path,
content,
});
const fetchOptions = {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },