Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
// TODO RUN A GO GET ON THE LIBRARIES BELOW
"code.gitea.io/sdk/gitea"
"context"
"time"
"fmt"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
func main() {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "GETTOKENFROMGITHUB"}, // TODO: GET TOKEN FROM GITHUB
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
giteaclient := gitea.NewClient("https://YOURGITEAHOST/", "GETTOKENFROMGITEA") // TODO: CONFIGURE WITH URL of your GITEA INSTANCE AND A TOKEN FROM YOUR GITEA INSTANCE
opt := &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{Type: "public", PerPage: 100},
}
// get all pages of results
var allRepos []*github.Repository
for {
repos, resp, err := client.Repositories.ListByOrg(ctx, "PUTGITHUBORGYOUWANTCLONEDHERE", opt) // TODO: SET WITH NAME OF GITHUB ORG YOU WANT CLONED
if err != nil {
fmt.Println(err)
return
}
allRepos = append(allRepos, repos...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
for i := 0; i < len(allRepos); i++ {
description := ""
if allRepos[i].Description != nil { // will throw a nil pointer error if description is passed directly to the below struct
description = *allRepos[i].Description
}
giteaclient.MigrateRepo(gitea.MigrateRepoOption{
CloneAddr: *allRepos[i].CloneURL,
UID: 4, // TODO: SET WITH THE ID OF YOUR USER IN GITEA (IN MY CASE 4 is the user id of an org on my gitea instance)
RepoName: *allRepos[i].Name,
// Mirror: true, // TODO: uncomment this if you want gitea to periodically check for changes
// Private: true, // TODO: uncomment this if you want the repo to be private on gitea
Description: description,
})
time.Sleep(100 * time.Millisecond) // THIS IS HERE SO THE GITEA SERVER DOESNT GET HAMMERED WITH REQUESTS
}
}
@Leopere

This comment has been minimized.

Copy link

Leopere commented Dec 11, 2018

# command-line-arguments
./main.go:24:35: unknown field 'Type' in struct literal of type github.ListOptions
@Leopere

This comment has been minimized.

Copy link

Leopere commented Dec 11, 2018

Also for future visitors this is the fix for the redirects issue with the import for the gitea sdk

techknowlogick Today at 10:41 PM
mkdir -p $GOPATH/src/code.gitea.io/
cd $GOPATH/src/code.gitea.io/
git clone https://github.com/go-gitea/go-sdk.git sdk
then dep should work
there is a weird issue with the redirects right now
@Leopere

This comment has been minimized.

Copy link

Leopere commented Dec 11, 2018

Just added the strings to the code and tried running this in GoLand

GOROOT=/usr/local/go #gosetup
GOPATH=/Users/chamunks/go #gosetup
/usr/local/go/bin/go build -o /private/var/folders/t2/86w7z3xd13n82919txs_2v1w0000gn/T/___go_build_main_go -gcflags "all=-N -l" /Users/chamunks/go/src/local/techknowlogick/git-batch-cloner/main.go #gosetup
# command-line-arguments
git-batch-cloner/main.go:24:35: unknown field 'Type' in struct literal of type github.ListOptions

Compilation finished with exit code 2```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.