Skip to content

Commit

Permalink
use ado-node-api
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisRumyantsev committed Dec 19, 2023
1 parent ee56363 commit 8d38332
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 240 deletions.
237 changes: 131 additions & 106 deletions ci/ci-test-tasks/test-and-verify-v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ci/ci-test-tasks/test-and-verify-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"build": "tsc"
},
"dependencies": {
"axios": "^1.6.2"
"azure-devops-node-api": "^12.1.0"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.2",
Expand Down
68 changes: 68 additions & 0 deletions ci/ci-test-tasks/test-and-verify-v2/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { WebApi, getPersonalAccessTokenHandler } from 'azure-devops-node-api';
import { IBuildApi } from 'azure-devops-node-api/BuildApi';

class API {
public readonly tasks: string[];

private readonly projectName: string;
private readonly webApi: WebApi;
private buildApi: IBuildApi;

constructor(argv: string[]) {
const authToken = argv[2];
if (!authToken) {
throw new Error('Auth token is not provided');
}
const adoUrl = argv[3];
if (!adoUrl) {
throw new Error('ADO url is not provided');
}
this.projectName = argv[4];
if (!this.projectName) {
throw new Error('Project name is not provided');
}
const TaskArg = argv[5];
if (!TaskArg) {
throw new Error('Task list is not provided');
}

this.tasks = TaskArg.split(',');
const authHandler = getPersonalAccessTokenHandler(authToken);
this.webApi = new WebApi(adoUrl, authHandler);
}

public async getDefinitions () {
const api = await this.getBuildApi();

return await api.getDefinitions(this.projectName);
}

public async getBuild (buildId: number) {
const api = await this.getBuildApi();

return await api.getBuild(this.projectName, buildId);
}

public async queueBuild (definitionId: number, parameters = {}) {
const api = await this.getBuildApi();

return await api.queueBuild({
definition: { id: definitionId },
parameters: JSON.stringify(parameters)
}, this.projectName);
}

public async updateBuild (buildId: number) {
const api = await this.getBuildApi();

return await api.updateBuild({}, this.projectName, buildId, true);
}

private async getBuildApi () {
if (!this.buildApi) this.buildApi = await this.webApi.getBuildApi();

return this.buildApi;
}
}

export const api = new API(process.argv);
39 changes: 0 additions & 39 deletions ci/ci-test-tasks/test-and-verify-v2/src/config.ts

This file was deleted.

1 change: 0 additions & 1 deletion ci/ci-test-tasks/test-and-verify-v2/src/constants.ts

This file was deleted.

Loading

0 comments on commit 8d38332

Please sign in to comment.