Skip to content

Commit 3c5bd61

Browse files
authored
Repackage azure-devops-extensions-api to fix Azure DevOps report plugin (#6299)
* Repackage azure-devops-extensions-api * Unify headers * Regenerate the package-lock.json file * Remove unneeded packages * Make tsc build verbose * Add debug flag for vite build * Add NPM build command for testing * Fix the tsc build * Make sure we log stdout when an error occurs.
1 parent 78d9c88 commit 3c5bd61

30 files changed

+1744
-275
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
override.json
22
package-lock.json
33
VSIXPackageVersion.json
4-
LICENSE
4+
LICENSE
5+
6+
!Build
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/*
3+
* ---------------------------------------------------------
4+
* Copyright(C) Microsoft Corporation. All rights reserved.
5+
* ---------------------------------------------------------
6+
*/
7+
8+
import * as TfsCore from "../Core/Core";
9+
10+
/**
11+
* Represents an attachment to a build.
12+
*/
13+
export interface Attachment {
14+
_links: any;
15+
/**
16+
* The name of the attachment.
17+
*/
18+
name: string;
19+
}
20+
21+
/**
22+
* Data representation of a build.
23+
*/
24+
export interface Build {
25+
/**
26+
* The ID of the build.
27+
*/
28+
id: number;
29+
30+
project: TfsCore.TeamProjectReference;
31+
}
32+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* ---------------------------------------------------------
3+
* Copyright(C) Microsoft Corporation. All rights reserved.
4+
* ---------------------------------------------------------
5+
*/
6+
7+
import { IVssRestClientOptions } from "../Common/Context";
8+
import { RestClientBase } from "../Common/RestClientBase";
9+
10+
import * as Build from "./Build";
11+
12+
export class BuildRestClient extends RestClientBase {
13+
constructor(options: IVssRestClientOptions) {
14+
super(options);
15+
}
16+
17+
public static readonly RESOURCE_AREA_ID = "965220d5-5bb9-42cf-8d67-9b146df2a5a4";
18+
19+
/**
20+
* Gets the list of attachments of a specific type that are associated with a build.
21+
*
22+
* @param project - Project ID or project name
23+
* @param buildId - The ID of the build.
24+
* @param type - The type of attachment.
25+
*/
26+
public async getAttachments(
27+
project: string,
28+
buildId: number,
29+
type: string
30+
): Promise<Build.Attachment[]> {
31+
32+
return this.beginRequest<Build.Attachment[]>({
33+
apiVersion: "7.2-preview.2",
34+
routeTemplate: "{project}/_apis/build/builds/{buildId}/attachments/{type}",
35+
routeValues: {
36+
project: project,
37+
buildId: buildId,
38+
type: type
39+
}
40+
});
41+
}
42+
43+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./Build";
2+
export * from "./BuildClient";
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
import { getAccessToken, getService } from "azure-devops-extension-sdk";
5+
import { IVssRestClientOptions } from "./Context";
6+
import { CommonServiceIds, ILocationService } from "./CommonServices";
7+
8+
/**
9+
* A REST client factory is the method used to create and initialize an IVssRestClient.
10+
*/
11+
export type RestClientFactory<T> = {
12+
new (options: IVssRestClientOptions): T;
13+
RESOURCE_AREA_ID?: string;
14+
}
15+
16+
export function getClient<T>(clientClass: RestClientFactory<T>, clientOptions?: IVssRestClientOptions) {
17+
18+
const options = clientOptions || {};
19+
20+
if (!options.rootPath) {
21+
options.rootPath = getService<ILocationService>(CommonServiceIds.LocationService).then(locationService => {
22+
if (clientClass.RESOURCE_AREA_ID) {
23+
return locationService.getResourceAreaLocation(clientClass.RESOURCE_AREA_ID);
24+
}
25+
else {
26+
return locationService.getServiceLocation();
27+
}
28+
});
29+
}
30+
31+
if (!options.authTokenProvider) {
32+
options.authTokenProvider = {
33+
getAuthorizationHeader: (): Promise<string> => {
34+
return getAccessToken().then(token => token ? ("Bearer " + token) : "");
35+
}
36+
};
37+
}
38+
39+
return new clientClass(options);
40+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
/**
5+
* Contribution ids of core DevOps services which can be obtained from DevOps.getService
6+
*/
7+
export const enum CommonServiceIds {
8+
9+
/**
10+
* Service for getting URLs/locations from the host context
11+
*/
12+
LocationService = "ms.vss-features.location-service",
13+
14+
}
15+
16+
/**
17+
* Host level for a VSS service
18+
*/
19+
export const enum TeamFoundationHostType {
20+
/**
21+
* The Deployment host
22+
*/
23+
Deployment = 1,
24+
25+
/**
26+
* The Enterprise host
27+
*/
28+
Enterprise = 2,
29+
30+
/**
31+
* The organization/project collection host
32+
*/
33+
Organization = 4
34+
}
35+
36+
/**
37+
* Service for external content to get locations
38+
*/
39+
export interface ILocationService {
40+
41+
/**
42+
* Gets the URL for the given REST resource area
43+
*
44+
* @param resourceAreaId - Id of the resource area
45+
*/
46+
getResourceAreaLocation(resourceAreaId: string): Promise<string>;
47+
48+
/**
49+
* Gets the location of a remote service at a given host type.
50+
*
51+
* @param serviceInstanceType - The GUID of the service instance type to lookup
52+
* @param hostType - The host type to lookup (defaults to the host type of the current page data)
53+
*/
54+
getServiceLocation(serviceInstanceType?: string, hostType?: TeamFoundationHostType): Promise<string>;
55+
56+
/**
57+
* Attemps to create a url for the specified route template and paramaters. The url will include host path.
58+
* For example, if the page url is https://dev.azure.com/foo and you try to create admin settings url for project "bar",
59+
* the output will be /foo/bar/_admin.
60+
*
61+
* This will asynchronously fetch a route contribution if it has not been included in page data.
62+
*
63+
* @param routeId - Id of the route contribution
64+
* @param routeValues - Route value replacements
65+
* @param hostPath - Optional host path to use rather than the default host path for the page.
66+
*/
67+
routeUrl(routeId: string, routeValues?: { [key: string]: string }, hostPath?: string): Promise<string>;
68+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
/**
5+
* Interface for a class that can retrieve authorization tokens to be used in fetch requests.
6+
*/
7+
export interface IAuthorizationTokenProvider {
8+
/**
9+
* Gets the authorization header to use in a fetch request
10+
*
11+
* @param forceRefresh - If true, indicates that we should get a new token, if applicable for current provider.
12+
* @returns the value to use for the Authorization header in a request.
13+
*/
14+
getAuthorizationHeader(forceRefresh?: boolean): Promise<string>;
15+
}
16+
17+
/**
18+
* Options for a specific instance of a REST client.
19+
*/
20+
export interface IVssRestClientOptions {
21+
22+
/**
23+
* Auth token manager that can be used to get and attach auth tokens to requests.
24+
* If not supplied, the default token provider is used if the serviceInstanceType option is supplied
25+
* and is different from the hosting page's service instance type.
26+
*/
27+
authTokenProvider?: IAuthorizationTokenProvider;
28+
29+
/**
30+
* The root URL path to use for this client. Can be relative or absolute.
31+
*/
32+
rootPath?: string | Promise<string>;
33+
34+
/**
35+
* Current session id.
36+
*/
37+
sessionId?: string;
38+
39+
/**
40+
* Current command for activity logging.
41+
*/
42+
command?: string;
43+
}

0 commit comments

Comments
 (0)