mirror of
https://github.com/Luzifer/github2gitea.git
synced 2024-11-14 09:52:48 +00:00
Knut Ahlers
494dbf16dd
in order to speed up the execution and to lower the need of Github tokens. Instead of running the tool multiple times it can now be run once while specifying more than one mapping using a mapping file. Signed-off-by: Knut Ahlers <knut@ahlers.me>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/google/go-github/github"
|
|
)
|
|
|
|
type createMigrationRequest struct {
|
|
AuthPassword string `json:"auth_password"`
|
|
AuthUsername string `json:"auth_username"`
|
|
CloneAddr string `json:"clone_addr"`
|
|
Description string `json:"description"`
|
|
Issues bool `json:"issues"`
|
|
//Labels bool `json:"labels"`
|
|
//Milestones bool `json:"milestones"`
|
|
Mirror bool `json:"mirror"`
|
|
Private bool `json:"private"`
|
|
PullRequests bool `json:"pull_requests"`
|
|
//Releases bool `json:"releases"`
|
|
RepoName string `json:"repo_name"`
|
|
UID int64 `json:"uid"`
|
|
Wiki bool `json:"wiki"`
|
|
}
|
|
|
|
func createMigrationRequestFromGithubRepo(gr *github.Repository, repoMapping *mapping) createMigrationRequest {
|
|
cmr := createMigrationRequest{
|
|
CloneAddr: strFromPtr(gr.CloneURL),
|
|
Description: strFromPtr(gr.Description),
|
|
Issues: boolFromPtr(gr.HasIssues),
|
|
Mirror: !cfg.NoMirror,
|
|
Private: boolFromPtr(gr.Private),
|
|
PullRequests: boolFromPtr(gr.HasIssues),
|
|
RepoName: strFromPtr(gr.Name),
|
|
UID: repoMapping.TargetUser,
|
|
Wiki: boolFromPtr(gr.HasWiki),
|
|
}
|
|
|
|
if boolFromPtr(gr.Private) {
|
|
uri, _ := url.Parse(strFromPtr(gr.CloneURL))
|
|
uri.User = url.UserPassword("api", cfg.GithubToken)
|
|
cmr.CloneAddr = uri.String()
|
|
}
|
|
|
|
return cmr
|
|
}
|
|
|
|
func boolFromPtr(in *bool) bool {
|
|
return in != nil && *in
|
|
}
|
|
|
|
func strFromPtr(in *string) string {
|
|
if in == nil {
|
|
return ""
|
|
}
|
|
|
|
return *in
|
|
}
|