vcsurl

package module
v0.0.0-...-2305ecc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2016 License: BSD-2-Clause Imports: 6 Imported by: 33

README

============================================= go-vcsurl - Lenient VCS repository URL parser

status

go-vcsurl parses VCS repository URLs in many common formats.

Note: the public API is experimental and subject to change until further notice.

Usage

Documentation: go-vcsurl on Sourcegraph.

Example: example_test.go (Sourcegraph):

package vcsurl_test

import (
	"fmt"
	"gopkg.in/sourcegraph/go-vcsurl.v1"
)

func ExampleParse() {
	urls := []string{
		"github.com/alice/libfoo",
		"git://github.com/bob/libbar",
		"code.google.com/p/libqux",
		"https://code.google.com/p/libbaz",
	}
	for i, url := range urls {
		if info, err := vcsurl.Parse(url); err == nil {
			fmt.Printf("%d. %s %s\n", i+1, info.VCS, info.CloneURL)
			fmt.Printf("   name: %s\n", info.Name)
			fmt.Printf("   host: %s\n", info.RepoHost)
		} else {
			fmt.Printf("error parsing %s\n")
		}
	}

	// output:
	// 1. git git://github.com/alice/libfoo.git
	//    name: libfoo
	//    host: github.com
	// 2. git git://github.com/bob/libbar.git
	//    name: libbar
	//    host: github.com
	// 3. hg https://code.google.com/p/libqux
	//    name: libqux
	//    host: code.google.com
	// 4. hg https://code.google.com/p/libbaz
	//    name: libbaz
	//    host: code.google.com
}

Running tests

Run go test.

Contributors

Documentation

Overview

Package vcsurl parses VCS repository URLs in many common formats.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RepoHost

type RepoHost string
const (
	GitHub     RepoHost = "github.com"
	Bitbucket  RepoHost = "bitbucket.org"
	GoogleCode RepoHost = "code.google.com"
	PythonOrg  RepoHost = "hg.python.org"
	Launchpad  RepoHost = "launchpad.net"
)

type RepoInfo

type RepoInfo struct {
	CloneURL string   // clone URL
	VCS      VCS      // VCS type
	RepoHost RepoHost // repo hosting site
	Username string   // username of repo owner on repo hosting site
	Name     string   // base name of repo on repo hosting site
	FullName string   // full name of repo on repo hosting site
	Rev      string   // a specific revision (commit ID, branch, etc.)
}

RepoInfo describes a VCS repository.

func Parse

func Parse(spec string) (info *RepoInfo, err error)

Parses a string that resembles a VCS repository URL. See TestParse for a list of supported URL formats.

Example
urls := []string{
	"github.com/alice/libfoo",
	"git://github.com/bob/libbar",
	"code.google.com/p/libqux",
	"https://code.google.com/p/libbaz",
}
for i, url := range urls {
	if info, err := vcsurl.Parse(url); err == nil {
		fmt.Printf("%d. %s %s\n", i+1, info.VCS, info.CloneURL)
		fmt.Printf("   name: %s\n", info.Name)
		fmt.Printf("   host: %s\n", info.RepoHost)
	} else {
		fmt.Printf("error parsing %s\n")
	}
}
Output:

1. git git://github.com/alice/libfoo.git
   name: libfoo
   host: github.com
2. git git://github.com/bob/libbar.git
   name: libbar
   host: github.com
3. hg https://code.google.com/p/libqux
   name: libqux
   host: code.google.com
4. hg https://code.google.com/p/libbaz
   name: libbaz
   host: code.google.com
func (r *RepoInfo) Link() string

Link returns the URL to the repository that is intended for access by humans using a Web browser (i.e., not the URL to the API resource).

type VCS

type VCS string
const (
	Git       VCS = "git"
	Mercurial VCS = "hg"
	Bazaar    VCS = "bzr"
)

func (*VCS) Scan

func (x *VCS) Scan(v interface{}) error

Scan implements database/sql.Scanner.

func (VCS) Value

func (x VCS) Value() (driver.Value, error)

Scan implements database/sql/driver.Valuer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL