From a76cca749574b788284387052eff420ed5ccb398 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Mon, 19 Apr 2021 15:19:01 +0800 Subject: [PATCH 1/2] feat: #105 --- hub-mirror/hub.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hub-mirror/hub.py b/hub-mirror/hub.py index c58b54c6..1cf632ac 100644 --- a/hub-mirror/hub.py +++ b/hub-mirror/hub.py @@ -15,6 +15,7 @@ def __init__( self.dst_type, self.dst_account = dst.split('/') self.dst_token = dst_token self.session = requests.Session() + self.all_dst_repo_list = [] if self.dst_type == "gitee": self.dst_base = 'https://gitee.com/api/v5' elif self.dst_type == "github": @@ -32,16 +33,20 @@ def __init__( # TODO: toekn push support prefix = "git@" + self.dst_type + ".com:" self.dst_repo_base = prefix + self.dst_account - - def has_dst_repo(self, repo_name): + + def make_dst_repo_list(self): url = '/'.join( [self.dst_base, self.account_type+'s', self.dst_account, 'repos'] ) - repo_names = self._get_all_repo_names(url) - if not repo_names: + return self._get_all_repo_names(url) + + def has_dst_repo(self, repo_name): + if not self.all_dst_repo_list: + self.all_dst_repo_list = self.make_dst_repo_list() + if not self.all_dst_repo_list: print("Warning: destination repos is []") return False - return repo_name in repo_names + return repo_name in self.all_dst_repo_list def create_dst_repo(self, repo_name): suffix = 'user/repos' From 62b228ca90b587cac39271a31de7427b89b8619c Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Mon, 19 Apr 2021 15:23:16 +0800 Subject: [PATCH 2/2] fix: lint --- hub-mirror/hub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hub-mirror/hub.py b/hub-mirror/hub.py index 1cf632ac..7cbc7100 100644 --- a/hub-mirror/hub.py +++ b/hub-mirror/hub.py @@ -33,7 +33,7 @@ def __init__( # TODO: toekn push support prefix = "git@" + self.dst_type + ".com:" self.dst_repo_base = prefix + self.dst_account - + def make_dst_repo_list(self): url = '/'.join( [self.dst_base, self.account_type+'s', self.dst_account, 'repos']