Added repo parsing

This commit is contained in:
Jguer 2017-05-01 02:23:03 +01:00
parent 38617c2781
commit acf2a33a68
2 changed files with 63 additions and 0 deletions

30
aur/github/github.go Normal file
View file

@ -0,0 +1,30 @@
package github
import "strings"
// Branches contains the information of a repository branch
type Branches []struct {
Name string `json:"name"`
Commit struct {
Sha string `json:"sha"`
URL string `json:"url"`
} `json:"commit"`
}
const repoAPI = "https://api.github.com/repos/{USER}/{REPOSITORY}/branches"
func parseSource(source string) (owner string, repo string) {
split := strings.Split(source, "github.com/")
if len(split) > 1 {
secondSplit := strings.Split(split[1], "/")
if len(secondSplit) > 1 {
owner = secondSplit[0]
thirdSplit := strings.Split(secondSplit[1], ".git")
if len(thirdSplit) > 0 {
repo = thirdSplit[0]
}
}
}
return
}

33
aur/github/github_test.go Normal file
View file

@ -0,0 +1,33 @@
package github
import (
"testing"
)
func TestParsing(t *testing.T) {
type source struct {
sourceurl string
owner string
repo string
}
neovim := source{sourceurl: "git+https://github.com/neovim/neovim.git"}
neovim.owner, neovim.repo = parseSource(neovim.sourceurl)
if neovim.owner != "neovim" || neovim.repo != "neovim" {
t.Fatalf("Expected to find neovim/neovim, found %+v/%+v", neovim.owner, neovim.repo)
}
yay := source{sourceurl: "git://github.com/jguer/yay.git#branch=master"}
yay.owner, yay.repo = parseSource(yay.sourceurl)
if yay.owner != "jguer" || yay.repo != "yay" {
t.Fatalf("Expected to find jguer/yay, found %+v/%+v", yay.owner, yay.repo)
}
ack := source{sourceurl: "git://github.com/davidgiven/ack"}
ack.owner, ack.repo = parseSource(ack.sourceurl)
if ack.owner != "davidgiven" || ack.repo != "ack" {
t.Fatalf("Expected to find davidgiven/ack, found %+v/%+v", ack.owner, ack.repo)
}
}