Skip to content

Commit

Permalink
Fix github_search_repository table queries failing when hydrating c…
Browse files Browse the repository at this point in the history
…olumns from v3 API fixes #336 (#337)
  • Loading branch information
graza-io authored Sep 18, 2023
1 parent 6c10dc5 commit 02d5be7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions github/models/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ type TextMatchHighlight struct {
EndIndice int `json:"end_indice"`
Text string `json:"text"`
}

type SearchRepositoryResult struct {
TextMatches []TextMatch
Node struct {
Repository `graphql:"... on Repository"`
}
}
21 changes: 19 additions & 2 deletions github/table_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github

import (
"context"
"fmt"
"github.com/google/go-github/v55/github"
"github.com/shurcooL/githubv4"
"github.com/turbot/steampipe-plugin-github/github/models"
Expand Down Expand Up @@ -144,7 +145,10 @@ func tableGitHubRepositoryList(ctx context.Context, d *plugin.QueryData, h *plug
}

func hydrateRepositoryDataFromV3(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
repo := h.Item.(models.Repository)
repo, err := extractRepoFromHydrateItem(h)
if err != nil {
return nil, err
}
owner := repo.Owner.Login
repoName := repo.Name

Expand All @@ -164,7 +168,10 @@ func hydrateRepositoryDataFromV3(ctx context.Context, d *plugin.QueryData, h *pl
}

func hydrateRepositoryHooksFromV3(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
repo := h.Item.(models.Repository)
repo, err := extractRepoFromHydrateItem(h)
if err != nil {
return nil, err
}
owner := repo.Owner.Login
repoName := repo.Name

Expand All @@ -187,3 +194,13 @@ func hydrateRepositoryHooksFromV3(ctx context.Context, d *plugin.QueryData, h *p
}
return repositoryHooks, nil
}

func extractRepoFromHydrateItem(h *plugin.HydrateData) (models.Repository, error) {
if repo, ok := h.Item.(models.Repository); ok {
return repo, nil
} else if searchResult, ok := h.Item.(models.SearchRepositoryResult); ok {
return searchResult.Node.Repository, nil
} else {
return models.Repository{}, fmt.Errorf("unable to parse hydrate item %v as a Repository", h.Item)
}
}
7 changes: 1 addition & 6 deletions github/table_github_search_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ func tableGitHubSearchRepositoryList(ctx context.Context, d *plugin.QueryData, h
Search struct {
RepositoryCount int
PageInfo models.PageInfo
Edges []struct {
TextMatches []models.TextMatch
Node struct {
models.Repository `graphql:"... on Repository"`
}
}
Edges []models.SearchRepositoryResult
} `graphql:"search(type: REPOSITORY, first: $pageSize, after: $cursor, query: $query)"`
}

Expand Down

0 comments on commit 02d5be7

Please sign in to comment.