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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/autolinks/autolinks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ConfigurationChangeEvent } from 'vscode';
import { Disposable } from 'vscode';
import { GlyphChars } from '../constants';
import type { IntegrationId } from '../constants.integrations';
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 { 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 +214,9 @@ 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;
const integrationId = link.provider ? remoteProviderIdToIntegrationId(link.provider.id) : undefined;
Copy link
Member Author

@sergeibbb sergeibbb Jan 30, 2025

Choose a reason for hiding this comment

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

@sergeibbb !
Here with this new ID converting function we'll need to make sure that other types of enriched autolinks are not broken. What do we have? Jira, GitHub Cloud and Ent, GitLab Cloud and Ent. Anything else to check?

Copy link
Contributor

Choose a reason for hiding this comment

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

In some cases like in Jira, we pass the entire integration in as a provider reference, so remoteProviderIdToIntegrationId will fail here. I think in the short term here, we can first try treating link.provider.id as an integration id and try to get the integration from that, and put that in a try/catch so if it fails, then we can try the solution here (try treating it as a remote provider id and convert first before getting the integration).

But in the long term, we need to distinguish, on pull requests, issues, and autolinks, the difference between a remote provider reference and an integration reference. They should be treated separately and put into different properties. If we cannot accomplish that here, we should treat it as a follow-up task.

Copy link
Contributor

Choose a reason for hiding this comment

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

My short term idea would be something like:

Suggested change
const integrationId = link.provider ? remoteProviderIdToIntegrationId(link.provider.id) : undefined;
const integrationId: IntegrationId | undefined = link.provider instanceof Integration ? link.provider.id : isRemoteProviderReference(link.provider) ? remoteProviderIdToIntegrationId(link.provider.id) : undefined;
let linkIntegration = integrationId != null ? await this.container.integrations.get(integrationId) : undefined;

But in long term, we should make sure we never put an Integration into provider property, reserve that for remote providers, and instead have a separate integration property or something that is an integration reference.

let linkIntegration =
integrationId != null ? await this.container.integrations.get(integrationId) : undefined;
if (linkIntegration != null) {
const connected = linkIntegration.maybeConnected ?? (await linkIntegration.isConnected());
if (!connected || !(await linkIntegration.access())) {
Expand All @@ -226,7 +226,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.

remoteProviderId: RemoteProviderId,
): SupportedCloudIntegrationIds | undefined {
export function remoteProviderIdToIntegrationId(remoteProviderId: unknown): 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