-
Notifications
You must be signed in to change notification settings - Fork 167
/
utility.ts
44 lines (41 loc) · 1.32 KB
/
utility.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as SDK from 'azure-devops-extension-sdk';
import { CommonServiceIds, IProjectPageService, getClient } from 'azure-devops-extension-api';
import { Build, BuildDefinition, BuildQueryOrder, BuildRestClient, BuildStatus } from 'azure-devops-extension-api/Build';
async function getCurrentProjectId(): Promise<string | undefined> {
const pps = await SDK.getService<IProjectPageService>(
CommonServiceIds.ProjectPageService
);
const project = await pps.getProject();
return project?.id;
}
export async function getLastestBuild( pipelineId: number ): Promise<Build | undefined> {
const projectId = await getCurrentProjectId();
const builds = await getClient(BuildRestClient).getBuilds(
projectId!,
[pipelineId],
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
BuildStatus.Completed,
undefined,
undefined,
undefined,
1 /*top*/,
undefined,
undefined,
undefined,
BuildQueryOrder.StartTimeDescending,
undefined,
undefined,
undefined,
undefined
);
return builds.length > 0 ? builds[0] : undefined;
}
export async function getPipelineDefinition(pipelineId: number): Promise<BuildDefinition> {
const projectId = await getCurrentProjectId();
return await getClient(BuildRestClient).getDefinition(projectId!, pipelineId);
}