Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createCredential(repositoryUrl, userName, password, branchName, requirePush) {
const path = UrlConfig.getJenkinsRootURL();
const validateCredUrl = Utils.cleanSlashes(`${path}/blue/rest/organizations/${this.organization}/scm/git/validate`);
const requestBody: any = {
userName,
password,
repositoryUrl,
};
if (branchName) {
requestBody.branch = branchName;
}
if (requirePush) {
requestBody.repositoryUrl = true; // Only set if true!
}
const fetchOptions = {findExistingCredential(repositoryUrl) {
const root = UrlConfig.getJenkinsRootURL();
const credUrl = Utils.cleanSlashes(`${root}/blue/rest/organizations/${this.organization}/scm/git/?repositoryUrl=${repositoryUrl}`);
// Create error in sync code for better stack trace
const possibleError = new TypedError();
return this._fetch(credUrl).then(
result => this._findExistingCredentialSuccess(result),
error => {
const { responseBody } = error;
if (responseBody.message.indexOf('Existing credential failed') >= 0) {
throw possibleError.populate(LoadError.TOKEN_REVOKED, responseBody);
}
throw possibleError.populate(LoadError.TOKEN_INVALID, responseBody);
}
);function getCredentialsUrl(organization) {
const path = UrlConfig.getRestBaseURL();
return Utils.cleanSlashes(`${path}/organizations/${organization}/credentials/user/`);
}findBranches(pipelineName) {
const path = UrlConfig.getJenkinsRootURL();
const pipelineUrl = Utils.cleanSlashes(`${path}/blue/rest/organizations/${this.organization}/pipelines/${pipelineName}/`);
return this._fetch(pipelineUrl)
.then(response => capabilityAugmenter.augmentCapabilities(response))
.then(pipeline => this._findBranchesSuccess(pipeline), error => this._findBranchesFailure(error));
}listAllCredentials() {
const path = UrlConfig.getRestBaseURL();
const searchUrl = Utils.cleanSlashes(`${path}/search?q=type:credential;organization:${this.organization}`, false);
return this._fetch(searchUrl)
.then(data => capabilityAugmenter.augmentCapabilities(data))
.then(creds => this._listAllCredentialsSuccess(creds), error => this._listAllCredentialsFailure(error));
}validateVersion(id) {
const path = UrlConfig.getJenkinsRootURL();
const serverUrl = Utils.cleanSlashes(`${path}/blue/rest/organizations/${this.organization}/scm/${this.scmId}/servers/${id}/validate`);
return this._fetch(serverUrl);
}createAccessToken(accessToken, apiUrl) {
const path = UrlConfig.getJenkinsRootURL();
let tokenUrl = Utils.cleanSlashes(`${path}/blue/rest/organizations/${this.organization}/scm/${this.scmId}/validate`);
tokenUrl = GithubApiUtils.appendApiUrlParam(tokenUrl, apiUrl);
const requestBody = {
accessToken,
};
const fetchOptions = {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
};
return this._fetch(tokenUrl, { fetchOptions }).catch(error => this._createAccessTokenFailure(error));
}createServer(serverName, serverUrl) {
const path = UrlConfig.getJenkinsRootURL();
const createUrl = Utils.cleanSlashes(`${path}/blue/rest/organizations/${this.organization}/scm/${this.scmId}/servers`);
const requestBody = {
name: serverName,
apiUrl: serverUrl,
};
const fetchOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
};
return this._fetch(createUrl, { fetchOptions });
}createPipeline(repositoryUrl, credentialId, name) {
const path = UrlConfig.getRestBaseURL();
const createUrl = Utils.cleanSlashes(`${path}/organizations/${this.organization}/pipelines`);
const requestBody = {
name,
$class: 'io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest',
scmConfig: {
uri: repositoryUrl,
credentialId,
},
};
const fetchOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),