@@ -10,15 +10,15 @@ import gql from 'graphql-tag';
10
10
import * as vscode from 'vscode' ;
11
11
import { Repository } from '../api/api' ;
12
12
import { COPILOT_ACCOUNTS , DiffSide , IComment , IReviewThread , SubjectType , ViewedState } from '../common/comment' ;
13
- import { getModifiedContentFromDiffHunk , parseDiff } from '../common/diffHunk' ;
13
+ import { getGitChangeType , getModifiedContentFromDiffHunk , parseDiff } from '../common/diffHunk' ;
14
14
import { commands } from '../common/executeCommands' ;
15
15
import { GitChangeType , InMemFileChange , SlimFileChange } from '../common/file' ;
16
16
import { GitHubRef } from '../common/githubRef' ;
17
17
import Logger from '../common/logger' ;
18
18
import { Remote } from '../common/remote' ;
19
19
import { ITelemetry } from '../common/telemetry' ;
20
20
import { ClosedEvent , EventType , ReviewEvent , TimelineEvent } from '../common/timelineEvent' ;
21
- import { resolvePath , reviewPath , Schemes , toPRUri , toReviewUri } from '../common/uri' ;
21
+ import { resolvePath , Schemes , toGitHubCommitUri , toPRUri , toReviewUri } from '../common/uri' ;
22
22
import { formatError , isDescendant } from '../common/utils' ;
23
23
import { InMemFileChangeModel , RemoteFileChangeModel } from '../view/fileChangeModel' ;
24
24
import { OctokitCommon } from './common' ;
@@ -1111,6 +1111,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
1111
1111
pullRequestId : this . graphNodeId ,
1112
1112
teamIds : teamReviewers . map ( t => t . id ) ,
1113
1113
userIds : reviewers . filter ( r => r . accountType !== AccountType . Bot ) . map ( r => r . id ) ,
1114
+ botIds : reviewers . filter ( r => r . accountType === AccountType . Bot ) . map ( r => r . id ) ,
1114
1115
union
1115
1116
} ,
1116
1117
} ,
@@ -1332,47 +1333,32 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
1332
1333
return vscode . commands . executeCommand ( 'vscode.changes' , vscode . l10n . t ( 'Changes in Pull Request #{0}' , pullRequestModel . number ) , args ) ;
1333
1334
}
1334
1335
1335
- static async openCommitChanges ( folderManager : FolderRepositoryManager , commitSha : string ) {
1336
+ static async openCommitChanges ( githubRepository : GitHubRepository , commitSha : string ) {
1336
1337
try {
1337
- // Get the repository from the folder manager
1338
- const repository = folderManager . repository ;
1339
- if ( ! repository ) {
1340
- vscode . window . showErrorMessage ( vscode . l10n . t ( 'No repository found' ) ) ;
1341
- return ;
1342
- }
1343
-
1344
- // Get the commit to find its parent
1345
- const commit = await repository . getCommit ( commitSha ) ;
1346
- if ( ! commit . parents || commit . parents . length === 0 ) {
1338
+ const parentCommit = await githubRepository . getCommitParent ( commitSha ) ;
1339
+ if ( ! parentCommit ) {
1347
1340
vscode . window . showErrorMessage ( vscode . l10n . t ( 'Commit {0} has no parent' , commitSha . substring ( 0 , 7 ) ) ) ;
1348
1341
return ;
1349
1342
}
1350
- const parentSha = commit . parents [ 0 ] ;
1351
1343
1352
- // Get the changes between the commit and its parent
1353
- const changes = await repository . diffBetween ( parentSha , commitSha ) ;
1354
- if ( ! changes || changes . length === 0 ) {
1344
+ const changes = await githubRepository . compareCommits ( parentCommit , commitSha ) ;
1345
+ if ( ! changes ?. files || changes . files . length === 0 ) {
1355
1346
vscode . window . showInformationMessage ( vscode . l10n . t ( 'No changes found in commit {0}' , commitSha . substring ( 0 , 7 ) ) ) ;
1356
1347
return ;
1357
1348
}
1358
1349
1359
1350
// Create URI pairs for the multi diff editor using review scheme
1360
1351
const args : [ vscode . Uri , vscode . Uri | undefined , vscode . Uri | undefined ] [ ] = [ ] ;
1361
- for ( const change of changes ) {
1362
- const rightRelativePath = path . relative ( repository . rootUri . fsPath , change . uri . fsPath ) ;
1363
- const rightPath = reviewPath ( rightRelativePath , commitSha ) ;
1364
- let rightUri = toReviewUri ( rightPath , rightRelativePath , undefined , commitSha , false , { base : false } , repository . rootUri ) ;
1365
-
1366
- const leftRelativePath = path . relative ( repository . rootUri . fsPath , change . originalUri . fsPath ) ;
1367
- const leftPath = reviewPath ( leftRelativePath , parentSha ) ;
1368
- let leftUri = toReviewUri ( leftPath , ( change . status === GitChangeType . RENAME ) ? path . relative ( repository . rootUri . fsPath , change . originalUri . fsPath ) : leftRelativePath , undefined , parentSha , false , { base : true } , repository . rootUri ) ;
1369
-
1370
- if ( change . status === GitChangeType . ADD ) {
1352
+ for ( const change of changes . files ) {
1353
+ const rightUri = toGitHubCommitUri ( change . filename , { commit : commitSha , owner : githubRepository . remote . owner , repo : githubRepository . remote . repositoryName } ) ;
1354
+ const leftUri = toGitHubCommitUri ( change . previous_filename ?? change . filename , { commit : parentCommit , owner : githubRepository . remote . owner , repo : githubRepository . remote . repositoryName } ) ;
1355
+ const changeType = getGitChangeType ( change . status ) ;
1356
+ if ( changeType === GitChangeType . ADD ) {
1371
1357
// For added files, show against empty
1372
1358
args . push ( [ rightUri , undefined , rightUri ] ) ;
1373
- } else if ( change . status === GitChangeType . DELETE ) {
1359
+ } else if ( changeType === GitChangeType . DELETE ) {
1374
1360
// For deleted files, show old version against empty
1375
- args . push ( [ rightPath , leftUri , undefined ] ) ;
1361
+ args . push ( [ rightUri , leftUri , undefined ] ) ;
1376
1362
} else {
1377
1363
args . push ( [ rightUri , leftUri , rightUri ] ) ;
1378
1364
}
@@ -1381,7 +1367,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
1381
1367
/* __GDPR__
1382
1368
"pr.openCommitChanges" : {}
1383
1369
*/
1384
- folderManager . telemetry . sendTelemetryEvent ( 'pr.openCommitChanges' ) ;
1370
+ githubRepository . telemetry . sendTelemetryEvent ( 'pr.openCommitChanges' ) ;
1385
1371
1386
1372
return commands . executeCommand ( 'vscode.changes' , vscode . l10n . t ( 'Changes in Commit {0}' , commitSha . substring ( 0 , 7 ) ) , args ) ;
1387
1373
} catch ( error ) {
@@ -2095,3 +2081,18 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
2095
2081
} ;
2096
2082
}
2097
2083
}
2084
+
2085
+ export async function isCopilotOnMyBehalf ( pullRequestModel : PullRequestModel , currentUser : IAccount , coAuthors ?: IAccount [ ] ) : Promise < boolean > {
2086
+ if ( ! COPILOT_ACCOUNTS [ pullRequestModel . author . login ] ) {
2087
+ return false ;
2088
+ }
2089
+
2090
+ if ( ! coAuthors ) {
2091
+ coAuthors = await pullRequestModel . getCoAuthors ( ) ;
2092
+ }
2093
+ if ( ! coAuthors || coAuthors . length === 0 ) {
2094
+ return false ;
2095
+ }
2096
+
2097
+ return coAuthors . some ( c => c . login === currentUser . login ) ;
2098
+ }
0 commit comments