diff --git a/.drone.yml b/.drone.yml index c163138..782431c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -9,26 +9,7 @@ clone: tags: true pipeline: - install: - image: node:8.6.0 - pull: true - commands: - - cd frontend/ - - node -v - - npm -v - - yarn --version - - yarn install --pure-lockfile - lint: - image: node:8.6.0 - commands: - - cd frontend/ - - yarn run lint - build_frontend: - image: node:8.6.0 - commands: - - cd frontend/ - - yarn build - build: + deps: image: golang:1.10 pull: true environment: @@ -53,7 +34,8 @@ pipeline: commands: - make release when: - event: [ tag ] + event: [ push, tag ] + branch: [ master ] clean: image: golang:1.10 pull: true @@ -82,3 +64,35 @@ pipeline: when: event: [ push, tag ] branch: [ master ] + s3: + image: plugins/s3:1 + pull: true + secrets: [ aws_access_key_id, aws_secret_access_key ] + bucket: gitea-github-migrator + path_style: true + acl: public-read + source: releases/* + target: dist/master + strip_prefix: releases/ + endpoint: https://storage.h.jonasfranz.software + when: + event: [ push ] + branch: [ master ] + s3: + image: plugins/s3:1 + pull: true + secrets: [ aws_access_key_id, aws_secret_access_key ] + bucket: gitea-github-migrator + path_style: true + acl: public-read + source: releases/* + target: dist/${DRONE_TAG##v} + strip_prefix: releases/ + endpoint: https://storage.h.jonasfranz.software + when: + event: [ tag ] + +services: + gitea: + image: jonasfranz/gitea-service + pull: true \ No newline at end of file diff --git a/Gopkg.lock b/Gopkg.lock index 7f36751..dfed5f1 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -50,6 +50,12 @@ revision = "bd47f2894846e32edcf9aa37290fef76c327883f" version = "v1.11.1" +[[projects]] + name = "github.com/davecgh/go-spew" + packages = ["spew"] + revision = "346938d642f2ec3594ed81d874461961cd0faa76" + version = "v1.1.0" + [[projects]] name = "github.com/golang/protobuf" packages = ["proto"] @@ -68,6 +74,29 @@ packages = ["query"] revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a" +[[projects]] + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + name = "github.com/stretchr/objx" + packages = ["."] + revision = "477a77ecc69700c7cdeb1fa9e129548e1c1c393c" + version = "v0.1.1" + +[[projects]] + name = "github.com/stretchr/testify" + packages = [ + ".", + "assert", + "http", + "mock" + ] + revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" + version = "v1.2.2" + [[projects]] branch = "master" name = "github.com/jinzhu/configor" @@ -146,6 +175,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "10db78bccc75a090bb1e23467c4f5d6abb8bd3b4b158e4b684550539d23565c9" + inputs-digest = "884bf618611f0aaad19defa64a14fa70fd2b522afe8cf99dedbfada2a9d8b88d" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 1b60a8d..1389f5f 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -3,9 +3,8 @@ unused-packages = true [[constraint]] - branch = "myuserinfo" + branch = "master" name = "code.gitea.io/sdk" - source = "github.com/JonasFranzDEV/go-sdk" [[constraint]] name = "github.com/urfave/cli" @@ -14,6 +13,9 @@ [[constraint]] name = "github.com/google/go-github" version = "15.0.0" +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.2.2" [[constraint]] branch = "master" diff --git a/Makefile b/Makefile index e4d5b86..074ca65 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ IMPORT := git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator GO ?= go -BUILD=$(or ${DRONE_BUILD_NUMBER},${DRONE_BUILD_NUMBER},0) ifneq ($(DRONE_TAG),) VERSION ?= $(subst v,,$(DRONE_TAG)) @@ -13,7 +12,7 @@ else endif endif -LDFLAGS := -X main.Version=$(VERSION) -X main.build=$(BUILD) +LDFLAGS := -X main.version=$(VERSION) -X main.build=$(DRONE_BUILD_NUMBER) .PHONY: all all: diff --git a/README.md b/README.md index 85b3cda..a0b2ad6 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,13 @@ Migrates: - [x] Milestones - [x] Comments - [ ] Users -- [ ] Pull Requests +- [x] Pull Requests (as issue) - [ ] Statuses ## Installation +### From source + ```bash go get git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator cd $GOPATH/src/git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator @@ -29,6 +31,12 @@ dep ensure go install ``` +### From Binary +We provide binaries of master builds and all releases at our [minio storage server](https://storage.h.jonasfranz.software/minio/gitea-github-migrator/dist/). + +Additionally we provide them for every release as release attachment under [releases](https://git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/releases). + +You don't need any dependencies except the binary to run the migrator. ## Usage Migrate one repository: diff --git a/cmd/migrate.go b/cmd/migrate.go index 4b8d605..271f492 100644 --- a/cmd/migrate.go +++ b/cmd/migrate.go @@ -55,13 +55,13 @@ func migrate(c context.Context, gc *github.Client, m *migrations.Migratory, user fmt.Printf("Fetching repository %s/%s...\n", username, repo) gr, _, err := gc.Repositories.Get(c, username, repo) if err != nil { - return err + return fmt.Errorf("error while fetching repo[%s/%s]: %v", username, repo, err) } fmt.Printf("Migrating repository %s/%s...\n", username, repo) var mr *gitea.Repository if mr, err = m.Repository(gr); err != nil { - return err + return fmt.Errorf("error while migrating repo[%s/%s]: %v", username, repo, err) } fmt.Printf("Repository migrated to %s/%s\n", mr.Owner.UserName, mr.Name) @@ -82,7 +82,7 @@ func migrate(c context.Context, gc *github.Client, m *migrations.Migratory, user for { issues, resp, err := gc.Issues.ListByRepo(c, username, repo, opt) if err != nil { - return err + return fmt.Errorf("error while listing repos: %v", err) } allIssues = append(allIssues, issues...) if resp.NextPage == 0 { @@ -91,7 +91,6 @@ func migrate(c context.Context, gc *github.Client, m *migrations.Migratory, user opt.Page = resp.NextPage } fmt.Println("Migrating issues...") - //bar := p.AddBar(int64(len(issues))) for _, gi := range allIssues { fmt.Printf("Migrating #%d...\n", *gi.Number) issue, err := m.Issue(gi) @@ -110,7 +109,6 @@ func migrate(c context.Context, gc *github.Client, m *migrations.Migratory, user fmt.Print("Done!\n") } fmt.Printf("Migrated #%d...\n", *gi.Number) - //bar.Increment() } return nil diff --git a/cmd/migrate_test.go b/cmd/migrate_test.go new file mode 100644 index 0000000..0f458e6 --- /dev/null +++ b/cmd/migrate_test.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "context" + "testing" + + "git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/migrations" + "github.com/google/go-github/github" + "github.com/stretchr/testify/assert" +) + +// Test_migrate is an integration tests for migrate command +// using repo JonasFranzDEV/test +func Test_migrate(t *testing.T) { + assert.NoError(t, migrate( + context.Background(), + github.NewClient(nil), + migrations.DemoMigratory, + "JonasFranzDEV", + "test", + false, + )) +} diff --git a/migrations/issue.go b/migrations/issue.go index 5a216b4..ca2c9d2 100644 --- a/migrations/issue.go +++ b/migrations/issue.go @@ -96,6 +96,7 @@ func githubStateToGiteaState(ghstate *string) *string { } switch *ghstate { case "open": + fallthrough case "closed": return ghstate case "all": diff --git a/migrations/issue_test.go b/migrations/issue_test.go new file mode 100644 index 0000000..85cc69c --- /dev/null +++ b/migrations/issue_test.go @@ -0,0 +1,49 @@ +package migrations + +import ( + "testing" + + "code.gitea.io/sdk/gitea" + "github.com/google/go-github/github" + "github.com/stretchr/testify/assert" +) + +func Test_githubStateToGiteaState(t *testing.T) { + open := "open" + all := "all" + closed := "closed" + tests := map[*string]string{&all: "open", &open: "open", &closed: "closed"} + for input, exceptedResult := range tests { + actualResult := githubStateToGiteaState(input) + assert.NotNil(t, actualResult) + assert.NotEmpty(t, *actualResult) + assert.Equal(t, exceptedResult, *actualResult) + } + nilInput := "teoafweogwoe" + assert.Nil(t, githubStateToGiteaState(&nilInput)) +} + +func TestMigratory_Label(t *testing.T) { + res, err := DemoMigratory.Label(&github.Label{ + Name: github.String("testlabel"), + Color: github.String("123456"), + }) + assert.NoError(t, err) + assert.Equal(t, "123456", res.Color) + assert.Equal(t, "testlabel", res.Name) +} + +func TestMigratory_Milestone(t *testing.T) { + res, err := DemoMigratory.Milestone(&github.Milestone{ + ID: github.Int64(1), + State: github.String("open"), + Description: github.String("test milestone"), + Title: github.String("TEST"), + DueOn: &demoTime, + }) + assert.NoError(t, err) + assert.Equal(t, "TEST", res.Title) + assert.Equal(t, "test milestone", res.Description) + assert.Equal(t, demoTime.Unix(), res.Deadline.Unix()) + assert.Equal(t, gitea.StateOpen, res.State) +} diff --git a/migrations/utils.go b/migrations/utils.go new file mode 100644 index 0000000..e0f6552 --- /dev/null +++ b/migrations/utils.go @@ -0,0 +1,24 @@ +package migrations + +import ( + "time" + + "code.gitea.io/sdk/gitea" +) + +var DemoMigratory = &Migratory{ + AuthUsername: "demo", + AuthPassword: "demo", + Client: gitea.NewClient("http://gitea:3000", "8bffa364d5a4b2f18421426da0baf6ccddd16d6b"), + repository: &gitea.Repository{ + Name: "demo", + Owner: &gitea.User{ + UserName: "demo", + }, + }, + NewOwnerID: 1, + migratedMilestones: make(map[int64]int64), + migratedLabels: make(map[int64]int64), +} + +var demoTime = time.Date(2018, 01, 01, 01, 01, 01, 01, time.UTC)