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
98 lines (84 loc) · 3.19 KB
/
extension.ts
File metadata and controls
98 lines (84 loc) · 3.19 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*---------------------------------------------------------------------------------------------
* 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 { migrateConfiguration } 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 { formatError, onceEvent } from './common/utils';
import { API as GitAPI, Repository, getAPI } from './git/api';
import { Telemetry } from './common/telemetry';
import { handler as uriHandler } from './common/uri';
import { ITelemetry } from './github/interface';
import * as Keychain from './authentication/keychain';
import { FileTypeDecorationProvider } from './view/fileTypeDecorationProvider';
// fetch.promise polyfill
const fetch = require('node-fetch');
const PolyfillPromise = require('es6-promise').Promise;
fetch.Promise = PolyfillPromise;
let telemetry: ITelemetry;
async function init(context: vscode.ExtensionContext, git: GitAPI, repository: Repository): Promise<void> {
context.subscriptions.push(Logger);
Logger.appendLine('Git repository found, initializing review manager and pr tree view.');
Keychain.init(context);
await migrateConfiguration();
context.subscriptions.push(Keychain.onDidChange(async _ => {
if (prManager) {
try {
await prManager.clearCredentialCache();
if (repository) {
repository.status();
}
} catch (e) {
vscode.window.showErrorMessage(formatError(e));
}
}
}));
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
context.subscriptions.push(new FileTypeDecorationProvider());
const prManager = new PullRequestManager(repository, telemetry);
const reviewManager = new ReviewManager(context, Keychain.onDidChange, repository, prManager, telemetry);
registerCommands(context, prManager, reviewManager, telemetry);
git.repositories.forEach(repo => {
repo.ui.onDidChange(() => {
// No multi-select support, always show last selected repo
if (repo.ui.selected) {
prManager.repository = repo;
reviewManager.repository = repo;
}
});
});
git.onDidOpenRepository(repo => {
repo.ui.onDidChange(() => {
if (repo.ui.selected) {
prManager.repository = repo;
reviewManager.repository = repo;
}
});
});
telemetry.on('startup');
}
export async function activate(context: vscode.ExtensionContext) {
// initialize resources
Resource.initialize(context);
telemetry = new Telemetry(context);
const git = getAPI();
context.subscriptions.push(git);
Logger.appendLine('Looking for git repository');
const firstRepository = git.repositories[0];
if (firstRepository) {
await init(context, git, firstRepository);
} else {
onceEvent(git.onDidOpenRepository)(r => init(context, git, r));
}
}
export async function deactivate() {
if (telemetry) {
await telemetry.shutdown();
}
}