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

Rich azure integration basics (#3976) #3984

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions src/constants.integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const supportedOrderedCloudIntegrationIds = [
SelfHostedIntegrationId.CloudGitHubEnterprise,
HostingIntegrationId.GitLab,
SelfHostedIntegrationId.CloudGitLabSelfHosted,
HostingIntegrationId.AzureDevOps,
axosoft-ramint marked this conversation as resolved.
Show resolved Hide resolved
IssueIntegrationId.Jira,
];

Expand Down Expand Up @@ -71,6 +72,12 @@ export const supportedCloudIntegrationDescriptors: IntegrationDescriptor[] = [
icon: 'gl-provider-gitlab',
supports: ['prs', 'issues'],
},
{
id: HostingIntegrationId.AzureDevOps,
name: 'Azure DevOps',
icon: 'gl-provider-azdo',
supports: ['prs', 'issues'],
},
{
id: IssueIntegrationId.Jira,
name: 'Jira',
Expand Down
108 changes: 2 additions & 106 deletions src/plus/integrations/authentication/azureDevOps.ts
Original file line number Diff line number Diff line change
@@ -1,112 +1,8 @@
import type { Disposable, QuickInputButton } from 'vscode';
import { env, ThemeIcon, Uri, window } from 'vscode';
import { HostingIntegrationId } from '../../../constants.integrations';
import { base64 } from '../../../system/string';
import type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider';
import { LocalIntegrationAuthenticationProvider } from './integrationAuthenticationProvider';
import type { ProviderAuthenticationSession } from './models';
import { CloudIntegrationAuthenticationProvider } from './integrationAuthenticationProvider';

export class AzureDevOpsAuthenticationProvider extends LocalIntegrationAuthenticationProvider<HostingIntegrationId.AzureDevOps> {
export class AzureDevOpsAuthenticationProvider extends CloudIntegrationAuthenticationProvider<HostingIntegrationId.AzureDevOps> {
protected override get authProviderId(): HostingIntegrationId.AzureDevOps {
return HostingIntegrationId.AzureDevOps;
}

override async createSession(
descriptor: IntegrationAuthenticationSessionDescriptor,
): Promise<ProviderAuthenticationSession | undefined> {
let azureOrganization: string | undefined = descriptor.organization as string | undefined;
if (!azureOrganization) {
const orgInput = window.createInputBox();
orgInput.ignoreFocusOut = true;
const orgInputDisposables: Disposable[] = [];
try {
azureOrganization = await new Promise<string | undefined>(resolve => {
orgInputDisposables.push(
orgInput.onDidHide(() => resolve(undefined)),
orgInput.onDidChangeValue(() => (orgInput.validationMessage = undefined)),
orgInput.onDidAccept(() => {
const value = orgInput.value.trim();
if (!value) {
orgInput.validationMessage = 'An organization is required';
return;
}

resolve(value);
}),
);

orgInput.title = `Azure DevOps Authentication \u2022 ${descriptor.domain}`;
orgInput.placeholder = 'Organization';
orgInput.prompt = 'Enter your Azure DevOps organization';
orgInput.show();
});
} finally {
orgInput.dispose();
orgInputDisposables.forEach(d => void d.dispose());
}
}

if (!azureOrganization) return undefined;

const tokenInput = window.createInputBox();
tokenInput.ignoreFocusOut = true;

const disposables: Disposable[] = [];

let token;
try {
const infoButton: QuickInputButton = {
iconPath: new ThemeIcon(`link-external`),
tooltip: 'Open the Azure DevOps Access Tokens Page',
};

token = await new Promise<string | undefined>(resolve => {
disposables.push(
tokenInput.onDidHide(() => resolve(undefined)),
tokenInput.onDidChangeValue(() => (tokenInput.validationMessage = undefined)),
tokenInput.onDidAccept(() => {
const value = tokenInput.value.trim();
if (!value) {
tokenInput.validationMessage = 'A personal access token is required';
return;
}

resolve(value);
}),
tokenInput.onDidTriggerButton(e => {
if (e === infoButton) {
void env.openExternal(
Uri.parse(`https://${descriptor.domain}/${azureOrganization}/_usersSettings/tokens`),
);
}
}),
);

tokenInput.password = true;
tokenInput.title = `Azure DevOps Authentication \u2022 ${descriptor.domain}`;
tokenInput.placeholder = `Requires ${descriptor.scopes.join(', ') ?? 'all'} scopes`;
tokenInput.prompt = `Paste your [Azure DevOps Personal Access Token](https://${descriptor.domain}/${azureOrganization}/_usersSettings/tokens "Get your Azure DevOps Access Token")`;
tokenInput.buttons = [infoButton];

tokenInput.show();
});
} finally {
tokenInput.dispose();
disposables.forEach(d => void d.dispose());
}

if (!token) return undefined;

return {
id: this.configuredIntegrationService.getSessionId(descriptor),
accessToken: base64(`:${token}`),
scopes: descriptor.scopes,
account: {
id: '',
label: '',
},
cloud: false,
domain: descriptor.domain,
};
}
}
8 changes: 4 additions & 4 deletions src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,10 @@ export class IntegrationService implements Disposable {

switch (remote.provider.id) {
// TODO: Uncomment when we support these integrations
// case 'azure-devops':
// return get(HostingIntegrationId.AzureDevOps) as RT;
// case 'bitbucket':
// return get(HostingIntegrationId.Bitbucket) as RT;
case 'azure-devops':
return get(HostingIntegrationId.AzureDevOps) as RT;
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably need to check the remote's domain here and only return the azure devops id if it's non-enterprise. We don't support azure enterprise yet and should probably return undefined for that.

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
Done.
Something like this?
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't tested it yet, but if you've verified by cloning an azure repo and making sure it passes this check, I think we should be good to go.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I cloned both: a repo under dev.azure.com and another one under *.visualstudio.com

case 'github':
if (remote.provider.domain != null && !isGitHubDotCom(remote.provider.domain)) {
return get(
Expand Down Expand Up @@ -1030,10 +1030,10 @@ export function remoteProviderIdToIntegrationId(
): SupportedCloudIntegrationIds | undefined {
switch (remoteProviderId) {
// TODO: Uncomment when we support these integrations
// case 'azure-devops':
// return HostingIntegrationId.AzureDevOps;
// case 'bitbucket':
// return HostingIntegrationId.Bitbucket;
case 'azure-devops':
return HostingIntegrationId.AzureDevOps;
case 'github':
return HostingIntegrationId.GitHub;
case 'gitlab':
Expand Down
Loading