@@ -11,7 +11,8 @@ import (
1111)
1212
1313const (
14- latestURLPattern = "https://api.github.com/repos/%s/releases/latest"
14+ latestReleaseURLPattern = "https://api.github.com/repos/%s/releases/latest"
15+ latestTagURLPattern = "https://api.github.com/repos/%s/tags"
1516)
1617
1718func LatestRelease (client * resty.Client , repo string , quiet bool ) (* types.GithubRelease , error ) {
@@ -26,16 +27,37 @@ func LatestRelease(client *resty.Client, repo string, quiet bool) (*types.Github
2627 }
2728 ghc = ghc .SetAuthToken (t )
2829 }
29- _ , err := ghc .Get (latestURL (repo ))
30+ _ , err := ghc .Get (latestReleaseURL (repo ))
3031 if err != nil {
3132 return nil , http .CheckError (err )
3233 }
34+
35+ if ghr .TagName == "" {
36+ ght := & types.GithubTags {}
37+ ghc .SetResult (ght )
38+ _ , err := ghc .Get (latestTagURL (repo ))
39+ if err != nil {
40+ return nil , http .CheckError (err )
41+ }
42+
43+ if latest := ght .GetLatest (); latest != nil {
44+ ghr .TagName = latest .Name
45+ }
46+ }
47+
3348 return ghr , nil
3449}
3550
36- func latestURL (repo string ) string {
51+ func latestReleaseURL (repo string ) string {
52+ if repo != "" {
53+ return fmt .Sprintf (latestReleaseURLPattern , repo )
54+ }
55+ return ""
56+ }
57+
58+ func latestTagURL (repo string ) string {
3759 if repo != "" {
38- return fmt .Sprintf (latestURLPattern , repo )
60+ return fmt .Sprintf (latestTagURLPattern , repo )
3961 }
4062 return ""
4163}
0 commit comments