Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enriches Azure autolinks on commits: issues and pull requests #3996

Merged
merged 12 commits into from
Feb 3, 2025
Merged
29 changes: 24 additions & 5 deletions src/autolinks/autolinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { IssueIntegrationId } from '../constants.integrations';
import type { Container } from '../container';
import type { GitRemote } from '../git/models/remote';
import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from '../git/utils/-webview/icons';
import type { HostingIntegration, IssueIntegration } from '../plus/integrations/integration';
import type { HostingIntegration, Integration, IssueIntegration } from '../plus/integrations/integration';
import { IntegrationBase } from '../plus/integrations/integration';
import { remoteProviderIdToIntegrationId } from '../plus/integrations/integrationService';
import { configuration } from '../system/-webview/configuration';
import { fromNow } from '../system/date';
import { debug } from '../system/decorators/log';
Expand Down Expand Up @@ -214,9 +216,26 @@ export class Autolinks implements Disposable {

const enrichedAutolinks = new Map<string, EnrichedAutolink>();
for (const [id, link] of messageOrAutolinks) {
let linkIntegration = link.provider
? await this.container.integrations.get(link.provider.id as IntegrationId)
: undefined;
let integrationId: IntegrationId | undefined;
let linkIntegration: Integration | undefined;
if (link.provider != null) {
// Try to make a smart choice
integrationId =
link.provider instanceof IntegrationBase
? link.provider.id
: remoteProviderIdToIntegrationId(link.provider.id);
if (integrationId == null) {
// Fall back to the old logic assuming that integration id might be saved as provider id.
// TODO: it should be removed when we put providers and integrations in order. Conversation: https://github.com/gitkraken/vscode-gitlens/pull/3996#discussion_r1936422826
integrationId = link.provider.id as IntegrationId;
}
try {
linkIntegration = await this.container.integrations.get(integrationId);
} catch (e) {
Logger.error(e, `Failed to get integration for ${link.provider.id}`);
linkIntegration = undefined;
}
}
if (linkIntegration != null) {
const connected = linkIntegration.maybeConnected ?? (await linkIntegration.isConnected());
if (!connected || !(await linkIntegration.access())) {
Expand All @@ -226,7 +245,7 @@ export class Autolinks implements Disposable {
const issueOrPullRequestPromise =
remote?.provider != null &&
integration != null &&
link.provider?.id === integration.id &&
integrationId === integration.id &&
link.provider?.domain === integration.domain
? integration.getIssueOrPullRequest(
link.descriptor ?? remote.provider.repoDesc,
Expand Down
23 changes: 23 additions & 0 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { CloudIntegrationService } from './plus/integrations/authentication
import { ConfiguredIntegrationService } from './plus/integrations/authentication/configuredIntegrationService';
import { IntegrationAuthenticationService } from './plus/integrations/authentication/integrationAuthenticationService';
import { IntegrationService } from './plus/integrations/integrationService';
import type { AzureDevOpsApi } from './plus/integrations/providers/azure/azure';
import type { GitHubApi } from './plus/integrations/providers/github/github';
import type { GitLabApi } from './plus/integrations/providers/gitlab/gitlab';
import { EnrichmentService } from './plus/launchpad/enrichmentService';
Expand Down Expand Up @@ -477,6 +478,28 @@ export class Container {
return this._git;
}

private _azure: Promise<AzureDevOpsApi | undefined> | undefined;
get azure(): Promise<AzureDevOpsApi | undefined> {
if (this._azure == null) {
async function load(this: Container) {
try {
const azure = new (
await import(/* webpackChunkName: "integrations" */ './plus/integrations/providers/azure/azure')
).AzureDevOpsApi(this);
this._disposables.push(azure);
return azure;
} catch (ex) {
Logger.error(ex);
return undefined;
}
}

this._azure = load.call(this);
}

return this._azure;
}

private _github: Promise<GitHubApi | undefined> | undefined;
get github(): Promise<GitHubApi | undefined> {
if (this._github == null) {
Expand Down
7 changes: 1 addition & 6 deletions src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,13 +1029,8 @@ export class IntegrationService implements Disposable {
}
}

export function remoteProviderIdToIntegrationId(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid setting the input typing to unknown here. I know we messed up by treating integrations as remote provider references in several places, but it would be better to work toward addressing that directly rather than loosening the typing here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axosoft-ramint Allow it to be astring?
If I require it to be RemoteProviderId it will cause type casting in autolinks.ts where we don't really know an actual type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

remoteProviderId: RemoteProviderId,
): SupportedCloudIntegrationIds | undefined {
export function remoteProviderIdToIntegrationId(remoteProviderId: string): SupportedCloudIntegrationIds | undefined {
switch (remoteProviderId) {
// TODO: Uncomment when we support these integrations
// case 'bitbucket':
// return HostingIntegrationId.Bitbucket;
case 'azure-devops':
return HostingIntegrationId.AzureDevOps;
case 'github':
Expand Down
Loading