-
-
Notifications
You must be signed in to change notification settings - Fork 64
Use v4 API for paginating releases in check
#102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc94afc
initial part
kirillbilchenko 492f3c4
Dependency updates and use graphql to list releases
kirillbilchenko 481dc86
Update in graphql link definition and readme definition
kirillbilchenko 4a99706
Cleanup vendor folder
kirillbilchenko 50e52f9
Remove scrip folder and deps
kirillbilchenko 3a30aa3
Moved graphql part to separate helper class
kirillbilchenko c669201
use github v3 for calls without access token and v4 with access token
kirillbilchenko e4a3b91
CR Fixes and fix exportloopref
kirillbilchenko 75dfa0c
Extract rate limit message to constant
kirillbilchenko a619a7b
CR more fixes and id adjustment
kirillbilchenko e746201
Fix tests and update parsing
kirillbilchenko 5615de4
Update tests
kirillbilchenko 67b0d74
Added test for corrupted id
kirillbilchenko 2bd9632
Remove unused print statement
kirillbilchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package resource | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/base64" | ||
| "errors" | ||
| "regexp" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/google/go-github/v32/github" | ||
| "github.com/shurcooL/githubv4" | ||
| ) | ||
|
|
||
| func (g *GitHubClient) listReleasesV4() ([]*github.RepositoryRelease, error) { | ||
| if g.clientV4 == nil { | ||
|
kirillbilchenko marked this conversation as resolved.
|
||
| return nil, errors.New("github graphql is not been initialised") | ||
| } | ||
| var listReleases struct { | ||
| Repository struct { | ||
| Releases struct { | ||
| Edges []struct { | ||
| Node struct { | ||
| ReleaseObject | ||
| } | ||
| } `graphql:"edges"` | ||
| PageInfo struct { | ||
| EndCursor githubv4.String | ||
| HasNextPage bool | ||
| } `graphql:"pageInfo"` | ||
| } `graphql:"releases(first:$releasesCount, after: $releaseCursor, orderBy: {field: CREATED_AT, direction: DESC})"` | ||
| } `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"` | ||
| } | ||
|
|
||
| vars := map[string]interface{}{ | ||
| "repositoryOwner": githubv4.String(g.owner), | ||
| "repositoryName": githubv4.String(g.repository), | ||
| "releaseCursor": (*githubv4.String)(nil), | ||
| "releasesCount": githubv4.Int(100), | ||
| } | ||
|
|
||
| var allReleases []*github.RepositoryRelease | ||
| for { | ||
| if err := g.clientV4.Query(context.TODO(), &listReleases, vars); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, r := range listReleases.Repository.Releases.Edges { | ||
| r := r | ||
| publishedAt, _ := time.ParseInLocation(time.RFC3339, r.Node.PublishedAt.Time.Format(time.RFC3339), time.UTC) | ||
| createdAt, _ := time.ParseInLocation(time.RFC3339, r.Node.CreatedAt.Time.Format(time.RFC3339), time.UTC) | ||
| var releaseID int64 | ||
| decodedID, err := base64.StdEncoding.DecodeString(r.Node.ID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| re := regexp.MustCompile(`.*[^\d]`) | ||
| decodedID = re.ReplaceAll(decodedID, []byte("")) | ||
| if string(decodedID) == "" { | ||
| return nil, errors.New("bad release id from graph ql api") | ||
| } | ||
| releaseID, err = strconv.ParseInt(string(decodedID), 10, 64) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| allReleases = append(allReleases, &github.RepositoryRelease{ | ||
| ID: &releaseID, | ||
| TagName: &r.Node.TagName, | ||
| Name: &r.Node.Name, | ||
| Prerelease: &r.Node.IsPrerelease, | ||
| Draft: &r.Node.IsDraft, | ||
| URL: &r.Node.URL, | ||
| PublishedAt: &github.Timestamp{Time: publishedAt}, | ||
| CreatedAt: &github.Timestamp{Time: createdAt}, | ||
| }) | ||
| } | ||
|
|
||
| if !listReleases.Repository.Releases.PageInfo.HasNextPage { | ||
| break | ||
| } | ||
| vars["releaseCursor"] = listReleases.Repository.Releases.PageInfo.EndCursor | ||
| } | ||
|
|
||
| return allReleases, nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.