Add documentation Add only-repo flag Cleaned up dependencies Signed-off-by: Jonas Franz <info@jonasfranz.software>remotes/1717512478715731737/master
parent
b75c3bbb2c
commit
4efdc3b53b
@ -1,3 +1,64 @@ |
|||||||
# gitea-github-migrator |
# gitea-github-migrator |
||||||
|
|
||||||
A tool to migrate GitHub Repositories to Gitea including all issues |
A tool to migrate [GitHub](https://github.com) Repositories to [Gitea](https://gitea.io) including all issues, labels, milestones |
||||||
|
and comments. |
||||||
|
|
||||||
|
## Features |
||||||
|
Migrates: |
||||||
|
|
||||||
|
- [x] Repositories |
||||||
|
- [x] Issues |
||||||
|
- [x] Labels |
||||||
|
- [x] Milestones |
||||||
|
- [x] Comments |
||||||
|
- [ ] Users |
||||||
|
- [ ] Pull Requests |
||||||
|
- [ ] Statuses |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
```bash |
||||||
|
go get git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator |
||||||
|
cd $GOPATH/src/git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator |
||||||
|
dep ensure |
||||||
|
go install |
||||||
|
``` |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
Migrate one repository: |
||||||
|
```bash |
||||||
|
gitea-github-migrator migrate \ |
||||||
|
--gh-repo owner/reponame \ |
||||||
|
--gh-token GITHUB_TOKEN \ |
||||||
|
--url http://gitea-url.tdl \ |
||||||
|
--token GITEA_TOKEN \ |
||||||
|
--owner 1 |
||||||
|
``` |
||||||
|
`gh-token` is only required if you have more then 50 issues / repositories. |
||||||
|
|
||||||
|
Migrate all repositories: |
||||||
|
```bash |
||||||
|
gitea-github-migrator migrate-all \ |
||||||
|
--gh-user username \ |
||||||
|
--gh-token GITHUB_TOKEN \ |
||||||
|
--url http://gitea-url.tdl \ |
||||||
|
--token GITEA_TOKEN \ |
||||||
|
--owner 1 |
||||||
|
``` |
||||||
|
|
||||||
|
Migrate all repository without issues etc. (classic): |
||||||
|
```bash |
||||||
|
gitea-github-migrator migrate-all \ |
||||||
|
--gh-user username \ |
||||||
|
--gh-token GITHUB_TOKEN \ |
||||||
|
--url http://gitea-url.tdl \ |
||||||
|
--token GITEA_TOKEN \ |
||||||
|
--owner 1 |
||||||
|
--only-repo |
||||||
|
``` |
||||||
|
|
||||||
|
## Problems |
||||||
|
* This migrator does not work with Gitea instances utilizing a SQLite database. |
||||||
|
* Comments / Issues will be added by token's user (information about date and author will be added) |
||||||
|
* Current Date is utilized for creation date (information about date is added in a comment) |
@ -0,0 +1,83 @@ |
|||||||
|
package cmd |
||||||
|
|
||||||
|
import ( |
||||||
|
"code.gitea.io/sdk/gitea" |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/migrations" |
||||||
|
"github.com/google/go-github/github" |
||||||
|
"github.com/urfave/cli" |
||||||
|
"golang.org/x/oauth2" |
||||||
|
"sync" |
||||||
|
) |
||||||
|
|
||||||
|
var CmdMigrateAll = cli.Command{ |
||||||
|
Name: "migrate-all", |
||||||
|
Usage: "migrates all repositories of an user from github to a gitea repository", |
||||||
|
Action: runMigrateAll, |
||||||
|
Flags: append(migrateFlags, |
||||||
|
cli.StringFlag{ |
||||||
|
Name: "gh-user", |
||||||
|
EnvVar: "GH_USER", |
||||||
|
Usage: "GitHub Username", |
||||||
|
}, |
||||||
|
), |
||||||
|
} |
||||||
|
|
||||||
|
func runMigrateAll(ctx *cli.Context) error { |
||||||
|
m := &migrations.Migratory{ |
||||||
|
Client: gitea.NewClient(ctx.String("url"), ctx.String("token")), |
||||||
|
Private: ctx.Bool("private"), |
||||||
|
NewOwnerID: ctx.Int("owner"), |
||||||
|
} |
||||||
|
c := context.Background() |
||||||
|
|
||||||
|
var gc *github.Client |
||||||
|
if ctx.IsSet("gh-token") { |
||||||
|
ts := oauth2.StaticTokenSource( |
||||||
|
&oauth2.Token{AccessToken: ctx.String("gh-token")}, |
||||||
|
) |
||||||
|
tc := oauth2.NewClient(c, ts) |
||||||
|
gc = github.NewClient(tc) |
||||||
|
} else { |
||||||
|
gc = github.NewClient(nil) |
||||||
|
} |
||||||
|
|
||||||
|
opt := &github.RepositoryListOptions{ |
||||||
|
ListOptions: github.ListOptions{PerPage: 100}, |
||||||
|
} |
||||||
|
// get all pages of results
|
||||||
|
var allRepos []*github.Repository |
||||||
|
for { |
||||||
|
repos, resp, err := gc.Repositories.List(c, ctx.String("gh-user"), opt) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
allRepos = append(allRepos, repos...) |
||||||
|
if resp.NextPage == 0 { |
||||||
|
break |
||||||
|
} |
||||||
|
opt.Page = resp.NextPage |
||||||
|
} |
||||||
|
errs := make(chan error, 1) |
||||||
|
|
||||||
|
var wg sync.WaitGroup |
||||||
|
wg.Add(len(allRepos)) |
||||||
|
for _, repo := range allRepos { |
||||||
|
go func(r *github.Repository) { |
||||||
|
defer wg.Done() |
||||||
|
errs <- migrate(gc, c, m, r.Owner.GetLogin(), r.GetName(), ctx.Bool("only-repo")) |
||||||
|
}(repo) |
||||||
|
} |
||||||
|
|
||||||
|
go func() { |
||||||
|
for i := range errs { |
||||||
|
if i != nil { |
||||||
|
fmt.Printf("error: %v", i) |
||||||
|
} |
||||||
|
} |
||||||
|
}() |
||||||
|
|
||||||
|
wg.Wait() |
||||||
|
return nil |
||||||
|
} |
Loading…
Reference in new issue