forked from gitsight/go-vcsurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
54 lines (45 loc) · 1.21 KB
/
example_test.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
package vcsurl_test
import (
"fmt"
"github.com/gitsight/go-vcsurl"
)
func ExampleParse() {
urls := []string{
"github.com/alice/libfoo",
"git://github.com/bob/libbar",
"https://gitlab.com/foo/bar",
"https://github.com/go-enry/go-enry/releases/tag/v2.4.1",
}
for i, url := range urls {
info, err := vcsurl.Parse(url)
if err != nil {
fmt.Printf("error parsing %s\n", err)
}
fmt.Printf("%d. %s %s\n", i+1, info.Kind, info.ID)
fmt.Printf(" name: %s\n", info.Name)
fmt.Printf(" host: %s\n", info.Host)
remote, _ := info.Remote(vcsurl.SSH)
fmt.Printf(" remote: %s\n", remote)
if info.Committish != "" {
fmt.Printf(" commit-ish: %s\n", info.Committish)
}
}
// output:
// 1. git github.com/alice/libfoo
// name: libfoo
// host: github.com
// remote: [email protected]:alice/libfoo.git
// 2. git github.com/bob/libbar
// name: libbar
// host: github.com
// remote: [email protected]:bob/libbar.git
// 3. git gitlab.com/foo/bar
// name: bar
// host: gitlab.com
// remote: [email protected]:foo/bar.git
// 4. git github.com/go-enry/go-enry
// name: go-enry
// host: github.com
// remote: [email protected]:go-enry/go-enry.git
// commit-ish: v2.4.1
}