使用git API时遇到错误
from git import Repo
from github import Github
Connecting to git.xxxxx.com (port 9418) ... fatal: unable to connect to git.xxxxx.com:
git.xxxxx.com[0: 141.113.0.105]: errno=Connection refused
我可以通过命令从Enterprise github克隆代码
git clone https://[name]:[token]@git.git.xxxx.com/xxx.git
但是我混淆了git API中的克隆方式
def walk_githubprojects(token, organization):
client = Github(base_url='https://git.xxx.com/api/v3', login_or_token=token)
user=client.get_user().get_repos()
for repo in client.get_organization(organization).get_repos():
print(repo.name)
print(repo.git_url)
Repo.clone_from(repo.git_url, 'my_path')
我可以在组织下获取回购名称,脚本应将回购克隆到我的本地目录中
答案 0 :(得分:0)
解决方法是:
from git import Repo
from github import Github
def walk_githubprojects(token, organization):
client = Github(base_url='https://git.xxxxx.com/api/v3', login_or_token=token)
user=client.get_user().get_repos()
for repo in client.get_organization(organization).get_repos():
HTTPS_REMOTE_URL = f'https://[name]:[token]@git.xxxxx.com/{repo.full_name}'
Repo.clone_from(HTTPS_REMOTE_URL, f'/xxxx/{repo.name}')