Skip to content

Commit

Permalink
Update graphql github release model according to changes and new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillbilchenko committed Sep 8, 2021
1 parent 3f41047 commit 246572b
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions github_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package resource

import (
"context"
"encoding/base64"
"errors"
"regexp"
"strconv"
"time"

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 246572b

Please sign in to comment.