Skip to content
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

Use ghfs for AnalyzeGithubContent #581

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datasource

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand All @@ -11,7 +10,7 @@ import (
"strings"
"time"

"github.com/google/go-github/v58/github"
"github.com/k1LoW/ghfs"
"github.com/k1LoW/go-github-client/v58/factory"
"github.com/k1LoW/tbls/config"
"github.com/k1LoW/tbls/drivers"
Expand Down Expand Up @@ -167,25 +166,22 @@ func AnalyzeGitHubContent(dsn config.DSN) (*schema.Schema, error) {
if len(splitted) != 3 {
return nil, errors.Errorf("invalid dsn: %s", dsn)
}
ctx := context.Background()
s := &schema.Schema{}
options := []factory.Option{factory.OwnerRepo(splitted[0] + "/" + splitted[1])}
c, err := factory.NewGithubClient(options...)
if err != nil {
return nil, errors.WithStack(err)
}
f, _, _, err := c.Repositories.GetContents(ctx, splitted[0], splitted[1], splitted[2], &github.RepositoryContentGetOptions{})
o := ghfs.Client(c)
fsys, err := ghfs.New(splitted[0], splitted[1], o)
if err != nil {
return nil, errors.WithStack(err)
}
if f == nil {
return nil, errors.Errorf("invalid dsn: %s", dsn)
}
cc, err := f.GetContent()
b, err := fsys.ReadFile(splitted[2])
if err != nil {
return nil, errors.WithStack(err)
}
dec := json.NewDecoder(strings.NewReader(cc))
dec := json.NewDecoder(bytes.NewReader(b))
if err := dec.Decode(s); err != nil {
return s, errors.WithStack(err)
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/k1LoW/tbls

go 1.22.1
go 1.22.2

require (
cloud.google.com/go/bigquery v1.61.0
Expand Down Expand Up @@ -109,6 +109,7 @@ require (
github.com/josharian/txtarfs v0.0.0-20210615234325-77aca6df5bca // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k1LoW/fontdir v0.1.1 // indirect
github.com/k1LoW/ghfs v1.3.1 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ github.com/k1LoW/ffff v0.2.0/go.mod h1:XuWQte6DCVCGKkvfeOFHTihuYWusf7dU+kp9jot7F
github.com/k1LoW/fontdir v0.1.0/go.mod h1:9Zbr3T3BXZ5ypr1BM/JwzZN4bqBvl1+JnSTTg1c+zHg=
github.com/k1LoW/fontdir v0.1.1 h1:MGpv3LbkbpdVsEX6BCtsYeoQUZSzvb1RF1c/cfumUUw=
github.com/k1LoW/fontdir v0.1.1/go.mod h1:9Zbr3T3BXZ5ypr1BM/JwzZN4bqBvl1+JnSTTg1c+zHg=
github.com/k1LoW/ghfs v1.3.1 h1:xq/VenCDhSUDf1IsL0LBfWIn3QTCOOd8+pE0SNZF6wM=
github.com/k1LoW/ghfs v1.3.1/go.mod h1:IaAooDKpTdx/I0lSethYNMowo0rs0h/+btPPHdZlnE4=
github.com/k1LoW/go-github-client/v58 v58.0.12 h1:rIK+H2cSpK0ptOxNq0jITGu3ffRjLTe5ITCz1jik5c0=
github.com/k1LoW/go-github-client/v58 v58.0.12/go.mod h1:HFCYt6OBzCfusKY4aVYi4E3T4pbDDNdHQuWOL0pHkdI=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
Expand Down
Loading