Skip to content

Commit d54a782

Browse files
sergeibbbdv
authored and
dv
committed
Implements getAccountForCommit for AzureDevOps
(#4192, #4243)
1 parent e4f5410 commit d54a782

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

src/plus/integrations/providers/azure/azure.ts

+51
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
RequestClientError,
1414
RequestNotFoundError,
1515
} from '../../../../errors';
16+
import type { UnidentifiedAuthor } from '../../../../git/models/author';
1617
import type { Issue } from '../../../../git/models/issue';
1718
import type { IssueOrPullRequest } from '../../../../git/models/issueOrPullRequest';
1819
import type { PullRequest } from '../../../../git/models/pullRequest';
@@ -25,6 +26,7 @@ import type { LogScope } from '../../../../system/logger.scope';
2526
import { getLogScope } from '../../../../system/logger.scope';
2627
import { maybeStopWatch } from '../../../../system/stopwatch';
2728
import type {
29+
AzureGitCommit,
2830
AzureProjectDescriptor,
2931
AzurePullRequest,
3032
AzurePullRequestWithLinks,
@@ -312,6 +314,55 @@ export class AzureDevOpsApi implements Disposable {
312314
return undefined;
313315
}
314316

317+
@debug<AzureDevOpsApi['getAccountForCommit']>({ args: { 0: p => p.name, 1: '<token>' } })
318+
async getAccountForCommit(
319+
provider: Provider,
320+
token: string,
321+
owner: string,
322+
repo: string,
323+
rev: string,
324+
baseUrl: string,
325+
_options?: {
326+
avatarSize?: number;
327+
},
328+
): Promise<UnidentifiedAuthor | undefined> {
329+
const scope = getLogScope();
330+
const [projectName, _, repoName] = repo.split('/');
331+
332+
try {
333+
// Try to get the Work item (wit) first with specific fields
334+
const commit = await this.request<AzureGitCommit>(
335+
provider,
336+
token,
337+
baseUrl,
338+
`${owner}/${projectName}/_apis/git/repositories/${repoName}/commits/${rev}`,
339+
{
340+
method: 'GET',
341+
},
342+
scope,
343+
);
344+
const author = commit?.author;
345+
if (!author) {
346+
return undefined;
347+
}
348+
return {
349+
provider: provider,
350+
id: undefined,
351+
username: undefined,
352+
name: author?.name,
353+
email: author?.email,
354+
avatarUrl: undefined,
355+
} satisfies UnidentifiedAuthor;
356+
} catch (ex) {
357+
if (ex.original?.status !== 404) {
358+
Logger.error(ex, scope);
359+
return undefined;
360+
}
361+
}
362+
363+
return undefined;
364+
}
365+
315366
async getWorkItemStateCategory(
316367
issueType: string,
317368
state: string,

src/plus/integrations/providers/azure/models.ts

+33
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,44 @@ export interface AzureRepository {
202202
isInMaintenance: boolean;
203203
}
204204

205+
export interface AzureGitUser {
206+
date?: string;
207+
email?: string;
208+
imageUrl?: string;
209+
name: string;
210+
}
211+
205212
export interface AzureGitCommitRef {
206213
commitId: string;
207214
url: string;
208215
}
209216

217+
export interface AzureGitCommit {
218+
_links: {
219+
changes: AzureLink;
220+
repository: AzureLink;
221+
self: AzureLink;
222+
web: AzureLink;
223+
};
224+
author: AzureGitUser;
225+
comment: string;
226+
commentTruncated?: boolean;
227+
commitId: string;
228+
commitTooManyChanges?: boolean;
229+
committer: AzureGitUser;
230+
parents: string[];
231+
push: {
232+
date: string;
233+
pushedBy: AzureUser;
234+
pushId: number;
235+
};
236+
remoteUrl: string;
237+
statuses?: AzureGitStatus[];
238+
treeId: string;
239+
url: string;
240+
workItems?: AzureResourceRef[];
241+
}
242+
210243
export interface AzureResourceRef {
211244
id: string;
212245
url: string;

src/plus/integrations/providers/azureDevOps.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AuthenticationSession, CancellationToken } from 'vscode';
22
import { window } from 'vscode';
33
import { HostingIntegrationId } from '../../../constants.integrations';
4-
import type { Account } from '../../../git/models/author';
4+
import type { Account, UnidentifiedAuthor } from '../../../git/models/author';
55
import type { DefaultBranch } from '../../../git/models/defaultBranch';
66
import type { Issue, IssueShape } from '../../../git/models/issue';
77
import type { IssueOrPullRequest } from '../../../git/models/issueOrPullRequest';
@@ -218,14 +218,22 @@ export class AzureDevOpsIntegration extends HostingIntegration<
218218
}
219219

220220
protected override async getProviderAccountForCommit(
221-
_session: AuthenticationSession,
222-
_repo: AzureRepositoryDescriptor,
223-
_rev: string,
224-
_options?: {
221+
{ accessToken }: AuthenticationSession,
222+
repo: AzureRepositoryDescriptor,
223+
rev: string,
224+
options?: {
225225
avatarSize?: number;
226226
},
227-
): Promise<Account | undefined> {
228-
return Promise.resolve(undefined);
227+
): Promise<UnidentifiedAuthor | undefined> {
228+
return (await this.container.azure)?.getAccountForCommit(
229+
this,
230+
accessToken,
231+
repo.owner,
232+
repo.name,
233+
rev,
234+
this.apiBaseUrl,
235+
options,
236+
);
229237
}
230238

231239
protected override async getProviderAccountForEmail(

0 commit comments

Comments
 (0)