2019-07-27 00:16:03 +00:00
|
|
|
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"`
|
2019-07-27 16:48:06 +00:00
|
|
|
UID int64 `json:"uid"`
|
2019-07-27 00:16:03 +00:00
|
|
|
Wiki bool `json:"wiki"`
|
|
|
|
}
|
|
|
|
|
2019-08-04 12:34:54 +00:00
|
|
|
func createMigrationRequestFromGithubRepo(gr *github.Repository, repoMapping *mapping) createMigrationRequest {
|
2019-07-27 00:16:03 +00:00
|
|
|
cmr := createMigrationRequest{
|
|
|
|
CloneAddr: strFromPtr(gr.CloneURL),
|
|
|
|
Description: strFromPtr(gr.Description),
|
|
|
|
Issues: boolFromPtr(gr.HasIssues),
|
2019-07-27 18:25:39 +00:00
|
|
|
Mirror: !cfg.NoMirror,
|
2019-07-27 00:16:03 +00:00
|
|
|
Private: boolFromPtr(gr.Private),
|
|
|
|
PullRequests: boolFromPtr(gr.HasIssues),
|
|
|
|
RepoName: strFromPtr(gr.Name),
|
2019-08-04 12:34:54 +00:00
|
|
|
UID: repoMapping.TargetUser,
|
2019-07-27 00:16:03 +00:00
|
|
|
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
|
|
|
|
}
|