Compare commits

...

12 Commits

Author SHA1 Message Date
jnweiger d22c74c735 allow explicit GITHUB_USER and GITHUB_PASS 6 years ago
Jonas Franz afd81459b9
Fix release builds 6 years ago
Jonas Franz f92784c0b6 Add title and note to releases (#20) 6 years ago
Jonas Franz 82ea2d47b7 Fetch user if no --owner is given (#17) 6 years ago
Jonas Franz 9a306fb468 Add tests (#5) 6 years ago
Jonas Franz 4e61d1ca09
Fix drone build number/version 6 years ago
Jonas Franz 509abf5a7f Add support for S3 distribution (#15) 6 years ago
Jonas Franz b221b6d9df Add docker badge (#12) 6 years ago
Jonas Franz cecaa2f250 Limit drone docker build to master branch (#13) 6 years ago
techknowlogick d6c089a561 Remove example comments from Gopkg (#11) 6 years ago
techknowlogick f05c383db2 Add dockerfile (#7) 6 years ago
Jonas Franz 92b6438b55 Add badge for latest release (#8) 6 years ago
  1. 9
      .changelog.yml
  2. 57
      .drone.yml
  3. 18
      Dockerfile
  4. 22
      Gopkg.lock
  5. 32
      Gopkg.toml
  6. 11
      Makefile
  7. 12
      README.md
  8. 9
      cmd/migrate-all.go
  9. 24
      cmd/migrate.go
  10. 23
      cmd/migrate_test.go
  11. 1
      migrations/issue.go
  12. 49
      migrations/issue_test.go
  13. 2
      migrations/migratory.go
  14. 2
      migrations/repo.go
  15. 24
      migrations/utils.go

@ -0,0 +1,9 @@
## ENHANCEMENTS
* Fetch user if no --owner is given
## BUILD
* Add docker release
* Add tests
* Add makefile
* Add S3 distrubution

@ -30,7 +30,17 @@ pipeline:
environment:
GOPATH: /go
commands:
- make release
- make generate-release-file release
when:
event: [ push ]
branch: [ master ]
static:
image: golang:1.10
pull: true
environment:
GOPATH: /go
commands:
- make generate-release-file release
when:
event: [ tag ]
gitea:
@ -38,10 +48,53 @@ pipeline:
pull: true
base_url: "https://git.jonasfranz.software"
secrets: [ gitea_token ]
title: .version
note: .changelog.yml
files:
- releases/*
checksum:
- sha256
- md5
when:
event: [ tag ]
event: [ tag ]
docker:
image: plugins/docker:17.12
secrets: [ docker_username, docker_password ]
pull: true
repo: jonasfranz/gitea-github-migrator
default_tags: true
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

@ -0,0 +1,18 @@
#Build stage
FROM golang:1.10-alpine3.7 AS build-env
#Build deps
RUN apk --no-cache add build-base git
#Setup repo
COPY . ${GOPATH}/src/git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator
WORKDIR ${GOPATH}/src/git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator
RUN make docker-binary
FROM alpine:3.7
LABEL maintainer="info@jonasfranz.software"
COPY --from=build-env /go/src/git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/gitea-github-migrator /usr/local/bin/gitea-github-migrator
ENTRYPOINT ["/usr/local/bin/gitea-github-migrator"]

22
Gopkg.lock generated

@ -5,7 +5,13 @@
branch = "master"
name = "code.gitea.io/sdk"
packages = ["gitea"]
revision = "39c609e903992e25deca0e7aa2c5304fd680530f"
revision = "79a281c4e34ae44cf96a23f0283729a074a6c2a0"
[[projects]]
name = "github.com/davecgh/go-spew"
packages = ["spew"]
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0"
[[projects]]
name = "github.com/golang/protobuf"
@ -25,6 +31,18 @@
packages = ["query"]
revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a"
[[projects]]
name = "github.com/pmezard/go-difflib"
packages = ["difflib"]
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0"
[[projects]]
name = "github.com/stretchr/testify"
packages = ["assert"]
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
version = "v1.2.2"
[[projects]]
name = "github.com/urfave/cli"
packages = ["."]
@ -66,6 +84,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "8d6cfc8199a1dde1c7b34a3771993afc73f7952a4b261f24939a63d0dce83b2e"
inputs-digest = "a63a8945bd36ecc14dfbb7f9894543855f9e9e2e493dfdb77c06b4a12aada8a4"
solver-name = "gps-cdcl"
solver-version = 1

@ -1,30 +1,3 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[prune]
go-tests = true
unused-packages = true
@ -39,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"

@ -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,11 +12,19 @@ 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:
.PHONY: docker-binary
docker-binary:
go build -ldflags "$(LDFLAGS)" -o gitea-github-migrator
.PHONY: generate-release-file
generate-release-file:
echo $(VERSION) > .version
.PHONY: release
release:
@hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \

@ -1,5 +1,7 @@
# gitea-github-migrator
[![Build Status](https://drone.jonasfranz.software/api/badges/JonasFranzDEV/gitea-github-migrator/status.svg)](https://drone.jonasfranz.software/JonasFranzDEV/gitea-github-migrator)
[![Latest Release](https://img.shields.io/badge/dynamic/json.svg?label=release&url=https%3A%2F%2Fgit.jonasfranz.software%2Fapi%2Fv1%2Frepos%2FJonasFranzDEV%2Fgitea-github-migrator%2Freleases&query=%24%5B0%5D.tag_name)](https://git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/releases)
[![Docker Pulls](https://img.shields.io/docker/pulls/jonasfranz/gitea-github-migrator.svg)](https://hub.docker.com/r/jonasfranz/gitea-github-migrator/)
A tool to migrate [GitHub](https://github.com) Repositories to [Gitea](https://gitea.io) including all issues, labels, milestones
and comments.
@ -13,11 +15,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
@ -25,6 +29,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:

@ -30,7 +30,14 @@ 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"),
NewOwnerID: ctx.Int64("owner"),
}
if m.NewOwnerID == 0 {
usr, err := m.Client.GetMyUserInfo()
if err != nil {
return fmt.Errorf("cannot fetch user info about current user: %v", err)
}
m.NewOwnerID = usr.ID
}
c := context.Background()

@ -1,6 +1,7 @@
package cmd
import (
"os"
"context"
"fmt"
"strings"
@ -31,7 +32,14 @@ func runMigrate(ctx *cli.Context) error {
m := &migrations.Migratory{
Client: gitea.NewClient(ctx.String("url"), ctx.String("token")),
Private: ctx.Bool("private"),
NewOwnerID: ctx.Int("owner"),
NewOwnerID: ctx.Int64("owner"),
}
if m.NewOwnerID == 0 {
usr, err := m.Client.GetMyUserInfo()
if err != nil {
return fmt.Errorf("cannot fetch user info about current user: %v", err)
}
m.NewOwnerID = usr.ID
}
c := context.Background()
var gc *github.Client
@ -47,6 +55,12 @@ func runMigrate(ctx *cli.Context) error {
username := strings.Split(ctx.String("gh-repo"), "/")[0]
repo := strings.Split(ctx.String("gh-repo"), "/")[1]
if u := os.Getenv("GITHUB_USER"); u != "" {
m.AuthUsername = u
}
if p := os.Getenv("GITHUB_PASS"); p != "" {
m.AuthPassword = p
}
return migrate(c, gc, m, username, repo, ctx.Bool("only-repo"))
}
@ -55,13 +69,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 +96,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 +105,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 +123,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)
}

@ -9,7 +9,7 @@ type Migratory struct {
AuthPassword string
Private bool
NewOwnerID int
NewOwnerID int64
repository *gitea.Repository
// key: github milestone id | value: gitea milestone id

@ -14,7 +14,7 @@ func (m *Migratory) Repository(gr *github.Repository) (*gitea.Repository, error)
AuthUsername: m.AuthUsername,
CloneAddr: gr.GetCloneURL(),
RepoName: gr.GetName(),
UID: m.NewOwnerID,
UID: int(m.NewOwnerID),
Private: m.Private,
})
return m.repository, err

@ -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)
Loading…
Cancel
Save