add ref (SHA, branch, or tag) to the github migration source

This commit is contained in:
thurt
2018-05-04 03:16:12 +00:00
parent 3a20481cc3
commit edce900e6c
3 changed files with 9 additions and 6 deletions
+6 -4
View File
@@ -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
}