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

Refactor #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EditorConfig is awesome: https://EditorConfig.org
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.py]
indent_style = space
indent_size = 4
charset = utf-8

[Makefile]
indent_style = tab

[*.{yml,yaml}]
indent_style = space
indent_size = 2
Empty file added .github/workflows/release.yml
Empty file.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.vscode
*.json
.repos
.idea
__pycache__
ENV
test.py
.venv*
build
dist
*.egg-info
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2021 hsowan <[email protected]>
Copyright (c) 2020 K8sCat and The Gigrator Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version = 1.0.2

install:
python setup.py install

.PHONY: install-requirements
install-requirements:
pip install -r requirements.txt

build-wheel: clean
sed -i 's/{version}/$(version)/g' setup.py
python setup.py sdist bdist_wheel

username = __token__
password =
release-pypi: install-requirements clean build-wheel
python -m twine upload -u $(username) -p $(password) dist/*

clean:
rm -rf build dist gigrator.egg-info

install-wheel:
pip install --force-reinstall dist/gigrator-$(version)-py3-none-any.whl
150 changes: 57 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,87 @@
# Gigrator

[![](https://img.shields.io/badge/GitHub-success)](https://github.com/k8scat/gigrator)
[![](https://img.shields.io/badge/Gitee-red)](https://gitee.com/k8scat/gigrator)
Gigrator 是一个 Git 代码仓批量迁移工具,支持众多流行的代码托管平台,包括 GitHub、码云(Gitee)、GitLab、Gitea、Coding、Gogs、腾讯工蜂,
同时可以基于本项目进行拓展其他代码托管平台。

Git 代码仓批量迁移
如果你在国外 GitHub 上托管了数十上百个代码仓,
现在想要快速地迁移到国内的码云(Gitee)或自建的 Git 代码托管平台(比如 GitLab、Gitea)上的话,
可以使用 [Gigrator](https://github.com/k8scat/gigrator.git) 帮助你快速地迁移这些代码仓。

![gigrator.png](images/gigrator.png)
## 支持的平台

## Start
- [x] [Gitee](https://gitee.com/)
- [x] [GitLab](https://gitlab.com/)
- [x] [GitHub](https://github.com/)
- [x] [Gitea](https://gitea.io/zh-cn/)
- [x] [Coding](https://coding.net/)
- [x] [Gogs](https://gogs.io/)
- [x] [腾讯工蜂](https://code.tencent.com/)
- [ ] [Bitbucket](https://bitbucket.org/)
- [ ] [云效 Codeup](https://codeup.aliyun.com/)

```shell script
git clone https://github.com/k8scat/gigrator.git
cd gigrator
pip3 install -r requirements.txt
说明:

# 迁移前需在配置文件(settings.py)中配置 SOURCE_GIT 和 DEST_GIT
# 配置参考: settings_example.py
python3 gigrator.py
```
- 暂不支持迁移至 `Coding`,可从 Coding 迁移至其他 `Git` 服务器
- 由于 `Coding` 的升级,其基础 `API` 不再是 `https://coding.net`,而改为: `https://{username}.coding.net`
- 迁移前请确认已在Git服务器上添加 `SSH Key`
- 只能迁移指定用户下的仓库,即 `{username}/{repo_name}`,不包括参与的或者组织的仓库
- 迁移包括commits、branches和tags,不包括issues、pr和wiki

## Develop
## 安装

```python
# Base class
class Git:
pass
### pip 安装

# Other GitServer class should inherit Git
class OtherGit(Git):
pass
```bash
pip install gigrator
```

## Support

* [x] [Gitee](https://gitee.com/)
* [x] [GitLab](https://gitlab.com/)
* [x] [GitHub](https://github.com/)
* [x] [Gitea](https://gitea.io/zh-cn/)
* [x] [Coding](https://coding.net/)
* [x] [Gogs](https://gogs.io/)
* [x] [腾讯工蜂](https://code.tencent.com/)
* [ ] [Bitbucket](https://bitbucket.org/)

Note:

* 不支持迁移至 `Coding`, 可从 Coding 迁移至其他 `Git` 服务器
* 由于 `Coding` 的升级, 其基础 `API` 不再是 `https://coding.net`, 而改为: `https://{username}.coding.net`
* 迁移前请确认已在Git服务器上添加 `SSH Key`
* 只能迁移指定用户下的仓库, 即 `{username}/{repo_name}`, 不包括参与的或者组织的仓库
* 迁移包括commits、branches和tags, 不包括issues、pr和wiki

## Environment

* Git
* Python

开发环境: `git version 2.20.1 (Apple Git-117)` + `Python 3.7.2`

## Dependencies

* [Requests](https://2.python-requests.org/en/master/)

## References

### GitLab
### 源码安装

* [GitLab API Docs](https://docs.gitlab.com/ee/api/)
* [GitLab Create Repo](https://docs.gitlab.com/ee/api/projects.html#create-project)
* [Project visibility level](https://docs.gitlab.com/ee/api/projects.html#project-visibility-level)

## [GitLab GraphQL API](https://docs.gitlab.com/ee/api/graphql/)

Can not create a project!

It will co-exist with the current v4 REST API. If we have a v5 API, this should be a compatibility layer on top of GraphQL.

* [Introduction to GraphQL](https://developer.github.com/v4/guides/intro-to-graphql/)
* [GraphQL API Resources](https://docs.gitlab.com/ee/api/graphql/reference/index.html)

### [GitHub REST API v3](https://developer.github.com/v3/)

* [GitHub Create Repo](https://developer.github.com/v3/repos/#create)
* [GitHub Personal Access Token](https://github.com/settings/tokens)

## [GitHub GraphQL API v4](https://developer.github.com/v4/)
```shell script
git clone https://github.com/k8scat/gigrator.git
cd gigrator
make
```

* [GraphQL resource limitations](https://developer.github.com/v4/guides/resource-limitations/)
* [Forming Calls with GraphQL](https://developer.github.com/v4/guides/forming-calls/)
## 使用

### 环境要求

### Gitee
- Git
- Python3

* [Gitee OpenAPI](https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoStargazers?ex=no)
* [Gitee Personal Access Token](https://gitee.com/profile/personal_access_tokens)
### 配置文件

### Gitea
参考 [config.yml](./config.yml)

* [Gitea API](https://gitea.com/api/v1/swagger)
* [Get a repo](https://gitea.com/api/v1/swagger#/repository/repoGet)
* [Create a repo](https://gitea.com/api/v1/swagger#/repository/createCurrentUserRepo)
* [List the repos that the authenticated user owns or has access to](https://gitea.com/api/v1/swagger#/user/userCurrentListRepos)
### 运行

### Gogs
```bash
gigrator -c config.yml
```

* [gogs/docs-api](https://github.com/gogs/docs-api)
* [Demo site](https://try.gogs.io/)
## 扩展更多平台

### Coding
基于 `Git` 类实现其他平台的代码仓迁移

* [Open API](https://open.coding.net/open-api/?_ga=2.122224323.99121124.1563808661-1235584671.1544277191)
```python
class Git:
def list_repos(self) -> list:
raise NotImplementedError

### GF (腾讯工蜂)
def create_repo(self, name: str, desc: str, is_private: bool) -> bool:
raise NotImplementedError

* [Open API](https://code.tencent.com/help/api/prepare)
def is_repo_existed(self, repo_name: str) -> bool:
raise NotImplementedError
```

### GraphQL Client
## 贡献

* [sgqlc](https://github.com/profusion/sgqlc)
<a href="https://github.com/k8scat/gigrator/graphs/contributors">
<img src="https://contrib.rocks/image?repo=k8scat/gigrator" />
</a>

## License
## 开源协议 LICENSE

[MIT](https://github.com/k8scat/gigrator/blob/master/LICENSE)
57 changes: 57 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
migrate:
from: github
to: gitee
clone_dir: ""
# 默认迁移所有代码仓,可以设置 repos 迁移特定的代码仓
# repos:
# - repo_a
# - repo_b

gitee:
provider: gitee
api: https://gitee.com/api/v5
ssh_prefix: [email protected]
https_prefix: https://gitee.com
username: ""
token: ""

github:
provider: github
api: https://api.github.com/graphql
ssh_prefix: [email protected]
https_prefix: https://github.com
username: ""
token: ""

gitlab:
provider": gitlab
api: https://gitlab.com/api/v4
ssh_prefix: [email protected]
https_prefix: https://gitlab.com
username: ""
token: ""

coding:
provider: coding
api: https://{your-team}.coding.net
ssh_prefix: [email protected]
https_prefix: https://e.coding.net
username: ""
token: ""

# 腾讯工蜂 https://code.tencent.com/
gongfeng:
provider: gongfeng
api: https://code.tencent.com/api/v3
ssh_prefix: [email protected]
https_prefix: https://git.code.tencent.com
username: ""
token: ""

gitea:
provider: gitea
api: https://gitea.com/api/v1
ssh_prefix: [email protected]
https_prefix: https://gitea.com
username: ""
token: ""
47 changes: 47 additions & 0 deletions dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 开发文档

## GitLab

- [GitLab API Docs](https://docs.gitlab.com/ee/api/)
- [GitLab Create Repo](https://docs.gitlab.com/ee/api/projects.html#create-project)
- [Project visibility level](https://docs.gitlab.com/ee/api/projects.html#project-visibility-level)
- [GitLab GraphQL API](https://docs.gitlab.com/ee/api/graphql/)
- [Introduction to GraphQL](https://developer.github.com/v4/guides/intro-to-graphql/)
- [GraphQL API Resources](https://docs.gitlab.com/ee/api/graphql/reference/index.html)

## [GitHub REST API v3](https://developer.github.com/v3/)

- [GitHub Create Repo](https://developer.github.com/v3/repos/#create)
- [GitHub Personal Access Token](https://github.com/settings/tokens)
- [GitHub GraphQL API v4](https://developer.github.com/v4/)
- [GraphQL resource limitations](https://developer.github.com/v4/guides/resource-limitations/)
- [Forming Calls with GraphQL](https://developer.github.com/v4/guides/forming-calls/)

## Gitee

- [Gitee OpenAPI](https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoStargazers?ex=no)
- [Gitee Personal Access Token](https://gitee.com/profile/personal_access_tokens)

## Gitea

- [Gitea API](https://gitea.com/api/v1/swagger)
- [Get a repo](https://gitea.com/api/v1/swagger#/repository/repoGet)
- [Create a repo](https://gitea.com/api/v1/swagger#/repository/createCurrentUserRepo)
- [List the repos that the authenticated user owns or has access to](https://gitea.com/api/v1/swagger#/user/userCurrentListRepos)

## Gogs

- [gogs/docs-api](https://github.com/gogs/docs-api)
- [Demo site](https://try.gogs.io/)

## Coding

- [Open API](https://help.coding.net/openapi)

## GF (腾讯工蜂)

- [Open API](https://code.tencent.com/help/api/prepare)

## GraphQL Client

- [sgqlc](https://github.com/profusion/sgqlc)
Loading