Skip to content

VCS repository URL parsing library for Go

License

Notifications You must be signed in to change notification settings

gitsight/go-vcsurl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-vcsurl GoDoc Test

go-vcsurl library provides a VCS URL parser for HTTP, git or ssh remote URLs and also frontend URLs from providers like GitHub, GitLab, and Bitbucket.

This library is based on the previous work done by @sourcegraph.

Installation

The recommended way to install go-vcsurl

go get github.com/gitsight/go-vcsurl

Usage

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)
	}
}
1. git github.com/alice/libfoo
   name: libfoo
   host: github.com
   remote: git@github.com/alice/libfoo.git
2. git github.com/bob/libbar
   name: libbar
   host: github.com
   remote: git@github.com/bob/libbar.git
3. git gitlab.com/foo/bar
   name: bar
   host: gitlab.com
   remote: git@gitlab.com/foo/bar.git
4. git github.com/go-enry/go-enry
   name: go-enry
   host: github.com
   remote: git@github.com/go-enry/go-enry.git
   commit-ish: v2.4.1

License

MIT, see LICENSE