-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathrepositories.go
More file actions
81 lines (72 loc) · 2.1 KB
/
repositories.go
File metadata and controls
81 lines (72 loc) · 2.1 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"log"
"net/http"
forgejo "codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2"
"github.com/google/go-github/v34/github"
bitbucket "github.com/ktrysmt/go-bitbucket"
gitlab "github.com/xanzy/go-gitlab"
)
// Response is derived from the following sources:
// https://github.com/google/go-github/blob/27c7c32b6d369610435bd2ad7b4d8554f235eb01/github/github.go#L301
// https://github.com/xanzy/go-gitlab/blob/3acf8d75e9de17ad4b41839a7cabbf2537760ab4/gitlab.go#L286
type Response struct {
*http.Response
// These fields provide the page values for paginating through a set of
// results. Any or all of these may be set to the zero value for
// responses that are not part of a paginated set, or for which there
// are no additional pages.
NextPage int
PrevPage int
FirstPage int
LastPage int
}
// Repository represents a git repository to be backed up
type Repository struct {
CloneURL string
Name string
Namespace string
Private bool
}
// getRepositories retrieves all repositories from the specified git service
// that match the given criteria (repo type, visibility, membership, etc.)
func getRepositories(
client interface{},
service string, githubRepoType string, githubNamespaceWhitelist []string,
gitlabProjectVisibility string, gitlabProjectMembershipType string,
ignoreFork bool, forgejoRepoType string,
) ([]*Repository, error) {
if client == nil {
log.Fatalf("Couldn't acquire a client to talk to %s", service)
}
var repositories []*Repository
var err error
switch service {
case "github":
repositories, err = getGithubRepositories(
client.(*github.Client),
githubRepoType,
githubNamespaceWhitelist,
ignoreFork,
)
case "gitlab":
repositories, err = getGitlabRepositories(
client.(*gitlab.Client),
gitlabProjectVisibility,
gitlabProjectMembershipType,
ignoreFork,
)
case "bitbucket":
repositories, err = getBitbucketRepositories(
client.(*bitbucket.Client),
ignoreFork,
)
case "forgejo":
repositories, err = getForgejoRepositories(
client.(*forgejo.Client),
forgejoRepoType,
ignoreFork,
)
}
return repositories, err
}