diff --git a/datasource/datasource.go b/datasource/datasource.go index c5c315038..e75d8f448 100644 --- a/datasource/datasource.go +++ b/datasource/datasource.go @@ -2,7 +2,6 @@ package datasource import ( "bytes" - "context" "encoding/json" "io" "net/http" @@ -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" @@ -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) } diff --git a/go.mod b/go.mod index 9ff7e3d7d..89fc3ebdd 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 581fc99da..4f9392e06 100644 --- a/go.sum +++ b/go.sum @@ -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=