Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #105 #106

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: #105
  • Loading branch information
yihong0618 committed Apr 19, 2021
commit a76cca749574b788284387052eff420ed5ccb398
15 changes: 10 additions & 5 deletions hub-mirror/hub.py
Original file line number Diff line number Diff line change
@@ -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'