updated g2g
This commit is contained in:
parent
ad5927adca
commit
fde65b3e8d
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
*.swp
|
*.swp
|
||||||
*.ini
|
*.ini
|
||||||
g2g
|
/g2g
|
||||||
|
18
Makefile
18
Makefile
@ -1,7 +1,19 @@
|
|||||||
|
# g2g Makefile
|
||||||
|
|
||||||
|
GOCMD=go
|
||||||
|
GOBUILDCMD=${GOCMD} build
|
||||||
|
GOOPTIONS=-mod=vendor -ldflags="-s -w"
|
||||||
VERSION := $(shell cat ./VERSION)
|
VERSION := $(shell cat ./VERSION)
|
||||||
|
|
||||||
|
RMCMD=rm
|
||||||
|
BINNAME=g2g
|
||||||
|
|
||||||
|
SRCFILES=cmd/g2g/*.go
|
||||||
|
|
||||||
|
all: build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go build -ldflags="-s -w" -mod=vendor
|
${GOBUILDCMD} ${GOOPTIONS} ${SRCFILES}
|
||||||
|
|
||||||
release:
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
${RMCMD} -f ${BINNAME}
|
||||||
|
25
README.md
25
README.md
@ -47,17 +47,30 @@ gitea_mirror=true
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Copyright (c) 2019 PaulBSD
|
Copyright (c) 2020 PaulBSD
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
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.
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
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.
|
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
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
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
30
cmd/g2g/g2g.go
Normal 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
28
g2g.go
@ -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)
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ github_auth_password="pass"
|
|||||||
gitea_username="user"
|
gitea_username="user"
|
||||||
gitea_dest_username="user_or_org"
|
gitea_dest_username="user_or_org"
|
||||||
gitea_repo_url_tmpl="https://gogs.example.com/api/v1/repos/%s/%s"
|
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_migrate_url="https://gogs.example.com/api/v1/repos/migrate"
|
||||||
gitea_auth_token="token xxxx"
|
gitea_auth_token="token xxxx"
|
||||||
gitea_mirror=true
|
gitea_mirror=true
|
@ -1,9 +1,10 @@
|
|||||||
package main
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.paulbsd.com/paulbsd/g2g/src/utils"
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ import (
|
|||||||
func (config *Config) GetConfig() error {
|
func (config *Config) GetConfig() error {
|
||||||
var configfile string
|
var configfile string
|
||||||
|
|
||||||
flag.Usage = Usage
|
flag.Usage = utils.Usage
|
||||||
|
|
||||||
flag.StringVar(&configfile, "configfile", "g2g.ini", "config file to use with g2g section")
|
flag.StringVar(&configfile, "configfile", "g2g.ini", "config file to use with g2g section")
|
||||||
flag.Parse()
|
flag.Parse()
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,20 +1,20 @@
|
|||||||
package main
|
package g2g
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.paulbsd.com/paulbsd/g2g/src/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetReposFromGitHub get starred repositories from github
|
// GetReposFromGitHub get starred repositories from github
|
||||||
func GetReposFromGitHub(config *Config) ([]GitHubRepo, error) {
|
func GetReposFromGitHub(config *config.Config) ([]GitHubRepo, error) {
|
||||||
var repopartiallist []GitHubRepo
|
var repopartiallist []GitHubRepo
|
||||||
var repofulllist []GitHubRepo
|
var repofulllist []GitHubRepo
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func GetReposFromGitHub(config *Config) ([]GitHubRepo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetGitHubResponse fetchs starred repositories on GitHub
|
// 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)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// 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
|
var isExists bool
|
||||||
|
|
||||||
gitearepourl := fmt.Sprintf(config.GiteaRepoURLTmpl, config.GiteaDestUsername, repo.Name)
|
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
|
// GetGiteaUserUID get the logued user identifier
|
||||||
func (config *Config) GetGiteaUserUID() error {
|
func GetGiteaUserUID(config *config.Config) error {
|
||||||
var giteaorg GiteaOrg
|
var giteaorg GiteaOrg
|
||||||
|
|
||||||
gitearepourl := fmt.Sprintf(config.GiteaOrgsURLTmpl, config.GiteaDestUsername)
|
gitearepourl := fmt.Sprintf(config.GiteaOrgsURLTmpl, config.GiteaDestUsername)
|
||||||
@ -134,7 +134,7 @@ func (config *Config) GetGiteaUserUID() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunMigration run threads for migration
|
// RunMigration run threads for migration
|
||||||
func RunMigration(config *Config, repolist []GitHubRepo) {
|
func RunMigration(config *config.Config, repolist []GitHubRepo) {
|
||||||
repochan := make(chan GitHubRepo)
|
repochan := make(chan GitHubRepo)
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ func RunMigration(config *Config, repolist []GitHubRepo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MigrateReposToGitea migrates input repositories to gitea
|
// 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)
|
wg.Add(1)
|
||||||
for {
|
for {
|
||||||
elem, more := <-jobs
|
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
|
// GitHubRepo githubrepo struct
|
||||||
type GitHubRepo struct {
|
type GitHubRepo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
12
src/utils/main.go
Normal file
12
src/utils/main.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Usage displays possible arguments
|
||||||
|
func Usage() {
|
||||||
|
flag.PrintDefaults()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user