Skip to content

Commit

Permalink
[Azure DevOps Node API] Add support of the pipelines API (#590)
Browse files Browse the repository at this point in the history
* M236 API updates

- Add new endpoints

* M236 API updates

- Fix types

* M236 API updates

- Add pipelines api sample

* M236 API updates

- Formating

* M236 API updates

- Remove legacy method
  • Loading branch information
DmitriiBobreshev authored Mar 25, 2024
1 parent 00d544f commit 1351c2c
Show file tree
Hide file tree
Showing 25 changed files with 2,471 additions and 247 deletions.
47 changes: 47 additions & 0 deletions api/AlertApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IAlertApi extends basem.ClientApiBase {
getAlertSarif(project: string, alertId: number, repository: string, ref?: string, expand?: AlertInterfaces.ExpandOption): Promise<string>;
updateAlert(stateUpdate: AlertInterfaces.AlertStateUpdate, project: string, alertId: number, repository: string): Promise<AlertInterfaces.Alert>;
getAlertInstances(project: string, alertId: number, repository: string, ref?: string): Promise<AlertInterfaces.AlertAnalysisInstance[]>;
updateAlertsMetadata(alertsMetadata: AlertInterfaces.AlertMetadata[], project: string, repository: string): Promise<AlertInterfaces.AlertMetadataChange[]>;
uploadSarif(customHeaders: any, contentStream: NodeJS.ReadableStream, project: string, repository: string): Promise<number>;
getUxFilters(project: string, repository: string, alertType: AlertInterfaces.AlertType): Promise<AlertInterfaces.UxFilters>;
getSarif(sarifId: number): Promise<AlertInterfaces.SarifUploadStatus>;
Expand Down Expand Up @@ -310,6 +311,52 @@ export class AlertApi extends basem.ClientApiBase implements IAlertApi {
});
}

/**
* Update alert metadata associations.
*
* @param {AlertInterfaces.AlertMetadata[]} alertsMetadata - A list of metadata to associate with alerts.
* @param {string} project - Project ID or project name
* @param {string} repository - The name or ID of the repository.
*/
public async updateAlertsMetadata(
alertsMetadata: AlertInterfaces.AlertMetadata[],
project: string,
repository: string
): Promise<AlertInterfaces.AlertMetadataChange[]> {

return new Promise<AlertInterfaces.AlertMetadataChange[]>(async (resolve, reject) => {
let routeValues: any = {
project: project,
repository: repository
};

try {
let verData: vsom.ClientVersioningData = await this.vsoClient.getVersioningData(
"7.2-preview.1",
"Alert",
"65de4b84-7519-4ae8-8623-175f79b49b80",
routeValues);

let url: string = verData.requestUrl!;
let options: restm.IRequestOptions = this.createRequestOptions('application/json',
verData.apiVersion);

let res: restm.IRestResponse<AlertInterfaces.AlertMetadataChange[]>;
res = await this.rest.update<AlertInterfaces.AlertMetadataChange[]>(url, alertsMetadata, options);

let ret = this.formatResponse(res.result,
AlertInterfaces.TypeInfo.AlertMetadataChange,
true);

resolve(ret);

}
catch (err) {
reject(err);
}
});
}

/**
* Upload a Sarif containing security alerts
*
Expand Down
240 changes: 240 additions & 0 deletions api/CIXApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/*
* ---------------------------------------------------------
* Copyright(C) Microsoft Corporation. All rights reserved.
* ---------------------------------------------------------
*
* ---------------------------------------------------------
* Generated file, DO NOT EDIT
* ---------------------------------------------------------
*/

// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import * as restm from 'typed-rest-client/RestClient';
import vsom = require('./VsoClient');
import basem = require('./ClientApiBases');
import VsoBaseInterfaces = require('./interfaces/common/VsoBaseInterfaces');
import CIXInterfaces = require("./interfaces/CIXInterfaces");
import OperationsInterfaces = require("./interfaces/common/OperationsInterfaces");

export interface ICixApi extends basem.ClientApiBase {
getConfigurations(project: string, repositoryType?: string, repositoryId?: string, branch?: string, serviceConnectionId?: string): Promise<CIXInterfaces.ConfigurationFile[]>;
createProjectConnection(createConnectionInputs: CIXInterfaces.CreatePipelineConnectionInputs, project: string): Promise<CIXInterfaces.PipelineConnection>;
getDetectedBuildFrameworks(project: string, repositoryType?: string, repositoryId?: string, branch?: string, detectionType?: CIXInterfaces.BuildFrameworkDetectionType, serviceConnectionId?: string): Promise<CIXInterfaces.DetectedBuildFramework[]>;
createResources(creationParameters: { [key: string] : CIXInterfaces.ResourceCreationParameter; }, project: string): Promise<CIXInterfaces.CreatedResources>;
}

export class CixApi extends basem.ClientApiBase implements ICixApi {
constructor(baseUrl: string, handlers: VsoBaseInterfaces.IRequestHandler[], options?: VsoBaseInterfaces.IRequestOptions) {
super(baseUrl, handlers, 'node-Pipelines-api', options);
}

/**
* Gets a list of existing configuration files for the given repository.
*
* @param {string} project - Project ID or project name
* @param {string} repositoryType - The type of the repository such as GitHub, TfsGit (i.e. Azure Repos), Bitbucket, etc.
* @param {string} repositoryId - The vendor-specific identifier or the name of the repository, e.g. Microsoft/vscode (GitHub) or e9d82045-ddba-4e01-a63d-2ab9f040af62 (Azure Repos)
* @param {string} branch - The repository branch where to look for the configuration file.
* @param {string} serviceConnectionId - If specified, the ID of the service endpoint to query. Can only be omitted for providers that do not use service endpoints, e.g. TfsGit (i.e. Azure Repos).
*/
public async getConfigurations(
project: string,
repositoryType?: string,
repositoryId?: string,
branch?: string,
serviceConnectionId?: string
): Promise<CIXInterfaces.ConfigurationFile[]> {

return new Promise<CIXInterfaces.ConfigurationFile[]>(async (resolve, reject) => {
let routeValues: any = {
project: project
};

let queryValues: any = {
repositoryType: repositoryType,
repositoryId: repositoryId,
branch: branch,
serviceConnectionId: serviceConnectionId,
};

try {
let verData: vsom.ClientVersioningData = await this.vsoClient.getVersioningData(
"7.2-preview.1",
"pipelines",
"8fc87684-9ebc-4c37-ab92-f4ac4a58cb3a",
routeValues,
queryValues);

let url: string = verData.requestUrl!;
let options: restm.IRequestOptions = this.createRequestOptions('application/json',
verData.apiVersion);

let res: restm.IRestResponse<CIXInterfaces.ConfigurationFile[]>;
res = await this.rest.get<CIXInterfaces.ConfigurationFile[]>(url, options);

let ret = this.formatResponse(res.result,
null,
true);

resolve(ret);

}
catch (err) {
reject(err);
}
});
}

/**
* Creates a new Pipeline connection between the provider installation and the specified project. Returns the PipelineConnection object created.
*
* @param {CIXInterfaces.CreatePipelineConnectionInputs} createConnectionInputs
* @param {string} project
*/
public async createProjectConnection(
createConnectionInputs: CIXInterfaces.CreatePipelineConnectionInputs,
project: string
): Promise<CIXInterfaces.PipelineConnection> {
if (project == null) {
throw new TypeError('project can not be null or undefined');
}

return new Promise<CIXInterfaces.PipelineConnection>(async (resolve, reject) => {
let routeValues: any = {
};

let queryValues: any = {
project: project,
};

try {
let verData: vsom.ClientVersioningData = await this.vsoClient.getVersioningData(
"7.2-preview.1",
"pipelines",
"00df4879-9216-45d5-b38d-4a487b626b2c",
routeValues,
queryValues);

let url: string = verData.requestUrl!;
let options: restm.IRequestOptions = this.createRequestOptions('application/json',
verData.apiVersion);

let res: restm.IRestResponse<CIXInterfaces.PipelineConnection>;
res = await this.rest.create<CIXInterfaces.PipelineConnection>(url, createConnectionInputs, options);

let ret = this.formatResponse(res.result,
null,
false);

resolve(ret);

}
catch (err) {
reject(err);
}
});
}

/**
* Returns a list of build frameworks that best match the given repository based on its contents.
*
* @param {string} project - Project ID or project name
* @param {string} repositoryType - The type of the repository such as GitHub, TfsGit (i.e. Azure Repos), Bitbucket, etc.
* @param {string} repositoryId - The vendor-specific identifier or the name of the repository, e.g. Microsoft/vscode (GitHub) or e9d82045-ddba-4e01-a63d-2ab9f040af62 (Azure Repos)
* @param {string} branch - The repository branch to detect build frameworks for.
* @param {CIXInterfaces.BuildFrameworkDetectionType} detectionType
* @param {string} serviceConnectionId - If specified, the ID of the service endpoint to query. Can only be omitted for providers that do not use service endpoints, e.g. TfsGit (i.e. Azure Repos).
*/
public async getDetectedBuildFrameworks(
project: string,
repositoryType?: string,
repositoryId?: string,
branch?: string,
detectionType?: CIXInterfaces.BuildFrameworkDetectionType,
serviceConnectionId?: string
): Promise<CIXInterfaces.DetectedBuildFramework[]> {

return new Promise<CIXInterfaces.DetectedBuildFramework[]>(async (resolve, reject) => {
let routeValues: any = {
project: project
};

let queryValues: any = {
repositoryType: repositoryType,
repositoryId: repositoryId,
branch: branch,
detectionType: detectionType,
serviceConnectionId: serviceConnectionId,
};

try {
let verData: vsom.ClientVersioningData = await this.vsoClient.getVersioningData(
"7.2-preview.1",
"pipelines",
"29a30bab-9efb-4652-bf1b-9269baca0980",
routeValues,
queryValues);

let url: string = verData.requestUrl!;
let options: restm.IRequestOptions = this.createRequestOptions('application/json',
verData.apiVersion);

let res: restm.IRestResponse<CIXInterfaces.DetectedBuildFramework[]>;
res = await this.rest.get<CIXInterfaces.DetectedBuildFramework[]>(url, options);

let ret = this.formatResponse(res.result,
null,
true);

resolve(ret);

}
catch (err) {
reject(err);
}
});
}

/**
* @param {{ [key: string] : CIXInterfaces.ResourceCreationParameter; }} creationParameters
* @param {string} project - Project ID or project name
*/
public async createResources(
creationParameters: { [key: string] : CIXInterfaces.ResourceCreationParameter; },
project: string
): Promise<CIXInterfaces.CreatedResources> {

return new Promise<CIXInterfaces.CreatedResources>(async (resolve, reject) => {
let routeValues: any = {
project: project
};

try {
let verData: vsom.ClientVersioningData = await this.vsoClient.getVersioningData(
"7.2-preview.1",
"pipelines",
"43201899-7690-4870-9c79-ab69605f21ed",
routeValues);

let url: string = verData.requestUrl!;
let options: restm.IRequestOptions = this.createRequestOptions('application/json',
verData.apiVersion);

let res: restm.IRestResponse<CIXInterfaces.CreatedResources>;
res = await this.rest.create<CIXInterfaces.CreatedResources>(url, creationParameters, options);

let ret = this.formatResponse(res.result,
null,
false);

resolve(ret);

}
catch (err) {
reject(err);
}
});
}

}
13 changes: 10 additions & 3 deletions api/GitApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export interface IGitApi extends basem.ClientApiBase {
getRevertForRefName(project: string, repositoryId: string, refName: string): Promise<GitInterfaces.GitRevert>;
createCommitStatus(gitCommitStatusToCreate: GitInterfaces.GitStatus, commitId: string, repositoryId: string, project?: string): Promise<GitInterfaces.GitStatus>;
getStatuses(commitId: string, repositoryId: string, project?: string, top?: number, skip?: number, latestOnly?: boolean): Promise<GitInterfaces.GitStatus[]>;
getSuggestions(repositoryId: string, project?: string): Promise<GitInterfaces.GitSuggestion[]>;
getSuggestions(repositoryId: string, project?: string, preferCompareBranch?: boolean): Promise<GitInterfaces.GitSuggestion[]>;
getTree(repositoryId: string, sha1: string, project?: string, projectId?: string, recursive?: boolean, fileName?: string): Promise<GitInterfaces.GitTreeRef>;
getTreeZip(repositoryId: string, sha1: string, project?: string, projectId?: string, recursive?: boolean, fileName?: string): Promise<NodeJS.ReadableStream>;
}
Expand Down Expand Up @@ -7670,10 +7670,12 @@ export class GitApi extends basem.ClientApiBase implements IGitApi {
*
* @param {string} repositoryId - ID of the git repository.
* @param {string} project - Project ID or project name
* @param {boolean} preferCompareBranch - If true, prefer the compare branch over the default branch as target branch for pull requests.
*/
public async getSuggestions(
repositoryId: string,
project?: string
project?: string,
preferCompareBranch?: boolean
): Promise<GitInterfaces.GitSuggestion[]> {

return new Promise<GitInterfaces.GitSuggestion[]>(async (resolve, reject) => {
Expand All @@ -7682,12 +7684,17 @@ export class GitApi extends basem.ClientApiBase implements IGitApi {
repositoryId: repositoryId
};

let queryValues: any = {
preferCompareBranch: preferCompareBranch,
};

try {
let verData: vsom.ClientVersioningData = await this.vsoClient.getVersioningData(
"7.2-preview.1",
"git",
"9393b4fb-4445-4919-972b-9ad16f442d83",
routeValues);
routeValues,
queryValues);

let url: string = verData.requestUrl!;
let options: restm.IRequestOptions = this.createRequestOptions('application/json',
Expand Down
Loading

0 comments on commit 1351c2c

Please sign in to comment.