-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.go
62 lines (48 loc) · 2 KB
/
github.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
59
60
61
62
package github
import (
"context"
"gitlab.com/distributed_lab/logan/v3"
"github.com/acs-dl/github-module-svc/internal/config"
"github.com/acs-dl/github-module-svc/internal/data"
"github.com/acs-dl/github-module-svc/internal/service/background"
)
type GithubClient interface {
AddUserFromApi(typeTo, link, username, permission string) (*data.Permission, error)
UpdateUserFromApi(typeTo, link, username, permission string) (*data.Permission, error)
AddOrUpdateUserInRepositoryFromApi(link, username, permission string) (*data.Permission, error)
AddOrUpdateUserInOrganizationFromApi(link, username, permission string) (*data.Permission, error)
GetUsersFromApi(link, typeTo string) ([]data.Permission, error)
GetUserFromApi(username string) (*data.User, error)
RemoveUserFromApi(link, username, typeTo string) error
GetOrganizationFromApi(link string) (*data.Sub, error)
GetRepositoryFromApi(link string) (*data.Sub, error)
CheckUserFromApi(link, username, typeTo string) (*data.Permission, error)
CheckRepositoryCollaborator(link, username string) (*data.Permission, error)
CheckOrganizationCollaborator(link, username string) (*data.Permission, error)
FindType(link string) (*TypeSub, error)
FindRepositoryOwner(link string) (string, error)
SearchByFromApi(username string) ([]data.User, error)
GetProjectsFromApi(link string) ([]data.Sub, error)
}
type TypeSub struct {
Type string
Sub data.Sub
}
type github struct {
superUserToken string
userToken string
log *logan.Entry
}
func NewGithubAsInterface(cfg config.Config, _ context.Context) interface{} {
return interface{}(&github{
superUserToken: cfg.Github().SuperToken,
userToken: cfg.Github().UsualToken,
log: cfg.Log(),
})
}
func GithubClientInstance(ctx context.Context) GithubClient {
return ctx.Value(background.GithubClientCtxKey).(GithubClient)
}
func CtxGithubClientInstance(entry interface{}, ctx context.Context) context.Context {
return context.WithValue(ctx, background.GithubClientCtxKey, entry)
}