mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Fix latest version error (#3648)
This commit is contained in:
@@ -113,7 +113,6 @@ type LatestRelease struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeGithubRequest(ctx context.Context, url string, output interface{}) error {
|
func makeGithubRequest(ctx context.Context, url string, output interface{}) error {
|
||||||
|
|
||||||
transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
|
transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
|
||||||
|
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
@@ -124,6 +123,7 @@ func makeGithubRequest(ctx context.Context, url string, output interface{}) erro
|
|||||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
|
|
||||||
req.Header.Add("Accept", apiAcceptHeader) // gh api recommendation , send header with api version
|
req.Header.Add("Accept", apiAcceptHeader) // gh api recommendation , send header with api version
|
||||||
|
logger.Debugf("Github API request: %s", url)
|
||||||
response, err := client.Do(req)
|
response, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -229,19 +229,39 @@ func GetLatestRelease(ctx context.Context) (*LatestRelease, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getReleaseHash(ctx context.Context, tagName string) (string, error) {
|
func getReleaseHash(ctx context.Context, tagName string) (string, error) {
|
||||||
url := apiTags
|
// Start with a small page size if not searching for latest_develop
|
||||||
tags := []githubTagResponse{}
|
perPage := 10
|
||||||
err := makeGithubRequest(ctx, url, &tags)
|
if tagName == developmentTag {
|
||||||
if err != nil {
|
perPage = 100
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tag := range tags {
|
// Limit to 5 pages, ie 500 tags - should be plenty
|
||||||
if tag.Name == tagName {
|
for page := 1; page <= 5; {
|
||||||
if len(tag.Commit.Sha) != 40 {
|
url := fmt.Sprintf("%s?per_page=%d&page=%d", apiTags, perPage, page)
|
||||||
return "", errors.New("invalid Github API response")
|
tags := []githubTagResponse{}
|
||||||
|
err := makeGithubRequest(ctx, url, &tags)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag.Name == tagName {
|
||||||
|
if len(tag.Commit.Sha) != 40 {
|
||||||
|
return "", errors.New("invalid Github API response")
|
||||||
|
}
|
||||||
|
return tag.Commit.Sha, nil
|
||||||
}
|
}
|
||||||
return tag.Commit.Sha, nil
|
}
|
||||||
|
|
||||||
|
if len(tags) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// if not found in the first 10, search again on page 1 with the first 100
|
||||||
|
if perPage == 10 {
|
||||||
|
perPage = 100
|
||||||
|
} else {
|
||||||
|
page++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user