@@ -21,7 +21,11 @@ import { showAndLogInformationMessage, tmpDir } from "./helpers";
2121import { reportStreamProgress , ProgressCallback } from "./commandRunner" ;
2222import { extLogger } from "./common" ;
2323import { Credentials } from "./authentication" ;
24- import { REPO_REGEX , getErrorMessage } from "./pure/helpers-pure" ;
24+ import { getErrorMessage } from "./pure/helpers-pure" ;
25+ import {
26+ convertGitHubUrlToNwo ,
27+ looksLikeGithubRepo ,
28+ } from "./databases/github-nwo" ;
2529
2630/**
2731 * Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
@@ -509,55 +513,6 @@ export async function findDirWithFile(
509513 return ;
510514}
511515
512- /**
513- * The URL pattern is https://github.com/{owner}/{name}/{subpages}.
514- *
515- * This function accepts any URL that matches the pattern above. It also accepts just the
516- * name with owner (NWO): `<owner>/<repo>`.
517- *
518- * @param githubRepo The GitHub repository URL or NWO
519- *
520- * @return true if this looks like a valid GitHub repository URL or NWO
521- */
522- export function looksLikeGithubRepo (
523- githubRepo : string | undefined ,
524- ) : githubRepo is string {
525- if ( ! githubRepo ) {
526- return false ;
527- }
528- if ( REPO_REGEX . test ( githubRepo ) || convertGitHubUrlToNwo ( githubRepo ) ) {
529- return true ;
530- }
531- return false ;
532- }
533-
534- /**
535- * Converts a GitHub repository URL to the corresponding NWO.
536- * @param githubUrl The GitHub repository URL
537- * @return The corresponding NWO, or undefined if the URL is not valid
538- */
539- function convertGitHubUrlToNwo ( githubUrl : string ) : string | undefined {
540- try {
541- const uri = Uri . parse ( githubUrl , true ) ;
542- if ( uri . scheme !== "https" ) {
543- return ;
544- }
545- if ( uri . authority !== "github.com" && uri . authority !== "www.github.com" ) {
546- return ;
547- }
548- const paths = uri . path . split ( "/" ) . filter ( ( segment : string ) => segment ) ;
549- const nwo = `${ paths [ 0 ] } /${ paths [ 1 ] } ` ;
550- if ( REPO_REGEX . test ( nwo ) ) {
551- return nwo ;
552- }
553- return ;
554- } catch ( e ) {
555- // Ignore the error here, since we catch failures at a higher level.
556- // In particular: returning undefined leads to an error in 'promptImportGithubDatabase'.
557- return ;
558- }
559- }
560-
561516export async function convertGithubNwoToDatabaseUrl (
562517 githubRepo : string ,
563518 octokit : Octokit . Octokit ,
0 commit comments