Skip to content

Commit

Permalink
Use server API version 5.0 with BuildRestClient
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyskoedijk committed Nov 21, 2024
1 parent 3e3f6bd commit 01ba0b4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ui/sbom-report-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { CommonServiceIds, getClient, IProjectPageService } from 'azure-devops-extension-api';
import { BuildRestClient, BuildServiceIds, IBuildPageDataService } from 'azure-devops-extension-api/Build';
import { BuildServiceIds, IBuildPageDataService } from 'azure-devops-extension-api/Build';
import { Spinner } from 'azure-devops-ui/Spinner';
import { ZeroData } from 'azure-devops-ui/ZeroData';

import { SpdxDocumentPage } from './components/SpdxDocumentPage';
import { ISpdx22Document } from './models/Spdx22';

import { BuildRestClient } from './utils/BuildRestClient';
import './utils/StringExtensions';

import './sbom-report-tab.scss';
Expand Down
64 changes: 64 additions & 0 deletions ui/utils/BuildRestClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { IVssRestClientOptions } from 'azure-devops-extension-api/Common';
import { RestClientBase } from 'azure-devops-extension-api/Common/RestClientBase';

import * as Build from 'azure-devops-extension-api/Build';

export class BuildRestClient extends RestClientBase {
constructor(options: IVssRestClientOptions) {
super(options);
}

public static readonly API_VERSION = '5.0';

/**
* Gets the list of attachments of a specific type that are associated with a build.
*
* @param project - Project ID or project name
* @param buildId - The ID of the build.
* @param type - The type of attachment.
*/
public async getAttachments(project: string, buildId: number, type: string): Promise<Build.Attachment[]> {
return this.beginRequest<Build.Attachment[]>({
apiVersion: BuildRestClient.API_VERSION,
routeTemplate: '{project}/_apis/build/builds/{buildId}/attachments/{type}',
routeValues: {
project: project,
buildId: buildId,
type: type,
},
});
}

/**
* Gets a specific attachment.
*
* @param project - Project ID or project name
* @param buildId - The ID of the build.
* @param timelineId - The ID of the timeline.
* @param recordId - The ID of the timeline record.
* @param type - The type of the attachment.
* @param name - The name of the attachment.
*/
public async getAttachment(
project: string,
buildId: number,
timelineId: string,
recordId: string,
type: string,
name: string,
): Promise<ArrayBuffer> {
return this.beginRequest<ArrayBuffer>({
apiVersion: BuildRestClient.API_VERSION,
httpResponseType: 'application/octet-stream',
routeTemplate: '{project}/_apis/build/builds/{buildId}/{timelineId}/{recordId}/attachments/{type}/{name}',
routeValues: {
project: project,
buildId: buildId,
timelineId: timelineId,
recordId: recordId,
type: type,
name: name,
},
});
}
}

0 comments on commit 01ba0b4

Please sign in to comment.