pull/17/head
Jonas Franz преди 6 години committed by Gitea
родител 4e61d1ca09
ревизия 9a306fb468
  1. 7
      .drone.yml
  2. 31
      Gopkg.lock
  3. 5
      Gopkg.toml
  4. 8
      cmd/migrate.go
  5. 23
      cmd/migrate_test.go
  6. 1
      migrations/issue.go
  7. 49
      migrations/issue_test.go
  8. 24
      migrations/utils.go

@ -81,4 +81,9 @@ pipeline:
strip_prefix: releases/
endpoint: https://storage.h.jonasfranz.software
when:
event: [ tag ]
event: [ tag ]
services:
gitea:
image: jonasfranz/gitea-service
pull: true

31
Gopkg.lock generated

@ -7,6 +7,12 @@
packages = ["gitea"]
revision = "39c609e903992e25deca0e7aa2c5304fd680530f"
[[projects]]
name = "github.com/davecgh/go-spew"
packages = ["spew"]
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0"
[[projects]]
name = "github.com/golang/protobuf"
packages = ["proto"]
@ -25,6 +31,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]]
name = "github.com/urfave/cli"
packages = ["."]
@ -66,6 +95,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "8d6cfc8199a1dde1c7b34a3771993afc73f7952a4b261f24939a63d0dce83b2e"
inputs-digest = "884bf618611f0aaad19defa64a14fa70fd2b522afe8cf99dedbfada2a9d8b88d"
solver-name = "gps-cdcl"
solver-version = 1

@ -12,4 +12,7 @@
[[constraint]]
name = "github.com/google/go-github"
version = "15.0.0"
version = "15.0.0"
[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.2"

@ -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

@ -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,
))
}

@ -96,6 +96,7 @@ func githubStateToGiteaState(ghstate *string) *string {
}
switch *ghstate {
case "open":
fallthrough
case "closed":
return ghstate
case "all":

@ -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)
}

@ -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)
Зареждане…
Отказ
Запис