From 696f8c4839e359c1f4b14edcf8e6410772391635 Mon Sep 17 00:00:00 2001 From: Ildar Valiullin Date: Mon, 28 Feb 2022 03:31:46 +0300 Subject: [PATCH] fixed gh token auth flow Signed-off-by: Ildar Valiullin --- github_backup/github_backup.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 59fd19f..a2d99ad 100755 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -10,6 +10,7 @@ Created: Fri Jun 15 2012 import os +import re import errno import codecs import json @@ -337,7 +338,15 @@ class RepositoryBackup(object): elif args.type == 'git': url = repo.git_url elif args.type == 'http' or not IS_AUTHORIZED: - url = repo.clone_url + if re.match('^ghp_.+$', args.login_or_token): + url = re.sub('^https://', f'https://{args.login_or_token}:x-auth-basic@', repo.clone_url) + elif args.password: + if args.username: + url = re.sub('^https://', f'https://{args.username}:{args.password}@', repo.clone_url) + else: + url = re.sub('^https://', f'https://{args.login_or_token}:{args.password}@', repo.clone_url) + else: + url = repo.clone_url self.url = url self.wiki_url = None