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
107 lines (89 loc) · 3.71 KB
/
Copy pathextension.ts
File metadata and controls
107 lines (89 loc) · 3.71 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
99
100
101
102
103
104
105
106
107
/*---------------------------------------------------------------------------------------------
* 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 { 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 { formatError, onceEvent } from './common/utils';
import { GitExtension, API as GitAPI, Repository } from './typings/git';
import { Telemetry } from './common/telemetry';
import { handler as uriHandler } from './common/uri';
import { ITelemetry } from './github/interface';
import { NewPRPanel } from './view/newPRPanel';
import { Store } from './store';
// 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> {
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());
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
const prManager = new PullRequestManager(configuration, repository, telemetry);
const reviewManager = new ReviewManager(context, configuration, repository, prManager, telemetry);
registerCommands(context, prManager, reviewManager, telemetry);
/**
* Since selection changes are per repository, selecting a different repo will trigger two
* selection change events, one for the repository losing selection and one for the repository gaining selection.
* Try to debounce these so that only one update is done.
*/
let updateRepositoryTimer;
git.repositories.forEach(repo => {
(<any>repo).ui.onDidChange(_ => {
if (updateRepositoryTimer) {
clearTimeout(updateRepositoryTimer);
}
updateRepositoryTimer = setTimeout(() => {
// no multi select support yet, always show PRs of first selected repository
const firstSelectedRepository = git.repositories.filter(r => r.ui.selected)[0];
if (firstSelectedRepository) {
prManager.repository = firstSelectedRepository;
reviewManager.repository = firstSelectedRepository;
}
}, 50);
});
});
Store.init(prManager, vscode, context.subscriptions);
NewPRPanel.init(context.extensionPath);
telemetry.on('startup');
}
export async function activate(context: vscode.ExtensionContext) {
// initialize resources
Resource.initialize(context);
telemetry = new Telemetry(context);
const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git').exports;
const git = gitExtension.getAPI(1);
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();
}
}