-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Adds create pr urls for other providers #4143
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
Changes from 9 commits
59b2670
7824100
37b442a
335e51e
9ee38b0
28a5220
e53c6fb
bf2d1d5
2ccaefa
a244941
b2f2ab3
27f916a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import type { Range, Uri } from 'vscode'; | ||
| import type { AutolinkReference, DynamicAutolinkReference } from '../../autolinks/models/autolinks'; | ||
| import type { Container } from '../../container'; | ||
| import { HostingIntegration } from '../../plus/integrations/integration'; | ||
| import { remoteProviderIdToIntegrationId } from '../../plus/integrations/integrationService'; | ||
| import { parseAzureHttpsUrl } from '../../plus/integrations/providers/azure/models'; | ||
| import type { Brand, Unbrand } from '../../system/brand'; | ||
| import type { Repository } from '../models/repository'; | ||
| import type { GkProviderId } from '../models/repositoryIdentities'; | ||
|
|
@@ -17,7 +21,14 @@ const rangeRegex = /line=(\d+)(?:&lineEnd=(\d+))?/; | |
|
|
||
| export class AzureDevOpsRemote extends RemoteProvider { | ||
| private readonly project: string | undefined; | ||
| constructor(domain: string, path: string, protocol?: string, name?: string, legacy: boolean = false) { | ||
| constructor( | ||
| private readonly container: Container, | ||
| domain: string, | ||
| path: string, | ||
| protocol?: string, | ||
| name?: string, | ||
| legacy: boolean = false, | ||
| ) { | ||
| let repoProject; | ||
| if (sshDomainRegex.test(domain)) { | ||
| path = path.replace(sshPathRegex, ''); | ||
|
|
@@ -182,8 +193,44 @@ export class AzureDevOpsRemote extends RemoteProvider { | |
| return this.encodeUrl(`${this.baseUrl}/commit/${sha}`); | ||
| } | ||
|
|
||
| protected override getUrlForComparison(base: string, compare: string, _notation: '..' | '...'): string { | ||
| return this.encodeUrl(`${this.baseUrl}/branchCompare?baseVersion=GB${base}&targetVersion=GB${compare}`); | ||
| protected override getUrlForComparison(base: string, head: string, _notation: '..' | '...'): string { | ||
| return this.encodeUrl(`${this.baseUrl}/branchCompare?baseVersion=GB${base}&targetVersion=GB${head}`); | ||
| } | ||
|
|
||
| override async isReadyForForCrossForkPullRequestUrls(): Promise<boolean> { | ||
| const integrationId = remoteProviderIdToIntegrationId(this.id); | ||
| const integration = integrationId && (await this.container.integrations.get(integrationId)); | ||
| return integration?.maybeConnected ?? integration?.isConnected() ?? false; | ||
| } | ||
|
|
||
| protected override async getUrlForCreatePullRequest( | ||
| base: { branch?: string; remote: { path: string; url: string } }, | ||
| head: { branch: string; remote: { path: string; url: string } }, | ||
| ): Promise<string | undefined> { | ||
| const query = new URLSearchParams({ sourceRef: head.branch, targetRef: base.branch ?? '' }); | ||
| if (base.remote.url !== head.remote.url) { | ||
| const parsedBaseUrl = parseAzureUrl(base.remote.url); | ||
| if (parsedBaseUrl == null) { | ||
| return undefined; | ||
| } | ||
| const { org: baseOrg, project: baseProject, repo: baseName } = parsedBaseUrl; | ||
| const targetDesc = { project: baseProject, name: baseName, owner: baseOrg }; | ||
|
|
||
| const integrationId = remoteProviderIdToIntegrationId(this.id); | ||
| const integration = integrationId && (await this.container.integrations.get(integrationId)); | ||
| let targetRepoId = undefined; | ||
| if (integration?.isConnected && integration instanceof HostingIntegration) { | ||
| targetRepoId = (await integration.getRepoInfo?.(targetDesc))?.id; | ||
| } | ||
|
|
||
| if (!targetRepoId) { | ||
| return undefined; | ||
| } | ||
| query.set('targetRepositoryId', targetRepoId); | ||
| // query.set('sourceRepositoryId', compare.repoId); // ?? looks like not needed | ||
| } | ||
|
|
||
| return `${this.encodeUrl(`${this.getRepoBaseUrl(head.remote.path)}/pullrequestcreate`)}?${query.toString()}`; | ||
| } | ||
|
|
||
| protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string { | ||
|
|
@@ -207,3 +254,22 @@ export class AzureDevOpsRemote extends RemoteProvider { | |
| return this.encodeUrl(`${this.baseUrl}?path=/${fileName}${line}`); | ||
| } | ||
| } | ||
|
|
||
| const azureSshUrlRegex = /^(?:[^@]+@)?([^:]+):v\d\//; | ||
| function parseAzureUrl(url: string): { org: string; project: string; repo: string } | undefined { | ||
| if (azureSshUrlRegex.test(url)) { | ||
| // Examples of SSH urls: | ||
| // - old one: [email protected]:v3/bbbchiv/MyFirstProject/test | ||
| // - modern one: [email protected]:v3/bbbchiv2/MyFirstProject/test | ||
| url = url.replace(azureSshUrlRegex, ''); | ||
| const match = orgAndProjectRegex.exec(url); | ||
| if (match != null) { | ||
| const [, org, project, rest] = match; | ||
| return { org: org, project: project, repo: rest }; | ||
| } | ||
| } else { | ||
| const [org, project, rest] = parseAzureHttpsUrl(url); | ||
| return { org: org, project: project, repo: rest }; | ||
| } | ||
| return undefined; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,8 +157,26 @@ | |
| return this.encodeUrl(`${this.baseUrl}/commits/${sha}`); | ||
| } | ||
|
|
||
| protected override getUrlForComparison(base: string, compare: string, _notation: '..' | '...'): string { | ||
| return this.encodeUrl(`${this.baseUrl}/branches/compare/${base}%0D${compare}`).replace('%250D', '%0D'); | ||
| protected override getUrlForComparison(base: string, head: string, _notation: '..' | '...'): string { | ||
| return this.encodeUrl(`${this.baseUrl}/branches/compare/${base}%0D${head}`).replace('%250D', '%0D'); | ||
| } | ||
|
|
||
| protected override getUrlForCreatePullRequest( | ||
| base: { branch?: string; remote: { path: string; url: string } }, | ||
| head: { branch: string; remote: { path: string; url: string } }, | ||
| options?: { title?: string; description?: string }, | ||
| ): string | undefined { | ||
| const query = new URLSearchParams({ sourceBranch: head.branch, targetBranch: base.branch ?? '' }); | ||
| // TODO: figure this out | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this just need to be removed or figured out still? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eamodio It's been waiting for bitbucket-server to be merged. But than I've switched to another task. So, yes, needs to be figured out. |
||
| // query.set('targetRepoId', base.repoId); | ||
| if (options?.title) { | ||
| query.set('title', options.title); | ||
| } | ||
| if (options?.description) { | ||
| query.set('description', options.description); | ||
| } | ||
|
|
||
| return `${this.encodeUrl(`${this.baseUrl}/pull-requests?create`)}&${query.toString()}`; | ||
| } | ||
|
|
||
| protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.