forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
78 lines (67 loc) · 2.67 KB
/
Copy pathextension.ts
File metadata and controls
78 lines (67 loc) · 2.67 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import { Repository } from './common/repository';
import { VSCodeConfiguration } from './authentication/vsConfiguration';
import { Resource } from './common/resources';
import { ReviewManager } from './view/reviewManager';
import { registerCommands } from './commands';
import Logger from './common/logger';
import { PullRequestManager } from './github/pullRequestManager';
import { setGitPath } from './common/git';
import { formatError } from './common/utils';
import { Telemetry } from './common/telemetry';
import { ITelemetry } from './github/interface';
// fetch.promise polyfill
const fetch = require('node-fetch');
const PolyfillPromise = require('es6-promise').Promise;
fetch.Promise = PolyfillPromise;
let telemetry: ITelemetry;
export async function activate(context: vscode.ExtensionContext) {
// initialize resources
Resource.initialize(context);
telemetry = new Telemetry(context);
const rootPath = vscode.workspace.rootPath;
let gitExt = vscode.extensions.getExtension('vscode.git');
let importedGitApi = gitExt.exports;
let gitPath = await importedGitApi.getGitPath();
setGitPath(gitPath);
Logger.appendLine('Looking for git repository');
const repository = new Repository(rootPath);
let repositoryInitialized = false;
let prManager: PullRequestManager;
repository.onDidRunGitStatus(async e => {
if (repositoryInitialized) {
return;
}
Logger.appendLine('Git repository found, initializing review manager and pr tree view.');
const configuration = new VSCodeConfiguration();
await configuration.loadConfiguration();
configuration.onDidChange(async _ => {
if (prManager) {
try {
await prManager.clearCredentialCache();
if (repository) {
repository.status();
}
} catch (e) {
vscode.window.showErrorMessage(formatError(e));
}
}
});
context.subscriptions.push(configuration.listenForVSCodeChanges());
repositoryInitialized = true;
prManager = new PullRequestManager(configuration, repository, telemetry);
const reviewManager = new ReviewManager(context, configuration, repository, prManager, telemetry);
registerCommands(context, prManager, reviewManager, telemetry);
telemetry.on('startup');
});
}
export async function deactivate(context: vscode.ExtensionContext) {
if (telemetry) {
await telemetry.shutdown();
}
}