-
Notifications
You must be signed in to change notification settings - Fork 1
/
submit.go
64 lines (50 loc) · 1.2 KB
/
submit.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
package main
import (
"errors"
"regexp"
"gitlab.com/jfaucherre/mergo/hosts/github"
"gitlab.com/jfaucherre/mergo/hosts/gitlab"
"gitlab.com/jfaucherre/mergo/logger"
"gitlab.com/jfaucherre/mergo/models"
)
var (
ErrHostNotFound = errors.New("host not found")
hosts = map[*regexp.Regexp]func() (models.Host, error){
gitlab.IsHostRegexp: gitlab.New,
github.IsHostRegexp: github.New,
}
)
func GetHost(url string) (models.Host, error) {
logger.Info("searching host for URL: %s\n", url)
for reg, constructor := range hosts {
if reg.MatchString(url) {
return constructor()
}
}
return nil, ErrHostNotFound
}
func SubmitOnRemote(params *models.MRParams) (*models.MRInfo, error) {
logger.Debug("Submitting PR with parameters: %+v\n", params)
host, err := GetHost(params.URL)
if err != nil {
return nil, err
}
infos, err := host.SubmitPr(params)
if err != nil {
return nil, err
}
return infos, nil
}
func SubmitPr(params *models.MRParams, rmts []string) []string {
mrUrls := []string{}
for _, rmt := range rmts {
params.URL = rmt
infos, err := SubmitOnRemote(params)
if err != nil {
logger.Error("%+v\n", err)
continue
}
mrUrls = append(mrUrls, infos.URL)
}
return mrUrls
}