/
gitea.go
58 lines (49 loc) · 1.46 KB
/
gitea.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
}