Skip to content

Commit

Permalink
Merge pull request #3 from mona-actions/amenocal/pagination
Browse files Browse the repository at this point in the history
adds pagination, removes fatal
  • Loading branch information
amenocal authored Jul 16, 2024
2 parents aa71c45 + 3f0b8f6 commit d88371e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 16 additions & 4 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,24 @@ func GetSourceRepositoryReleases() ([]*github.RepositoryRelease, error) {
client := newGHRestClient(viper.GetString("source_token"), viper.GetString("source_hostname"))

ctx := context.WithValue(context.Background(), github.SleepUntilPrimaryRateLimitResetWhenRateLimited, true)
releases, _, err := client.Repositories.ListReleases(ctx, viper.Get("SOURCE_ORGANIZATION").(string), viper.Get("REPOSITORY").(string), &github.ListOptions{})
if err != nil {
return nil, fmt.Errorf("error getting releases: %v", err)

var allReleases []*github.RepositoryRelease
opts := &github.ListOptions{PerPage: 100}

for {
releases, resp, err := client.Repositories.ListReleases(ctx, viper.Get("SOURCE_ORGANIZATION").(string), viper.Get("REPOSITORY").(string), opts)
if err != nil {
return allReleases, fmt.Errorf("error getting releases: %v", err)
}
allReleases = append(allReleases, releases...)
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}

return releases, nil
return allReleases, nil

}

func DownloadReleaseAssets(asset *github.ReleaseAsset) error {
Expand Down
5 changes: 3 additions & 2 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sync

import (
"fmt"
"strings"

"github.com/mona-actions/gh-migrate-releases/internal/api"
Expand All @@ -17,7 +18,7 @@ func SyncReleases() {
pterm.Error.Printf("Error getting releases: %v", err)
fetchReleasesSpinner.Fail()
}
fetchReleasesSpinner.UpdateText("Releases fetched successfully!")
fetchReleasesSpinner.UpdateText(fmt.Sprintf(" %d Releases fetched successfully!", len(releases)))
fetchReleasesSpinner.Success()

// Create releases in target repository
Expand All @@ -44,7 +45,7 @@ func SyncReleases() {
continue
} else {
createReleasesSpinner.Fail()
pterm.Fatal.Printf("Error creating release: %v", err)
pterm.Warning.Printf("Error creating release: %v", err)
}
}
// Download assets from source repository and upload to target repository
Expand Down

0 comments on commit d88371e

Please sign in to comment.