Skip to content

Commit 13a5d48

Browse files
joaomorenoRMacfarlane
authored andcommitted
remove core github functionality (#1817)
1 parent 9eec469 commit 13a5d48

3 files changed

Lines changed: 4 additions & 152 deletions

File tree

package.json

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": "0.16.0",
1616
"publisher": "GitHub",
1717
"engines": {
18-
"vscode": "^1.45.0"
18+
"vscode": "^1.46.0"
1919
},
2020
"categories": [
2121
"Other"
@@ -701,10 +701,6 @@
701701
{
702702
"command": "issue.userCompletion",
703703
"title": "User Completion Chosen"
704-
},
705-
{
706-
"command": "github.publish",
707-
"title": "Publish to GitHub"
708704
}
709705
],
710706
"keybindings": [
@@ -1164,14 +1160,7 @@
11641160
"when": "commentController =~ /^(browse|review)/"
11651161
}
11661162
]
1167-
},
1168-
"viewsWelcome": [
1169-
{
1170-
"view": "scm",
1171-
"contents": "You can also directly publish this folder to a GitHub repository.\n[$(github) Publish to GitHub](command:github.publish)",
1172-
"when": "config.git.enabled && !git.missing && workbenchState == folder"
1173-
}
1174-
]
1163+
}
11751164
},
11761165
"scripts": {
11771166
"vscode:prepublish": "webpack --env.production",

src/commands.ts

Lines changed: 1 addition & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import { PullRequestModel } from './github/pullRequestModel';
2828
import { resolveCommentHandler, CommentReply } from './commentHandlerResolver';
2929
import { ITelemetry } from './common/telemetry';
3030
import { TreeNode } from './view/treeNodes/treeNode';
31-
import { CredentialStore, GitHub } from './github/credentials';
32-
import { GitAPI } from './typings/git';
31+
import { CredentialStore } from './github/credentials';
3332

3433
const _onDidUpdatePR = new vscode.EventEmitter<PullRequest | void>();
3534
export const onDidUpdatePR: vscode.Event<PullRequest | void> = _onDidUpdatePR.event;
@@ -552,131 +551,3 @@ export function registerCommands(context: vscode.ExtensionContext, prManager: Pu
552551
}
553552
}));
554553
}
555-
556-
function sanitizeRepositoryName(value: string): string {
557-
return value.trim().replace(/[^a-z0-9_.]/ig, '-');
558-
}
559-
560-
export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI: GitAPI, credentialStore: CredentialStore) {
561-
async function getHub(): Promise<GitHub | undefined> {
562-
if (await credentialStore.hasOctokit()) {
563-
return await credentialStore.getHub()!;
564-
} else {
565-
return await credentialStore.login();
566-
}
567-
}
568-
569-
async function publish(): Promise<void> {
570-
if (!vscode.workspace.workspaceFolders?.length) {
571-
return;
572-
}
573-
574-
const folder = vscode.workspace.workspaceFolders[0]; // TODO
575-
const hub = await getHub();
576-
577-
if (!hub) {
578-
return;
579-
}
580-
581-
const owner = hub.octokit.currentUser!.login;
582-
583-
const quickpick = vscode.window.createQuickPick<vscode.QuickPickItem & { repo?: string, auth?: 'https' | 'ssh' }>();
584-
quickpick.ignoreFocusOut = true;
585-
586-
quickpick.placeholder = 'Repository Name';
587-
quickpick.show();
588-
589-
let repo: string | undefined;
590-
591-
const onDidChangeValue = async () => {
592-
const sanitizedRepo = sanitizeRepositoryName(quickpick.value);
593-
594-
if (!sanitizedRepo) {
595-
quickpick.items = [];
596-
} else {
597-
quickpick.items = [{ label: `$(repo) Create private repository`, description: `$(github) ${owner}/${sanitizedRepo}`, alwaysShow: true, repo: sanitizedRepo }];
598-
}
599-
};
600-
601-
quickpick.value = folder.name;
602-
onDidChangeValue();
603-
604-
while (true) {
605-
const listener = quickpick.onDidChangeValue(onDidChangeValue);
606-
const pick = await getPick(quickpick);
607-
listener.dispose();
608-
609-
repo = pick?.repo;
610-
611-
if (repo) {
612-
try {
613-
quickpick.busy = true;
614-
await hub.octokit.repos.get({ owner, repo: repo });
615-
quickpick.items = [{ label: `$(error) Repository already exists`, description: `$(github) ${owner}/${repo}`, alwaysShow: true }];
616-
} catch {
617-
break;
618-
} finally {
619-
quickpick.busy = false;
620-
}
621-
}
622-
}
623-
624-
quickpick.dispose();
625-
626-
if (!repo) {
627-
return;
628-
}
629-
630-
const githubRepository = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, cancellable: false, title: 'Publish to GitHub' }, async progress => {
631-
progress.report({ message: 'Creating private repository in GitHub', increment: 25 });
632-
633-
const res = await hub.octokit.repos.createForAuthenticatedUser({
634-
name: repo!,
635-
private: true
636-
});
637-
638-
const createdGithubRepository = res.data;
639-
640-
progress.report({ message: 'Creating first commit', increment: 25 });
641-
const repository = await gitAPI.init(folder.uri);
642-
643-
if (!repository) {
644-
return;
645-
}
646-
647-
await repository.commit('first commit', { all: true });
648-
649-
progress.report({ message: 'Uploading files', increment: 25 });
650-
await repository.addRemote('origin', createdGithubRepository.clone_url);
651-
await repository.push('origin', 'master', true);
652-
653-
return createdGithubRepository;
654-
});
655-
656-
if (!githubRepository) {
657-
return;
658-
}
659-
660-
const openInGitHub = 'Open In GitHub';
661-
const action = await vscode.window.showInformationMessage(`Successfully published the '${owner}/${repo}' repository on GitHub.`, openInGitHub);
662-
663-
if (action === openInGitHub) {
664-
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(githubRepository.html_url));
665-
}
666-
}
667-
668-
context.subscriptions.push(vscode.commands.registerCommand('github.publish', async () => {
669-
try {
670-
publish();
671-
} catch (err) {
672-
vscode.window.showErrorMessage(err.message);
673-
}
674-
}));
675-
}
676-
677-
function getPick<T extends vscode.QuickPickItem>(quickpick: vscode.QuickPick<T>): Promise<T | undefined> {
678-
return Promise.race<T | undefined>([
679-
new Promise<T>(c => quickpick.onDidAccept(() => quickpick.selectedItems.length > 0 && c(quickpick.selectedItems[0]))),
680-
new Promise<undefined>(c => quickpick.onDidHide(() => c(undefined)))
681-
]);
682-
}

src/extension.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
88
import TelemetryReporter from 'vscode-extension-telemetry';
99
import { Repository } from './api/api';
1010
import { ApiImpl } from './api/api1';
11-
import { registerCommands, registerGlobalCommands } from './commands';
11+
import { registerCommands } from './commands';
1212
import Logger from './common/logger';
1313
import { Resource } from './common/resources';
1414
import { handler as uriHandler } from './common/uri';
@@ -22,7 +22,6 @@ import { PullRequestsTreeDataProvider } from './view/prsTreeDataProvider';
2222
import { ReviewManager } from './view/reviewManager';
2323
import { IssueFeatureRegistrar } from './issues/issueFeatureRegistrar';
2424
import { CredentialStore } from './github/credentials';
25-
import { GithubRemoteSourceProvider } from './gitExtensionIntegration';
2625
import { GitExtension, GitAPI } from './typings/git';
2726
import { GitHubContactServiceProvider } from './gitProviders/GitHubContactServiceProvider';
2827
import { LiveShare } from 'vsls/vscode.js';
@@ -116,19 +115,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<ApiImp
116115
const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports;
117116
const gitAPI = gitExtension.getAPI(1);
118117

119-
// let's not break compatibility
120-
if (gitAPI.registerRemoteSourceProvider) {
121-
const remoteSourceProvider = new GithubRemoteSourceProvider(credentialStore);
122-
context.subscriptions.push(gitAPI.registerRemoteSourceProvider(remoteSourceProvider));
123-
}
124-
125118
context.subscriptions.push(registerBuiltinGitProvider(apiImpl));
126119
const liveshareGitProvider = registerLiveShareGitProvider(apiImpl);
127120
context.subscriptions.push(liveshareGitProvider);
128121
const liveshareApiPromise = liveshareGitProvider.initialize();
129122

130123
context.subscriptions.push(apiImpl);
131-
registerGlobalCommands(context, gitAPI, credentialStore);
132124

133125
Logger.appendLine('Looking for git repository');
134126

0 commit comments

Comments
 (0)