-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathgithub.go
More file actions
66 lines (54 loc) · 1.39 KB
/
Copy pathgithub.go
File metadata and controls
66 lines (54 loc) · 1.39 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
package link
import (
"net/url"
"strings"
"github.com/pkg/errors"
)
type github struct{}
// Github service.
var Github = &github{}
func (s *github) ID() string {
return "github"
}
func (s *github) NormalizeURLString(name string, urs string) (string, error) {
return basicURLString(strings.ToLower(urs))
}
func (s *github) ValidateURLString(name string, urs string) (string, error) {
u, err := url.Parse(urs)
if err != nil {
return "", err
}
if u.Scheme != "https" {
return "", errors.Errorf("invalid scheme for url %s", u)
}
if u.Host != "gist.github.com" {
return "", errors.Errorf("invalid host for url %s", u)
}
path := u.Path
path = strings.TrimPrefix(path, "/")
paths := strings.Split(path, "/")
if len(paths) != 2 {
return "", errors.Errorf("path invalid %s for url %s", paths, u)
}
if paths[0] != name {
return "", errors.Errorf("path invalid (name mismatch) %s != %s", paths[0], name)
}
return u.String(), nil
}
func (s *github) NormalizeName(name string) string {
name = strings.ToLower(name)
return name
}
func (s *github) ValidateName(name string) error {
ok := isAlphaNumericWithDash(name)
if !ok {
return errors.Errorf("name has an invalid character")
}
if len(name) > 39 {
return errors.Errorf("github name is too long, it must be less than 40 characters")
}
return nil
}
func (s *github) CheckContent(name string, b []byte) ([]byte, error) {
return b, nil
}