|
@@ -10,9 +10,11 @@ import (
|
|
|
|
|
|
// branch contains the information of a repository branch
|
|
|
type branch struct {
|
|
|
- Name string `json:"name"`
|
|
|
- SHA string `json:"sha"`
|
|
|
- URL string `json:"url"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Commit struct {
|
|
|
+ SHA string `json:"sha"`
|
|
|
+ URL string `json:"url"`
|
|
|
+ } `json:"commit"`
|
|
|
}
|
|
|
|
|
|
type branches []branch
|
|
@@ -29,11 +31,16 @@ type infos []Info
|
|
|
var savedInfo infos
|
|
|
var configfile string
|
|
|
|
|
|
+// Updated returns if database has been updated
|
|
|
+var Updated bool
|
|
|
+
|
|
|
func init() {
|
|
|
+ Updated = false
|
|
|
configfile = os.Getenv("HOME") + "/.config/yay/yay_vcs.json"
|
|
|
|
|
|
if _, err := os.Stat(configfile); os.IsNotExist(err) {
|
|
|
_ = os.MkdirAll(os.Getenv("HOME")+"/.config/yay", 0755)
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
file, err := os.Open(configfile)
|
|
@@ -50,6 +57,11 @@ func init() {
|
|
|
|
|
|
// ParseSource returns owner and repo from source
|
|
|
func ParseSource(source string) (owner string, repo string) {
|
|
|
+ if !(strings.Contains(source, "git://") ||
|
|
|
+ strings.Contains(source, ".git") ||
|
|
|
+ strings.Contains(source, "git+https://")) {
|
|
|
+ return
|
|
|
+ }
|
|
|
split := strings.Split(source, "github.com/")
|
|
|
if len(split) > 1 {
|
|
|
secondSplit := strings.Split(split[1], "/")
|
|
@@ -81,7 +93,7 @@ func (info *Info) needsUpdate() bool {
|
|
|
|
|
|
for _, e := range newRepo {
|
|
|
if e.Name == "master" {
|
|
|
- if e.SHA != info.SHA {
|
|
|
+ if e.Commit.SHA != info.SHA {
|
|
|
return true
|
|
|
} else {
|
|
|
return false
|
|
@@ -100,9 +112,9 @@ func CheckUpdates() (toUpdate []string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func inStore(pkgname string) *Info {
|
|
|
+func inStore(url string) *Info {
|
|
|
for i, e := range savedInfo {
|
|
|
- if pkgname == e.Package {
|
|
|
+ if url == e.URL {
|
|
|
return &savedInfo[i]
|
|
|
}
|
|
|
}
|
|
@@ -111,6 +123,7 @@ func inStore(pkgname string) *Info {
|
|
|
|
|
|
// BranchInfo updates saved information
|
|
|
func BranchInfo(pkgname string, owner string, repo string) (err error) {
|
|
|
+ Updated = true
|
|
|
var newRepo branches
|
|
|
url := "https://api.github.com/repos/" + owner + "/" + repo + "/branches"
|
|
|
r, err := http.Get(url)
|
|
@@ -121,16 +134,16 @@ func BranchInfo(pkgname string, owner string, repo string) (err error) {
|
|
|
|
|
|
_ = json.NewDecoder(r.Body).Decode(&newRepo)
|
|
|
|
|
|
- packinfo := inStore(pkgname)
|
|
|
+ packinfo := inStore(url)
|
|
|
|
|
|
for _, e := range newRepo {
|
|
|
if e.Name == "master" {
|
|
|
if packinfo != nil {
|
|
|
packinfo.Package = pkgname
|
|
|
packinfo.URL = url
|
|
|
- packinfo.SHA = e.SHA
|
|
|
+ packinfo.SHA = e.Commit.SHA
|
|
|
} else {
|
|
|
- savedInfo = append(savedInfo, Info{Package: pkgname, URL: url, SHA: e.SHA})
|
|
|
+ savedInfo = append(savedInfo, Info{Package: pkgname, URL: url, SHA: e.Commit.SHA})
|
|
|
}
|
|
|
}
|
|
|
}
|