Skip to content

Commit

Permalink
Merge pull request #247 from cdnjs/increase-graphql-limit
Browse files Browse the repository at this point in the history
Force-update can view last 100 git versions
  • Loading branch information
xtuc authored Aug 20, 2021
2 parents 953d2b9 + 1b5af44 commit 7c7d6fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion functions/force-update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Invoke(w http.ResponseWriter, r *http.Request) {
var versions []version.Version
switch src {
case "git":
versions, err = git.GetVersions(ctx, pkg.Autoupdate)
versions, err = git.GetVersionsWithLimit(ctx, pkg.Autoupdate, 100)
if err != nil {
http.Error(w, "failed to fetch versions", 500)
fmt.Println(err)
Expand Down
8 changes: 6 additions & 2 deletions git/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,17 @@ type GraphQLRequest struct {
// GetVersions gets all of the versions associated with a git repo,
// as well as the latest version.
func GetVersions(ctx context.Context, config *packages.Autoupdate) ([]version.Version, error) {
return GetVersionsWithLimit(ctx, config, 10)
}

func GetVersionsWithLimit(ctx context.Context, config *packages.Autoupdate, limit int) ([]version.Version, error) {
name := *config.Target
repo := getRepo(*config.Target)
parts := strings.Split(repo, "/")
query := GraphQLRequest{Query: fmt.Sprintf(`
query {
repository(name: "%s", owner: "%s") {
refs(refPrefix: "refs/tags/", last: 10) {
refs(refPrefix: "refs/tags/", last: %d) {
nodes {
name
target {
Expand All @@ -129,7 +133,7 @@ query {
}
}
}
`, parts[1], parts[0])}
`, parts[1], parts[0], limit)}

var res GetVersionsRes

Expand Down

0 comments on commit 7c7d6fb

Please sign in to comment.