mirror of
https://github.com/Jguer/yay
synced 2024-09-14 13:51:12 +00:00
Make devel operations respect default branch
This commit is contained in:
parent
7b2b2fb7bc
commit
7471478352
189
vcs.go
189
vcs.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// branch contains the information of a repository branch
|
// branch contains the information of a repository branch
|
||||||
|
@ -29,6 +30,125 @@ type Info struct {
|
||||||
|
|
||||||
type infos []Info
|
type infos []Info
|
||||||
|
|
||||||
|
// Repo contains information about the repository
|
||||||
|
type repo struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Owner struct {
|
||||||
|
Login string `json:"login"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GravatarID string `json:"gravatar_id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
FollowersURL string `json:"followers_url"`
|
||||||
|
FollowingURL string `json:"following_url"`
|
||||||
|
GistsURL string `json:"gists_url"`
|
||||||
|
StarredURL string `json:"starred_url"`
|
||||||
|
SubscriptionsURL string `json:"subscriptions_url"`
|
||||||
|
OrganizationsURL string `json:"organizations_url"`
|
||||||
|
ReposURL string `json:"repos_url"`
|
||||||
|
EventsURL string `json:"events_url"`
|
||||||
|
ReceivedEventsURL string `json:"received_events_url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
SiteAdmin bool `json:"site_admin"`
|
||||||
|
} `json:"owner"`
|
||||||
|
Private bool `json:"private"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Fork bool `json:"fork"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
ForksURL string `json:"forks_url"`
|
||||||
|
KeysURL string `json:"keys_url"`
|
||||||
|
CollaboratorsURL string `json:"collaborators_url"`
|
||||||
|
TeamsURL string `json:"teams_url"`
|
||||||
|
HooksURL string `json:"hooks_url"`
|
||||||
|
IssueEventsURL string `json:"issue_events_url"`
|
||||||
|
EventsURL string `json:"events_url"`
|
||||||
|
AssigneesURL string `json:"assignees_url"`
|
||||||
|
BranchesURL string `json:"branches_url"`
|
||||||
|
TagsURL string `json:"tags_url"`
|
||||||
|
BlobsURL string `json:"blobs_url"`
|
||||||
|
GitTagsURL string `json:"git_tags_url"`
|
||||||
|
GitRefsURL string `json:"git_refs_url"`
|
||||||
|
TreesURL string `json:"trees_url"`
|
||||||
|
StatusesURL string `json:"statuses_url"`
|
||||||
|
LanguagesURL string `json:"languages_url"`
|
||||||
|
StargazersURL string `json:"stargazers_url"`
|
||||||
|
ContributorsURL string `json:"contributors_url"`
|
||||||
|
SubscribersURL string `json:"subscribers_url"`
|
||||||
|
SubscriptionURL string `json:"subscription_url"`
|
||||||
|
CommitsURL string `json:"commits_url"`
|
||||||
|
GitCommitsURL string `json:"git_commits_url"`
|
||||||
|
CommentsURL string `json:"comments_url"`
|
||||||
|
IssueCommentURL string `json:"issue_comment_url"`
|
||||||
|
ContentsURL string `json:"contents_url"`
|
||||||
|
CompareURL string `json:"compare_url"`
|
||||||
|
MergesURL string `json:"merges_url"`
|
||||||
|
ArchiveURL string `json:"archive_url"`
|
||||||
|
DownloadsURL string `json:"downloads_url"`
|
||||||
|
IssuesURL string `json:"issues_url"`
|
||||||
|
PullsURL string `json:"pulls_url"`
|
||||||
|
MilestonesURL string `json:"milestones_url"`
|
||||||
|
NotificationsURL string `json:"notifications_url"`
|
||||||
|
LabelsURL string `json:"labels_url"`
|
||||||
|
ReleasesURL string `json:"releases_url"`
|
||||||
|
DeploymentsURL string `json:"deployments_url"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
PushedAt time.Time `json:"pushed_at"`
|
||||||
|
GitURL string `json:"git_url"`
|
||||||
|
SSHURL string `json:"ssh_url"`
|
||||||
|
CloneURL string `json:"clone_url"`
|
||||||
|
SvnURL string `json:"svn_url"`
|
||||||
|
Homepage string `json:"homepage"`
|
||||||
|
Size int `json:"size"`
|
||||||
|
StargazersCount int `json:"stargazers_count"`
|
||||||
|
WatchersCount int `json:"watchers_count"`
|
||||||
|
Language string `json:"language"`
|
||||||
|
HasIssues bool `json:"has_issues"`
|
||||||
|
HasProjects bool `json:"has_projects"`
|
||||||
|
HasDownloads bool `json:"has_downloads"`
|
||||||
|
HasWiki bool `json:"has_wiki"`
|
||||||
|
HasPages bool `json:"has_pages"`
|
||||||
|
ForksCount int `json:"forks_count"`
|
||||||
|
MirrorURL interface{} `json:"mirror_url"`
|
||||||
|
Archived bool `json:"archived"`
|
||||||
|
OpenIssuesCount int `json:"open_issues_count"`
|
||||||
|
License struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SpdxID interface{} `json:"spdx_id"`
|
||||||
|
URL interface{} `json:"url"`
|
||||||
|
} `json:"license"`
|
||||||
|
Forks int `json:"forks"`
|
||||||
|
OpenIssues int `json:"open_issues"`
|
||||||
|
Watchers int `json:"watchers"`
|
||||||
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
Organization struct {
|
||||||
|
Login string `json:"login"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GravatarID string `json:"gravatar_id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
FollowersURL string `json:"followers_url"`
|
||||||
|
FollowingURL string `json:"following_url"`
|
||||||
|
GistsURL string `json:"gists_url"`
|
||||||
|
StarredURL string `json:"starred_url"`
|
||||||
|
SubscriptionsURL string `json:"subscriptions_url"`
|
||||||
|
OrganizationsURL string `json:"organizations_url"`
|
||||||
|
ReposURL string `json:"repos_url"`
|
||||||
|
EventsURL string `json:"events_url"`
|
||||||
|
ReceivedEventsURL string `json:"received_events_url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
SiteAdmin bool `json:"site_admin"`
|
||||||
|
} `json:"organization"`
|
||||||
|
NetworkCount int `json:"network_count"`
|
||||||
|
SubscribersCount int `json:"subscribers_count"`
|
||||||
|
}
|
||||||
|
|
||||||
// createDevelDB forces yay to create a DB of the existing development packages
|
// createDevelDB forces yay to create a DB of the existing development packages
|
||||||
func createDevelDB() error {
|
func createDevelDB() error {
|
||||||
_, _, _, remoteNames, err := filterPackages()
|
_, _, _, remoteNames, err := filterPackages()
|
||||||
|
@ -66,24 +186,46 @@ func parseSource(source string) (owner string, repo string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *Info) needsUpdate() bool {
|
func (info *Info) needsUpdate() bool {
|
||||||
var newRepo branches
|
var newRepo repo
|
||||||
r, err := http.Get(info.URL)
|
var newBranches branches
|
||||||
if err != nil {
|
if strings.HasSuffix(info.URL, "/branches") {
|
||||||
fmt.Println(err)
|
info.URL = info.URL[:len(info.URL)-9]
|
||||||
|
}
|
||||||
|
infoResp, infoErr := http.Get(info.URL)
|
||||||
|
if infoErr != nil {
|
||||||
|
fmt.Println(infoErr)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
defer infoResp.Body.Close()
|
||||||
|
|
||||||
body, _ := ioutil.ReadAll(r.Body)
|
infoBody, _ := ioutil.ReadAll(infoResp.Body)
|
||||||
err = json.Unmarshal(body, &newRepo)
|
var err = json.Unmarshal(infoBody, &newRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Cannot update '%v'\nError: %v\nStatus code: %v\nBody: %v\n",
|
fmt.Printf("Cannot update '%v'\nError: %v\nStatus code: %v\nBody: %v\n",
|
||||||
info.Package, err, r.StatusCode, string(body))
|
info.Package, err, infoResp.StatusCode, string(infoBody))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range newRepo {
|
defaultBranch := newRepo.DefaultBranch
|
||||||
if e.Name == "master" {
|
branchesURL := info.URL + "/branches"
|
||||||
|
|
||||||
|
branchResp, branchErr := http.Get(branchesURL)
|
||||||
|
if branchErr != nil {
|
||||||
|
fmt.Println(branchErr)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer branchResp.Body.Close()
|
||||||
|
|
||||||
|
branchBody, _ := ioutil.ReadAll(branchResp.Body)
|
||||||
|
err = json.Unmarshal(branchBody, &newBranches)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Cannot update '%v'\nError: %v\nStatus code: %v\nBody: %v\n",
|
||||||
|
info.Package, err, branchResp.StatusCode, string(branchBody))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, e := range newBranches {
|
||||||
|
if e.Name == defaultBranch {
|
||||||
return e.Commit.SHA != info.SHA
|
return e.Commit.SHA != info.SHA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,22 +242,33 @@ func inStore(pkgName string) *Info {
|
||||||
}
|
}
|
||||||
|
|
||||||
// branchInfo updates saved information
|
// branchInfo updates saved information
|
||||||
func branchInfo(pkgName string, owner string, repo string) (err error) {
|
func branchInfo(pkgName string, owner string, repoName string) (err error) {
|
||||||
updated = true
|
updated = true
|
||||||
var newRepo branches
|
var newRepo repo
|
||||||
url := "https://api.github.com/repos/" + owner + "/" + repo + "/branches"
|
var newBranches branches
|
||||||
r, err := http.Get(url)
|
url := "https://api.github.com/repos/" + owner + "/" + repoName
|
||||||
|
repoResp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
defer repoResp.Body.Close()
|
||||||
|
|
||||||
_ = json.NewDecoder(r.Body).Decode(&newRepo)
|
_ = json.NewDecoder(repoResp.Body).Decode(&newRepo)
|
||||||
|
defaultBranch := newRepo.DefaultBranch
|
||||||
|
branchesUrl := url + "/branches"
|
||||||
|
|
||||||
|
branchResp, err := http.Get(branchesUrl)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer branchResp.Body.Close()
|
||||||
|
|
||||||
|
_ = json.NewDecoder(branchResp.Body).Decode(&newBranches)
|
||||||
|
|
||||||
packinfo := inStore(pkgName)
|
packinfo := inStore(pkgName)
|
||||||
|
|
||||||
for _, e := range newRepo {
|
for _, e := range newBranches {
|
||||||
if e.Name == "master" {
|
if e.Name == defaultBranch {
|
||||||
if packinfo != nil {
|
if packinfo != nil {
|
||||||
packinfo.Package = pkgName
|
packinfo.Package = pkgName
|
||||||
packinfo.URL = url
|
packinfo.URL = url
|
||||||
|
|
Loading…
Reference in a new issue