/
repository.go
49 lines (41 loc) · 928 Bytes
/
repository.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
package gitea
import (
"fmt"
"net/url"
"code.gitea.io/sdk/gitea"
)
func (g *Gitea) convertRepository(repo *gitea.Repository) (repository, error) {
var repoURL string
if g.SSHAuth {
repoURL = repo.SSHURL
} else {
u, err := url.Parse(repo.CloneURL)
if err != nil {
return repository{}, err
}
// Set the token as https://oauth2:TOKEN@url
u.User = url.UserPassword("oauth2", g.token)
repoURL = u.String()
}
return repository{
url: repoURL,
name: repo.Name,
ownerName: repo.Owner.UserName,
defaultBranch: repo.DefaultBranch,
}, nil
}
type repository struct {
url string
name string
ownerName string
defaultBranch string
}
func (r repository) CloneURL() string {
return r.url
}
func (r repository) DefaultBranch() string {
return r.defaultBranch
}
func (r repository) FullName() string {
return fmt.Sprintf("%s/%s", r.ownerName, r.name)
}