updated g2g

This commit is contained in:
Paul 2020-01-29 12:54:43 +01:00
parent ad5927adca
commit fde65b3e8d
11 changed files with 95 additions and 61 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
*.swp
*.ini
g2g
/g2g

View File

@ -1,7 +1,19 @@
# g2g Makefile
GOCMD=go
GOBUILDCMD=${GOCMD} build
GOOPTIONS=-mod=vendor -ldflags="-s -w"
VERSION := $(shell cat ./VERSION)
RMCMD=rm
BINNAME=g2g
SRCFILES=cmd/g2g/*.go
all: build
build:
go build -ldflags="-s -w" -mod=vendor
release:
${GOBUILDCMD} ${GOOPTIONS} ${SRCFILES}
clean:
${RMCMD} -f ${BINNAME}

View File

@ -47,17 +47,30 @@ gitea_mirror=true
## License
```text
Copyright (c) 2019 PaulBSD
Copyright (c) 2020 PaulBSD
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the fuelprices project.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the fuelprices project.
```

30
cmd/g2g/g2g.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"git.paulbsd.com/paulbsd/g2g/src/config"
"git.paulbsd.com/paulbsd/g2g/src/g2g"
"log"
)
func main() {
var cfg config.Config
var err error
var repolist []g2g.GitHubRepo
err = cfg.GetConfig()
if err != nil {
log.Fatal(err)
}
err = g2g.GetGiteaUserUID(&cfg)
if err != nil {
log.Fatal(err)
}
repolist, err = g2g.GetReposFromGitHub(&cfg)
if err != nil {
log.Fatal(err)
}
g2g.RunMigration(&cfg, repolist)
}

28
g2g.go
View File

@ -1,28 +0,0 @@
package main
import (
"log"
)
func main() {
var config Config
var err error
var repolist []GitHubRepo
err = config.GetConfig()
if err != nil {
log.Fatal(err)
}
err = config.GetGiteaUserUID()
if err != nil {
log.Fatal(err)
}
repolist, err = GetReposFromGitHub(&config)
if err != nil {
log.Fatal(err)
}
RunMigration(&config, repolist)
}

View File

@ -11,7 +11,7 @@ github_auth_password="pass"
gitea_username="user"
gitea_dest_username="user_or_org"
gitea_repo_url_tmpl="https://gogs.example.com/api/v1/repos/%s/%s"
gitea_orgs_url_tmpl="https://git.paulbsd.com/api/v1/orgs/%s"
gitea_orgs_url_tmpl="https://gogs.example.com/api/v1/orgs/%s"
gitea_migrate_url="https://gogs.example.com/api/v1/repos/migrate"
gitea_auth_token="token xxxx"
gitea_mirror=true

2
go.mod
View File

@ -1,4 +1,4 @@
module g2g
module git.paulbsd.com/paulbsd/g2g
go 1.13

View File

@ -1,9 +1,10 @@
package main
package config
import (
"flag"
"time"
"git.paulbsd.com/paulbsd/g2g/src/utils"
"gopkg.in/ini.v1"
)
@ -11,7 +12,7 @@ import (
func (config *Config) GetConfig() error {
var configfile string
flag.Usage = Usage
flag.Usage = utils.Usage
flag.StringVar(&configfile, "configfile", "g2g.ini", "config file to use with g2g section")
flag.Parse()

View File

@ -1,4 +1,4 @@
package main
package config
import (
"fmt"

View File

@ -1,20 +1,20 @@
package main
package g2g
import (
"bytes"
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"sync"
"git.paulbsd.com/paulbsd/g2g/src/config"
)
// GetReposFromGitHub get starred repositories from github
func GetReposFromGitHub(config *Config) ([]GitHubRepo, error) {
func GetReposFromGitHub(config *config.Config) ([]GitHubRepo, error) {
var repopartiallist []GitHubRepo
var repofulllist []GitHubRepo
@ -48,7 +48,7 @@ func GetReposFromGitHub(config *Config) ([]GitHubRepo, error) {
}
// GetGitHubResponse fetchs starred repositories on GitHub
func GetGitHubResponse(config *Config, url string) (*http.Response, error) {
func GetGitHubResponse(config *config.Config, url string) (*http.Response, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
@ -71,7 +71,7 @@ func GetGitHubResponse(config *Config, url string) (*http.Response, error) {
}
// CheckGiteaExistingRepo checks if there's an existing repository in gitea
func CheckGiteaExistingRepo(config *Config, repo GitHubRepo) (bool, error) {
func CheckGiteaExistingRepo(config *config.Config, repo GitHubRepo) (bool, error) {
var isExists bool
gitearepourl := fmt.Sprintf(config.GiteaRepoURLTmpl, config.GiteaDestUsername, repo.Name)
@ -97,7 +97,7 @@ func CheckGiteaExistingRepo(config *Config, repo GitHubRepo) (bool, error) {
}
// GetGiteaUserUID get the logued user identifier
func (config *Config) GetGiteaUserUID() error {
func GetGiteaUserUID(config *config.Config) error {
var giteaorg GiteaOrg
gitearepourl := fmt.Sprintf(config.GiteaOrgsURLTmpl, config.GiteaDestUsername)
@ -134,7 +134,7 @@ func (config *Config) GetGiteaUserUID() error {
}
// RunMigration run threads for migration
func RunMigration(config *Config, repolist []GitHubRepo) {
func RunMigration(config *config.Config, repolist []GitHubRepo) {
repochan := make(chan GitHubRepo)
done := make(chan bool)
@ -152,7 +152,7 @@ func RunMigration(config *Config, repolist []GitHubRepo) {
}
// MigrateReposToGitea migrates input repositories to gitea
func MigrateReposToGitea(config *Config, wg *sync.WaitGroup, jobs chan GitHubRepo, done chan bool, thr int) error {
func MigrateReposToGitea(config *config.Config, wg *sync.WaitGroup, jobs chan GitHubRepo, done chan bool, thr int) error {
wg.Add(1)
for {
elem, more := <-jobs
@ -199,12 +199,6 @@ func MigrateReposToGitea(config *Config, wg *sync.WaitGroup, jobs chan GitHubRep
}
}
// Usage displays possible arguments
func Usage() {
flag.PrintDefaults()
os.Exit(1)
}
// GitHubRepo githubrepo struct
type GitHubRepo struct {
Name string `json:"name"`

12
src/utils/main.go Normal file
View File

@ -0,0 +1,12 @@
package utils
import (
"flag"
"os"
)
// Usage displays possible arguments
func Usage() {
flag.PrintDefaults()
os.Exit(1)
}