@@ -25,10 +25,28 @@ var (
2525// Sync checks the releases of upstream repository (owner, repo)
2626// with the given repo, and creates the missing latest tags from upstream.
2727func Sync (ctx context.Context , client * github.Client , owner , repo , upstreamOwner , upstreamRepo , tagPrefix string , dryrun bool ) error {
28- // retrieve the last 150 upstream releases
29- upstreamTags , _ , err := client .Repositories .ListTags (ctx , upstreamOwner , upstreamRepo , & github.ListOptions {PerPage : 150 })
30- if err != nil {
31- return fmt .Errorf ("failed to retrieve '%s/%s' tags: %v" , upstreamOwner , upstreamRepo , err )
28+
29+ logrus .Infof ("Retrieving all upstream tags for '%s/%s'..." , upstreamOwner , upstreamRepo )
30+
31+ // This slice will hold all tags gathered from all pages.
32+ var upstreamTags []* github.RepositoryTag
33+ opt := & github.ListOptions {PerPage : 100 }
34+
35+ for {
36+ tagsPage , resp , err := client .Repositories .ListTags (ctx , upstreamOwner , upstreamRepo , opt )
37+ if err != nil {
38+ return fmt .Errorf ("failed to retrieve page %d of '%s/%s' tags: %w" , opt .Page , upstreamOwner , upstreamRepo , err )
39+ }
40+
41+ upstreamTags = append (upstreamTags , tagsPage ... )
42+
43+ // If NextPage is 0 there's no more tags to retrieve so we can break out of the loop
44+ if resp .NextPage == 0 {
45+ break
46+ }
47+
48+ // set the page for the next iteration.
49+ opt .Page = resp .NextPage
3250 }
3351
3452 if len (upstreamTags ) == 0 {
@@ -79,7 +97,7 @@ func Sync(ctx context.Context, client *github.Client, owner, repo, upstreamOwner
7997 }
8098
8199 // skip current upstream release if not GA
82- if strings .Contains (upstreamTagName , "rc" ) || strings .Contains (upstreamTagName , "alpha" ) || strings .Contains (upstreamTagName , "beta" ) {
100+ if strings .Contains (upstreamTagName , "rc" ) || strings .Contains (upstreamTagName , "alpha" ) || strings .Contains (upstreamTagName , "beta" ) || strings . Contains ( upstreamTagName , "dev" ) {
83101 continue
84102 }
85103
@@ -179,10 +197,21 @@ func validateTagFormat(tagName, tagPrefix string) bool {
179197 }
180198
181199 // semver library to validate the version string, if it contains a prefix (besides 'v' it fails).
182- if _ , err := semver .NewVersion (versionStr ); err != nil {
200+ v , err := semver .NewVersion (versionStr )
201+ if err != nil {
183202 // If parsing fails, it's not a valid semantic version.
184203 return false
185204 }
186205
206+ // this checks for any suffix that a tag may have, and we ignore those with suffixes:
207+ // example:
208+ // - v3.21.1 <------------ correct
209+ // - v3.21.1-typha <------ will be skipped
210+ // - v3.21.1-pod2daemon <- will be skipped
211+ // - v3.24.2-0.dev <------ will be skipped
212+ if v .Prerelease () != "" {
213+ return false
214+ }
215+
187216 return true
188217}
0 commit comments