1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
- package main
- import (
- "context"
- "fmt"
- "log"
- "os"
- "os/signal"
- "path/filepath"
- "golang.org/x/sys/unix"
- )
- func main() {
- ctx, cancel := context.WithCancel(context.Background())
- // Catch signals
- go func() {
- sigChan := make(chan os.Signal, 1)
- signal.Notify(sigChan, unix.SIGINT, unix.SIGTERM)
- _ = <-sigChan
- log.Printf("caught signal; shutting down...")
- cancel()
- }()
- accessToken, ok := os.LookupEnv("GOGS_ACCESS_TOKEN")
- if !ok {
- log.Fatal("environment variable GOGS_ACCESS_TOKEN is unset")
- }
- gitlab := NewGitLabClient(ctx)
- gogs := NewGogsClient(ctx, accessToken)
- log.Printf("looking up authenticated gogs user...")
- user := &GogsUser{}
- err := FetchGogsUserAuthenticated(gogs, user)
- if err != nil {
- log.Fatal(err)
- }
- input := &MigrateToGogsRepoInput{}
- repo := &GogsRepo{}
- log.Printf("fetching gitlab projects...")
- org := "idio.link"
- projects := FetchGitLabGroupProjects(gitlab, org)
- for p := range projects.Iter() {
- input.SrcURI = p.RepoURL
- input.TgtUID = user.Id
- input.TgtRepoName = filepath.Base(p.PathWithNamespace)
- input.TgtRepoMirror = false
- input.TgtRepoPrivate = false
- input.TgtRepoDescr = p.Description
- log.Printf("migrating %s...", p.PathWithNamespace)
- err = MigrateToGogsRepo(gogs, input, repo)
- if err != nil {
- log.Printf("%v", err)
- }
- }
- if err := projects.LastErr(); err != nil {
- log.Fatal(fmt.Sprintf("fetch gitlab group projects: %v", err))
- }
- }
|