-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Search for GitLab PRs in Launchpad #3795
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
11 commits
Select commit
Hold shift + click to select a range
d15069a
Updates changelog by adding a note about GitLab PR search in Launchpad
sergeibbb 8ace646
Parse GitLab merge request URLs to identify those in Launchpad
sergeibbb e4dc9fc
Enhances PR search with multiple integrations instead of only GitHub
sergeibbb 3474f1b
Implements pull request search by its URL on GitLab
sergeibbb c73f0e8
Makes by URL or ID searched GitLab PRs checkoutable
sergeibbb 7863d5d
Implements pull request search to GitLab integration using GitLab's API
sergeibbb b2dae60
Performs specific PR URL match for each connected provider
sergeibbb 84c6259
Reuses connected integrations by passing to getPullRequestIdentity...
sergeibbb 42bf820
Fixes API result transformation
sergeibbb 04dad7a
Handles hostless avatar URLs coming from GraphQL
sergeibbb 7240a33
Unifies handling of pull request URL identities
sergeibbb 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
87 changes: 87 additions & 0 deletions
87
src/plus/integrations/providers/github/__tests__/github.utils.test.ts
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as assert from 'assert'; | ||
import { suite, test } from 'mocha'; | ||
//import { getGitHubPullRequestIdentityFromMaybeUrl } from '../github/models'; | ||
import { getGitHubPullRequestIdentityFromMaybeUrl, isMaybeGitHubPullRequestUrl } from '../github.utils'; | ||
|
||
suite('Test GitHub PR URL parsing to identity: getPullRequestIdentityFromMaybeUrl()', () => { | ||
function t(message: string, query: string, prNumber: string | undefined, ownerAndRepo?: string) { | ||
assert.deepStrictEqual( | ||
getGitHubPullRequestIdentityFromMaybeUrl(query), | ||
prNumber == null | ||
? undefined | ||
: { | ||
ownerAndRepo: ownerAndRepo, | ||
prNumber: prNumber, | ||
provider: 'github', | ||
}, | ||
`Parse: ${message} (${JSON.stringify(query)})`, | ||
); | ||
assert.equal( | ||
isMaybeGitHubPullRequestUrl(query), | ||
prNumber != null, | ||
`Check: ${message} (${JSON.stringify(query)})`, | ||
); | ||
} | ||
|
||
test('full URL or without protocol but with domain, should parse to ownerAndRepo and prNumber', () => { | ||
t('full URL', 'https://github.com/eamodio/vscode-gitlens/pull/1', '1', 'eamodio/vscode-gitlens'); | ||
t( | ||
'with suffix', | ||
'https://github.com/eamodio/vscode-gitlens/pull/1/files?diff=unified#hello', | ||
'1', | ||
'eamodio/vscode-gitlens', | ||
); | ||
t( | ||
'with query', | ||
'https://github.com/eamodio/vscode-gitlens/pull/1?diff=unified#hello', | ||
'1', | ||
'eamodio/vscode-gitlens', | ||
); | ||
|
||
t('with anchor', 'https://github.com/eamodio/vscode-gitlens/pull/1#hello', '1', 'eamodio/vscode-gitlens'); | ||
t('a weird suffix', 'https://github.com/eamodio/vscode-gitlens/pull/1-files', '1', 'eamodio/vscode-gitlens'); | ||
t('numeric repo name', 'https://github.com/sergeibbb/1/pull/16', '16', 'sergeibbb/1'); | ||
|
||
t('no protocol with leading slash', '/github.com/sergeibbb/1/pull/16?diff=unified', '16', 'sergeibbb/1'); | ||
t('no protocol without leading slash', 'github.com/sergeibbb/1/pull/16/files', '16', 'sergeibbb/1'); | ||
}); | ||
|
||
test('no domain, should parse to ownerAndRepo and prNumber', () => { | ||
t('with leading slash', '/sergeibbb/1/pull/16#hello', '16', 'sergeibbb/1'); | ||
t('words in repo name', 'eamodio/vscode-gitlens/pull/1?diff=unified#hello', '1', 'eamodio/vscode-gitlens'); | ||
t('numeric repo name', 'sergeibbb/1/pull/16/files', '16', 'sergeibbb/1'); | ||
}); | ||
|
||
test('domain vs. no domain', () => { | ||
t( | ||
'with anchor', | ||
'https://github.com/eamodio/vscode-gitlens/pull/1#hello/sergeibbb/1/pull/16', | ||
'1', | ||
'eamodio/vscode-gitlens', | ||
); | ||
}); | ||
|
||
test('numbers', () => { | ||
t('has "pull/" fragment', '/pull/16/files#hello', '16'); | ||
t('has "pull/" fragment with double slash', '1//pull/16?diff=unified#hello', '16'); | ||
t('with leading slash', '/16/files#hello', undefined); | ||
t('just a number', '16', undefined); | ||
t('with a hash', '#16', undefined); | ||
}); | ||
|
||
test('does not match', () => { | ||
t('without leading slash', '16?diff=unified#hello', undefined); | ||
t('with leading hash', '/#16/files#hello', undefined); | ||
t('number is a part of a word', 'hello16', undefined); | ||
t('number is a part of a word', '16hello', undefined); | ||
|
||
t('GitLab', 'https://gitlab.com/eamodio/vscode-gitlens/-/merge_requests/16', undefined); | ||
|
||
t('with a number', '1/16?diff=unified#hello', undefined); | ||
t('with a number and slash', '/1/16?diff=unified#hello', undefined); | ||
t('with a word', 'anything/16?diff=unified#hello', undefined); | ||
|
||
t('with a wrong character leading to pull', 'sergeibbb/1/-pull/16?diff=unified#hello', undefined); | ||
t('with a wrong character leading to pull', 'sergeibbb/1-pull/16?diff=unified#hello', 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// GitHub provider: github.ts pulls many dependencies through Container and some of them break the unit tests. | ||
// That's why this file has been created that can collect more simple functions which | ||
// don't require Container and can be tested. | ||
|
||
import { HostingIntegrationId } from '../../../../constants.integrations'; | ||
import type { PullRequestUrlIdentity } from '../../../../git/models/pullRequest.utils'; | ||
|
||
export function isMaybeGitHubPullRequestUrl(url: string): boolean { | ||
if (url == null) return false; | ||
|
||
return getGitHubPullRequestIdentityFromMaybeUrl(url) != null; | ||
} | ||
|
||
export function getGitHubPullRequestIdentityFromMaybeUrl( | ||
search: string, | ||
): (PullRequestUrlIdentity & { provider: HostingIntegrationId.GitHub }) | undefined { | ||
let ownerAndRepo: string | undefined = undefined; | ||
let prNumber: string | undefined = undefined; | ||
|
||
let match = search.match(/([^/]+\/[^/]+)\/(?:pull)\/(\d+)/); // with org and rep name | ||
if (match != null) { | ||
ownerAndRepo = match[1]; | ||
prNumber = match[2]; | ||
} | ||
|
||
if (prNumber == null) { | ||
match = search.match(/(?:\/|^)(?:pull)\/(\d+)/); // without repo name | ||
if (match != null) { | ||
prNumber = match[1]; | ||
} | ||
} | ||
|
||
return prNumber != null | ||
? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: HostingIntegrationId.GitHub } | ||
: 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
Oops, something went wrong.
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.
This is unnecessary since we return the promise in the next line, similar to other cases. If anything, I would suggest instead that we just combine the two lines to
return this.container.cache.get...
and do the same in other places where this pattern occurs across the file.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.
@axosoft-ramint
I did it because I set a breakpoint at this place it was convenient to see a resolved promise.