-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
59b2670
Adds support for comparison and create pull request URLs in remote se…
sergeibbb 7824100
Gets provider resource URL asyncronously
sergeibbb 37b442a
Generates create AzureDevOps PR URLs and retrieves repoId for cross-f…
sergeibbb 335e51e
Lets user connect and integration when it is required for a cross-for…
sergeibbb 9ee38b0
Generates create GitLab PR URLs and retrieves repoId for cross-forks
sergeibbb 28a5220
Generates create Bitbucket PR URLs
sergeibbb e53c6fb
Generates create Bitbucket DataCenter PR URLs (without cross-forks)
sergeibbb bf2d1d5
Generates create GitHub PR URLs
sergeibbb 2ccaefa
Adds create pr urls for other providers
eamodio a244941
Updates wording on the cross-repository prompt
axosoft-ramint b2f2ab3
Stops showing an error when user refuses to connect an integration
sergeibbb 27f916a
Updates use of `replace`
axosoft-ramint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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.