3636 VERSION = "unknown"
3737
3838FNULL = open (os .devnull , "w" )
39+ FILE_URI_PREFIX = "file://"
3940logger = logging .getLogger (__name__ )
4041
4142
@@ -438,11 +439,8 @@ def get_auth(args, encode=True, for_git_cli=False):
438439 "You must specify both name and account fields for osx keychain password items"
439440 )
440441 elif args .token_fine :
441- _path_specifier = "file://"
442- if args .token_fine .startswith (_path_specifier ):
443- args .token_fine = (
444- open (args .token_fine [len (_path_specifier ) :], "rt" ).readline ().strip ()
445- )
442+ if args .token_fine .startswith (FILE_URI_PREFIX ):
443+ args .token_fine = read_file_contents (args .token_fine )
446444
447445 if args .token_fine .startswith ("github_pat_" ):
448446 auth = args .token_fine
@@ -451,13 +449,8 @@ def get_auth(args, encode=True, for_git_cli=False):
451449 "Fine-grained token supplied does not look like a GitHub PAT"
452450 )
453451 elif args .token_classic :
454- _path_specifier = "file://"
455- if args .token_classic .startswith (_path_specifier ):
456- args .token_classic = (
457- open (args .token_classic [len (_path_specifier ) :], "rt" )
458- .readline ()
459- .strip ()
460- )
452+ if args .token_classic .startswith (FILE_URI_PREFIX ):
453+ args .token_classic = read_file_contents (args .token_classic )
461454
462455 if not args .as_app :
463456 auth = args .token_classic + ":" + "x-oauth-basic"
@@ -504,6 +497,10 @@ def get_github_host(args):
504497 return host
505498
506499
500+ def read_file_contents (file_uri ):
501+ result = open (file_uri [len (FILE_URI_PREFIX ) :], "rt" ).readline ().strip ()
502+
503+
507504def get_github_repo_url (args , repository ):
508505 if repository .get ("is_gist" ):
509506 if args .prefer_ssh :
@@ -525,20 +522,12 @@ def get_github_repo_url(args, repository):
525522
526523 auth = get_auth (args , encode = False , for_git_cli = True )
527524 if auth :
528- if args .token_fine is None :
529- repo_url = "https://{0}@{1}/{2}/{3}.git" .format (
530- auth ,
531- get_github_host (args ),
532- repository ["owner" ]["login" ],
533- repository ["name" ],
534- )
535- else :
536- repo_url = "https://{0}@{1}/{2}/{3}.git" .format (
537- "oauth2:" + auth ,
538- get_github_host (args ),
539- repository ["owner" ]["login" ],
540- repository ["name" ],
541- )
525+ repo_url = "https://{0}@{1}/{2}/{3}.git" .format (
526+ auth if args .token_fine is None else "oauth2:" + auth ,
527+ get_github_host (args ),
528+ repository ["owner" ]["login" ],
529+ repository ["name" ],
530+ )
542531 else :
543532 repo_url = repository ["clone_url" ]
544533
0 commit comments