mirror of
https://github.com/hanzoai/migrate.git
synced 2026-09-30 22:55:10 +00:00
add ref (SHA, branch, or tag) to the github migration source
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/golang-migrate/migrate/source"
|
||||
"github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -34,6 +34,7 @@ type Github struct {
|
||||
pathOwner string
|
||||
pathRepo string
|
||||
path string
|
||||
options *github.RepositoryContentGetOptions
|
||||
migrations *source.Migrations
|
||||
}
|
||||
|
||||
@@ -64,6 +65,7 @@ func (g *Github) Open(url string) (source.Driver, error) {
|
||||
client: github.NewClient(tr.Client()),
|
||||
url: url,
|
||||
migrations: source.NewMigrations(),
|
||||
options: &github.RepositoryContentGetOptions{Ref: u.Fragment},
|
||||
}
|
||||
|
||||
// set owner, repo and path in repo
|
||||
@@ -96,7 +98,7 @@ func WithInstance(client *github.Client, config *Config) (source.Driver, error)
|
||||
}
|
||||
|
||||
func (g *Github) readDirectory() error {
|
||||
fileContent, dirContents, _, err := g.client.Repositories.GetContents(context.Background(), g.pathOwner, g.pathRepo, g.path, &github.RepositoryContentGetOptions{})
|
||||
fileContent, dirContents, _, err := g.client.Repositories.GetContents(context.Background(), g.pathOwner, g.pathRepo, g.path, g.options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -147,7 +149,7 @@ func (g *Github) Next(version uint) (nextVersion uint, err error) {
|
||||
|
||||
func (g *Github) ReadUp(version uint) (r io.ReadCloser, identifier string, err error) {
|
||||
if m, ok := g.migrations.Up(version); ok {
|
||||
file, _, _, err := g.client.Repositories.GetContents(context.Background(), g.pathOwner, g.pathRepo, path.Join(g.path, m.Raw), &github.RepositoryContentGetOptions{})
|
||||
file, _, _, err := g.client.Repositories.GetContents(context.Background(), g.pathOwner, g.pathRepo, path.Join(g.path, m.Raw), g.options)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -164,7 +166,7 @@ func (g *Github) ReadUp(version uint) (r io.ReadCloser, identifier string, err e
|
||||
|
||||
func (g *Github) ReadDown(version uint) (r io.ReadCloser, identifier string, err error) {
|
||||
if m, ok := g.migrations.Down(version); ok {
|
||||
file, _, _, err := g.client.Repositories.GetContents(context.Background(), g.pathOwner, g.pathRepo, path.Join(g.path, m.Raw), &github.RepositoryContentGetOptions{})
|
||||
file, _, _, err := g.client.Repositories.GetContents(context.Background(), g.pathOwner, g.pathRepo, path.Join(g.path, m.Raw), g.options)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user