forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubFileContentProvider.ts
More file actions
39 lines (32 loc) · 1.66 KB
/
Copy pathgithubFileContentProvider.ts
File metadata and controls
39 lines (32 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { RepositoryFileSystemProvider } from './repositoryFileSystemProvider';
import { GitApiImpl } from '../api/api1';
import { fromGitHubCommitUri } from '../common/uri';
import { CredentialStore } from '../github/credentials';
import { RepositoriesManager } from '../github/repositoriesManager';
export class GitHubCommitFileSystemProvider extends RepositoryFileSystemProvider {
constructor(private readonly repos: RepositoriesManager, gitAPI: GitApiImpl, credentialStore: CredentialStore) {
super(gitAPI, credentialStore);
}
override async readFile(uri: vscode.Uri): Promise<Uint8Array> {
await this.waitForAuth();
await this.waitForAnyGitHubRepos(this.repos);
const params = fromGitHubCommitUri(uri);
if (!params) {
throw new Error(`Invalid GitHub commit URI: ${uri.toString()}`);
}
const folderManager = this.repos.getManagerForRepository(params.owner, params.repo);
if (!folderManager) {
throw new Error(`Repository not found for owner: ${params.owner}, repo: ${params.repo}`);
}
const githubRepo = await folderManager.createGitHubRepositoryFromOwnerName(params.owner, params.repo);
if (!githubRepo) {
throw new Error(`GitHub repository not found for owner: ${params.owner}, repo: ${params.repo}`);
}
return githubRepo.getFile(uri.path, params.commit);
}
}