-
Notifications
You must be signed in to change notification settings - Fork 2
/
factory.go
81 lines (72 loc) · 1.51 KB
/
factory.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package pkg
import (
"context"
"github.com/sanjid133/gopher-love/pkg/system"
"github.com/sanjid133/gopher-love/util"
"os"
"path/filepath"
"strings"
)
type Love interface {
Initialize(config *system.SecretConfig) (Love, error)
//Decode(url string) (*Repository, error)
GetOrgRepos(org string) ([]*Repository, error)
IsLoved(repo *Repository) (bool, error)
SendLove(repo *Repository) error
}
type LoveBag interface {
Initialize(directory string) LoveBag
File() string
Read() ([]*Repository, error)
}
type Repository struct {
Platform string
Owner string
Name string
Url string
HasMirror bool
MirrorUrl string
}
func DetectManager(ctx context.Context, directory string) string {
//managers := GetAllRegistereredManager()
for m := range manager {
file := manager[m](ctx).File()
if _, err := os.Stat(filepath.Join(directory, file)); err == nil {
return m
}
}
return ""
}
func UrlToRepo(url string) *Repository {
url = strings.TrimPrefix(url, "https://")
repo := &Repository{
Url: url,
}
parts := strings.Split(url, "/")
if len(parts) > 0 {
repo.Platform = util.GetPlatform(parts[0])
}
if len(parts) > 1 {
repo.Owner = parts[1]
}
if len(parts) > 2 {
repo.Name = parts[2]
}
return repo
}
var reaction = []string{
":kissing_heart:",
":kissing_closed_eyes:",
":kissing_smiling_eyes:",
":yellow_heart:",
":blue_heart:",
":purple_heart:",
":heart:",
":green_heart:",
":heartpulse:",
":heartbeat:",
":two_hearts:",
":revolving_hearts:",
":sparkling_heart:",
":gift_heart:",
}