Skip to content

Commit

Permalink
backporting github graphql updates
Browse files Browse the repository at this point in the history
we need the changes in #107 for 6.7 branch as well

Signed-off-by: Rui Yang <ruiya@vmware.com>
  • Loading branch information
Rui Yang committed Sep 13, 2021
1 parent 78d9793 commit 114374e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
29 changes: 17 additions & 12 deletions github_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,24 @@ func (g *GitHubClient) listReleasesV4() ([]*github.RepositoryRelease, error) {
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
if r.Node.DatabaseId == 0 {
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
}
} else {
releaseID = int64(r.Node.DatabaseId)
}

allReleases = append(allReleases, &github.RepositoryRelease{
ID: &releaseID,
TagName: &r.Node.TagName,
Expand Down
4 changes: 4 additions & 0 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
"node": {
"createdAt": "2010-10-01T00:58:07Z",
"id": "MDc6UmVsZWFzZTMyMDk1MTAz",
"databaseId": 32095103,
"name": "xyz",
"publishedAt": "2010-10-02T15:39:53Z",
"tagName": "xyz",
Expand All @@ -37,6 +38,7 @@ const (
"node": {
"createdAt": "2010-08-27T13:55:36Z",
"id": "MDc6UmVsZWFzZTMwMjMwNjU5",
"databaseId": 30230659,
"name": "xyz",
"publishedAt": "2010-08-27T17:18:06Z",
"tagName": "xyz",
Expand Down Expand Up @@ -64,6 +66,7 @@ const (
"node": {
"createdAt": "2010-10-10T01:01:07Z",
"id": "MDc6UmVsZWFzZTMzMjIyMjQz",
"databaseId": 33222243,
"name": "xyq",
"publishedAt": "2010-10-10T15:39:53Z",
"tagName": "xyq",
Expand All @@ -90,6 +93,7 @@ const (
"node": {
"createdAt": "2010-10-10T01:01:07Z",
"id": "MDc6UmVsZWFzZTMzMjZyzzzz",
"databaseId":"3322224a",
"name": "xyq",
"publishedAt": "2010-10-10T15:39:53Z",
"tagName": "xyq",
Expand Down
1 change: 1 addition & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ReleaseObject struct {
CreatedAt githubv4.DateTime `graphql:"createdAt"`
PublishedAt githubv4.DateTime `graphql:"publishedAt"`
ID string `graphql:"id"`
DatabaseId githubv4.Int `graphql:"databaseId"`
IsDraft bool `graphql:"isDraft"`
IsPrerelease bool `graphql:"isPrerelease"`
Name string `graphql:"name"`
Expand Down

0 comments on commit 114374e

Please sign in to comment.