From 7bfaa7cfc7772ca711e700636cb9e3c187c9eea0 Mon Sep 17 00:00:00 2001 From: kbilchenko Date: Wed, 8 Sep 2021 08:54:55 +0200 Subject: [PATCH 1/3] Update graphql github release model according to changes and new fields Signed-off-by: kbilchenko --- github_graphql.go | 13 +------------ github_test.go | 4 ++++ model.go | 1 + 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/github_graphql.go b/github_graphql.go index d44f9bb..b649740 100644 --- a/github_graphql.go +++ b/github_graphql.go @@ -2,9 +2,7 @@ package resource import ( "context" - "encoding/base64" "errors" - "regexp" "strconv" "time" @@ -50,16 +48,7 @@ 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) + releaseID, err := strconv.ParseInt(r.Node.DatabaseId, 10, 64) if err != nil { return nil, err } diff --git a/github_test.go b/github_test.go index e101d25..1f205fe 100644 --- a/github_test.go +++ b/github_test.go @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/model.go b/model.go index 4c6ef28..f27e70e 100644 --- a/model.go +++ b/model.go @@ -8,6 +8,7 @@ type ReleaseObject struct { CreatedAt githubv4.DateTime `graphql:"createdAt"` PublishedAt githubv4.DateTime `graphql:"publishedAt"` ID string `graphql:"id"` + DatabaseId string `graphql:"databaseId"` IsDraft bool `graphql:"isDraft"` IsPrerelease bool `graphql:"isPrerelease"` Name string `graphql:"name"` From 2a6b5d836bebdba0e5dad9ea6e1348429004fb14 Mon Sep 17 00:00:00 2001 From: kbilchenko Date: Wed, 8 Sep 2021 08:54:55 +0200 Subject: [PATCH 2/3] Update graphql github release model according to changes and new fields Signed-off-by: kbilchenko --- github_graphql.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/github_graphql.go b/github_graphql.go index b649740..b9ac1a0 100644 --- a/github_graphql.go +++ b/github_graphql.go @@ -2,7 +2,9 @@ package resource import ( "context" + "encoding/base64" "errors" + "regexp" "strconv" "time" @@ -48,10 +50,29 @@ 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 - releaseID, err := strconv.ParseInt(r.Node.DatabaseId, 10, 64) - if err != nil { - return nil, err + if r.Node.DatabaseId == "" { + 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 { + var id int64 + id, err := strconv.ParseInt(r.Node.DatabaseId, 10, 64) + if err != nil { + return nil, err + } + releaseID = id } + allReleases = append(allReleases, &github.RepositoryRelease{ ID: &releaseID, TagName: &r.Node.TagName, From 30fec6748578ba0a6247246b4284d57f2e4ddd31 Mon Sep 17 00:00:00 2001 From: kbilchenko Date: Wed, 8 Sep 2021 11:35:19 +0200 Subject: [PATCH 3/3] Update mode to use Int Signed-off-by: kbilchenko --- github_graphql.go | 9 ++------- github_test.go | 6 +++--- model.go | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/github_graphql.go b/github_graphql.go index b9ac1a0..2ae85b0 100644 --- a/github_graphql.go +++ b/github_graphql.go @@ -50,7 +50,7 @@ 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 - if r.Node.DatabaseId == "" { + if r.Node.DatabaseId == 0 { decodedID, err := base64.StdEncoding.DecodeString(r.Node.ID) if err != nil { return nil, err @@ -65,12 +65,7 @@ func (g *GitHubClient) listReleasesV4() ([]*github.RepositoryRelease, error) { return nil, err } } else { - var id int64 - id, err := strconv.ParseInt(r.Node.DatabaseId, 10, 64) - if err != nil { - return nil, err - } - releaseID = id + releaseID = int64(r.Node.DatabaseId) } allReleases = append(allReleases, &github.RepositoryRelease{ diff --git a/github_test.go b/github_test.go index 1f205fe..5874da8 100644 --- a/github_test.go +++ b/github_test.go @@ -25,7 +25,7 @@ const ( "node": { "createdAt": "2010-10-01T00:58:07Z", "id": "MDc6UmVsZWFzZTMyMDk1MTAz", - "databaseId": "32095103", + "databaseId": 32095103, "name": "xyz", "publishedAt": "2010-10-02T15:39:53Z", "tagName": "xyz", @@ -38,7 +38,7 @@ const ( "node": { "createdAt": "2010-08-27T13:55:36Z", "id": "MDc6UmVsZWFzZTMwMjMwNjU5", - "databaseId": "30230659", + "databaseId": 30230659, "name": "xyz", "publishedAt": "2010-08-27T17:18:06Z", "tagName": "xyz", @@ -66,7 +66,7 @@ const ( "node": { "createdAt": "2010-10-10T01:01:07Z", "id": "MDc6UmVsZWFzZTMzMjIyMjQz", - "databaseId":"33222243", + "databaseId": 33222243, "name": "xyq", "publishedAt": "2010-10-10T15:39:53Z", "tagName": "xyq", diff --git a/model.go b/model.go index f27e70e..0ed351f 100644 --- a/model.go +++ b/model.go @@ -8,7 +8,7 @@ type ReleaseObject struct { CreatedAt githubv4.DateTime `graphql:"createdAt"` PublishedAt githubv4.DateTime `graphql:"publishedAt"` ID string `graphql:"id"` - DatabaseId string `graphql:"databaseId"` + DatabaseId githubv4.Int `graphql:"databaseId"` IsDraft bool `graphql:"isDraft"` IsPrerelease bool `graphql:"isPrerelease"` Name string `graphql:"name"`