@@ -28,8 +28,7 @@ import { PullRequestModel } from './github/pullRequestModel';
2828import { resolveCommentHandler , CommentReply } from './commentHandlerResolver' ;
2929import { ITelemetry } from './common/telemetry' ;
3030import { 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
3433const _onDidUpdatePR = new vscode . EventEmitter < PullRequest | void > ( ) ;
3534export 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 - z 0 - 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- }
0 commit comments