@@ -29,7 +29,7 @@ import { GHPRComment, GHPRCommentThread, TemporaryComment } from './github/prCom
2929import { PullRequestModel } from './github/pullRequestModel' ;
3030import { PullRequestOverviewPanel } from './github/pullRequestOverview' ;
3131import { RepositoriesManager } from './github/repositoriesManager' ;
32- import { getIssuesUrl , getPullsUrl , isInCodespaces , vscodeDevPrLink } from './github/utils' ;
32+ import { getIssuesUrl , getPullsUrl , isInCodespaces , ISSUE_OR_URL_EXPRESSION , parseIssueExpressionOutput , vscodeDevPrLink } from './github/utils' ;
3333import { isNotificationTreeItem , NotificationTreeItem } from './notifications/notificationItem' ;
3434import { PullRequestsTreeDataProvider } from './view/prsTreeDataProvider' ;
3535import { ReviewCommentController } from './view/reviewCommentController' ;
@@ -1456,6 +1456,31 @@ ${contents}
14561456 }
14571457 } ) ) ;
14581458
1459+ function validateAndParseInput ( input : string , expectedOwner : string , expectedRepo : string ) : { isValid : true ; prNumber : number ; errorMessage ?: string } | { isValid : false ; prNumber ?: number ; errorMessage : string } {
1460+ const prNumberMatcher = / ^ # ? ( \d * ) $ / ;
1461+ const numberMatches = input . match ( prNumberMatcher ) ;
1462+ if ( numberMatches && ( numberMatches . length === 2 ) && ! Number . isNaN ( Number ( numberMatches [ 1 ] ) ) ) {
1463+ const num = Number ( numberMatches [ 1 ] ) ;
1464+ if ( num > 0 ) {
1465+ return { isValid : true , prNumber : num } ;
1466+ }
1467+ }
1468+
1469+ const urlMatches = input . match ( ISSUE_OR_URL_EXPRESSION ) ;
1470+ const parsed = parseIssueExpressionOutput ( urlMatches ) ;
1471+ if ( parsed && parsed . issueNumber && parsed . issueNumber > 0 ) {
1472+ // Check if the repository owner and name match
1473+ if ( parsed . owner && parsed . name ) {
1474+ if ( parsed . owner !== expectedOwner || parsed . name !== expectedRepo ) {
1475+ return { isValid : false , errorMessage : vscode . l10n . t ( 'Repository in URL does not match the selected repository' ) } ;
1476+ }
1477+ }
1478+ return { isValid : true , prNumber : parsed . issueNumber } ;
1479+ }
1480+
1481+ return { isValid : false , errorMessage : vscode . l10n . t ( 'Value must be a pull request number or GitHub URL' ) } ;
1482+ }
1483+
14591484 context . subscriptions . push (
14601485 vscode . commands . registerCommand ( 'pr.checkoutByNumber' , async ( ) => {
14611486
@@ -1473,21 +1498,24 @@ ${contents}
14731498 if ( ! githubRepo ) {
14741499 return ;
14751500 }
1476- const prNumberMatcher = / ^ # ? ( \d * ) $ / ;
14771501 const prNumber = await vscode . window . showInputBox ( {
1478- ignoreFocusOut : true , prompt : vscode . l10n . t ( 'Enter the pull request number' ) ,
1502+ ignoreFocusOut : true , prompt : vscode . l10n . t ( 'Enter the pull request number or URL ' ) ,
14791503 validateInput : ( input : string ) => {
1480- const matches = input . match ( prNumberMatcher ) ;
1481- if ( ! matches || ( matches . length !== 2 ) || Number . isNaN ( Number ( matches [ 1 ] ) ) ) {
1482- return vscode . l10n . t ( 'Value must be a number' ) ;
1483- }
1484- return undefined ;
1504+ const result = validateAndParseInput ( input , githubRepo . repo . remote . owner , githubRepo . repo . remote . repositoryName ) ;
1505+ return result . isValid ? undefined : result . errorMessage ;
14851506 }
14861507 } ) ;
14871508 if ( ( prNumber === undefined ) || prNumber === '#' ) {
14881509 return ;
14891510 }
1490- const prModel = await githubRepo . manager . fetchById ( githubRepo . repo , Number ( prNumber . match ( prNumberMatcher ) ! [ 1 ] ) ) ;
1511+
1512+ // Extract PR number from input (either direct number or URL)
1513+ const parseResult = validateAndParseInput ( prNumber , githubRepo . repo . remote . owner , githubRepo . repo . remote . repositoryName ) ;
1514+ if ( ! parseResult . isValid ) {
1515+ return vscode . window . showErrorMessage ( parseResult . errorMessage || vscode . l10n . t ( 'Invalid pull request number or URL' ) ) ;
1516+ }
1517+
1518+ const prModel = await githubRepo . manager . fetchById ( githubRepo . repo , parseResult . prNumber ) ;
14911519 if ( prModel ) {
14921520 return ReviewManager . getReviewManagerForFolderManager ( reviewsManager . reviewManagers , githubRepo . manager ) ?. switch ( prModel ) ;
14931521 }
0 commit comments