70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
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")
|
|
}
|
|
}
|