initial commit

This commit is contained in:
Gardient
2018-06-07 22:50:47 +03:00
commit 926aeb4eee
7 changed files with 252 additions and 0 deletions

69
main.go Normal file
View File

@@ -0,0 +1,69 @@
package main
import (
"fmt"
"net/http"
"os"
"strings"
"git.gyulakerezsi.ro/migrate-github/migration"
"git.gyulakerezsi.ro/migrate-github/utils"
"github.com/joho/godotenv"
)
type ghRepo struct {
Name string `json:"name"`
FullName string `json:"full_name"`
CloneURL string `json:"clone_url"`
Description string `json:"description"`
}
func main() {
godotenv.Load()
gogsTrgt := os.Getenv("TARGET_GOGS")
gogsPat := os.Getenv("GOGS_PAT")
user := os.Getenv("GH_USER")
response, err := http.Get("https://api.github.com/users/" + user + "/repos")
utils.PanicOnError(err)
migrationClient := migration.NewClient(gogsTrgt, gogsPat)
repos := make([]ghRepo, 0)
utils.UnmarshalFromResponse(response, &repos)
migrated := make([]string, 0)
for _, el := range repos {
fmt.Printf("Migrate %s to your git? [Y/n] > ", el.FullName)
resp := utils.ReadLine()
switch resp = strings.ToLower(strings.TrimSpace(resp)); resp {
case "n":
fmt.Println("skipping")
default:
fmt.Print("Target repo name [leave blank to use the curent one] > ")
newName := utils.ReadLine()
if newName == "" {
newName = el.Name
}
fmt.Printf("migrating %s ==> %s/%s\n", el.CloneURL, migrationClient.User.Username, newName)
err := migrationClient.Migrate(el.CloneURL, el.Description, newName)
utils.PanicOnError(err)
migrated = append(migrated, el.FullName+" -> "+migrationClient.User.Username+"/"+newName)
}
}
fmt.Println("\n\n================================================")
if len(migrated) > 0 {
fmt.Println("Migrated:")
for _, el := range migrated {
fmt.Printf("\t%s\n", el)
}
} else {
fmt.Println("Nothing migrated")
}
}