From ba552e784458a7218482b6722fbc5c9f00dcd935 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Thu, 23 Jan 2025 10:03:08 -0300 Subject: [PATCH] refactor(blogo,plugins): move gitea plugin to plugins package --- blogo/plugins/gitea/TODO.md | 2 ++ blogo/{ => plugins}/gitea/client.go | 0 blogo/{ => plugins}/gitea/fs.go | 14 +++++++------- blogo/{ => plugins}/gitea/gitea.go | 13 +++++++------ blogo/{ => plugins}/gitea/gitea_test.go | 8 ++++---- 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 blogo/plugins/gitea/TODO.md rename blogo/{ => plugins}/gitea/client.go (100%) rename blogo/{ => plugins}/gitea/fs.go (95%) rename blogo/{ => plugins}/gitea/gitea.go (87%) rename blogo/{ => plugins}/gitea/gitea_test.go (72%) diff --git a/blogo/plugins/gitea/TODO.md b/blogo/plugins/gitea/TODO.md new file mode 100644 index 0000000..13ade74 --- /dev/null +++ b/blogo/plugins/gitea/TODO.md @@ -0,0 +1,2 @@ +- [ ] Handle symlinks +- [ ] Handle submodules diff --git a/blogo/gitea/client.go b/blogo/plugins/gitea/client.go similarity index 100% rename from blogo/gitea/client.go rename to blogo/plugins/gitea/client.go diff --git a/blogo/gitea/fs.go b/blogo/plugins/gitea/fs.go similarity index 95% rename from blogo/gitea/fs.go rename to blogo/plugins/gitea/fs.go index c4c304f..b96aba6 100644 --- a/blogo/gitea/fs.go +++ b/blogo/plugins/gitea/fs.go @@ -28,7 +28,7 @@ import ( "syscall" "time" - "forge.capytal.company/loreddev/x/blogo" + "forge.capytal.company/loreddev/x/blogo/metadata" ) type repositoryFS struct { @@ -41,7 +41,7 @@ type repositoryFS struct { client *client } -func newRepositoryFS(owner, repo, ref string, client *client) blogo.FS { +func newRepositoryFS(owner, repo, ref string, client *client) fs.FS { return &repositoryFS{ owner: owner, repo: repo, @@ -50,7 +50,7 @@ func newRepositoryFS(owner, repo, ref string, client *client) blogo.FS { } } -func (fsys *repositoryFS) Metadata() blogo.Metadata { +func (fsys *repositoryFS) Metadata() metadata.Metadata { // TODO: Properly implement metadata with contents from the API if fsys.metadata == nil || (fsys.metadata != nil && len(fsys.metadata) == 0) { m := map[string]any{} @@ -63,10 +63,10 @@ func (fsys *repositoryFS) Metadata() blogo.Metadata { fsys.metadata = m } - return blogo.MetadataMap(fsys.metadata) + return metadata.Map(fsys.metadata) } -func (fsys *repositoryFS) Open(name string) (blogo.File, error) { +func (fsys *repositoryFS) Open(name string) (fs.File, error) { if !fs.ValidPath(name) { return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid} } @@ -181,7 +181,7 @@ type repositoryFile struct { contents io.ReadCloser } -func (f *repositoryFile) Metadata() blogo.Metadata { +func (f *repositoryFile) Metadata() metadata.Metadata { // TODO: Properly implement metadata with contents from the API if f.metadata == nil || (f.metadata != nil && len(f.metadata) == 0) { m := map[string]any{} @@ -194,7 +194,7 @@ func (f *repositoryFile) Metadata() blogo.Metadata { f.metadata = m } - return blogo.MetadataMap(f.metadata) + return metadata.Map(f.metadata) } func (f *repositoryFile) Stat() (fs.FileInfo, error) { diff --git a/blogo/gitea/gitea.go b/blogo/plugins/gitea/gitea.go similarity index 87% rename from blogo/gitea/gitea.go rename to blogo/plugins/gitea/gitea.go index 12a4ee7..665ecef 100644 --- a/blogo/gitea/gitea.go +++ b/blogo/plugins/gitea/gitea.go @@ -17,16 +17,17 @@ package gitea import ( "fmt" + "io/fs" "net/http" "net/url" "strings" - "forge.capytal.company/loreddev/x/blogo" + "forge.capytal.company/loreddev/x/blogo/plugin" ) const pluginName = "blogo-gitea-sourcer" -type plugin struct { +type p struct { client *client owner string @@ -39,7 +40,7 @@ type Opts struct { Ref string } -func New(owner, repo, apiUrl string, opts ...Opts) blogo.Plugin { +func New(owner, repo, apiUrl string, opts ...Opts) plugin.Plugin { opt := Opts{} if len(opts) > 0 { opt = opts[0] @@ -69,7 +70,7 @@ func New(owner, repo, apiUrl string, opts ...Opts) blogo.Plugin { client := newClient(u.String(), opt.HTTPClient) - return &plugin{ + return &p{ client: client, owner: owner, @@ -78,10 +79,10 @@ func New(owner, repo, apiUrl string, opts ...Opts) blogo.Plugin { } } -func (p *plugin) Name() string { +func (p *p) Name() string { return pluginName } -func (p *plugin) Source() (blogo.FS, error) { +func (p *p) Source() (fs.FS, error) { return newRepositoryFS(p.owner, p.repo, p.ref, p.client), nil } diff --git a/blogo/gitea/gitea_test.go b/blogo/plugins/gitea/gitea_test.go similarity index 72% rename from blogo/gitea/gitea_test.go rename to blogo/plugins/gitea/gitea_test.go index 1cea42c..8f4e0c9 100644 --- a/blogo/gitea/gitea_test.go +++ b/blogo/plugins/gitea/gitea_test.go @@ -4,14 +4,14 @@ import ( "io" "testing" - "forge.capytal.company/loreddev/x/blogo" - "forge.capytal.company/loreddev/x/blogo/gitea" + "forge.capytal.company/loreddev/x/blogo/plugin" + "forge.capytal.company/loreddev/x/blogo/plugins/gitea" ) func TestSource(t *testing.T) { - plugin := gitea.New("loreddev", "x", "https://forge.capytal.company") + p := gitea.New("loreddev", "x", "https://forge.capytal.company") - s := plugin.(blogo.SourcerPlugin) + s := p.(plugin.Sourcer) fs, err := s.Source() if err != nil {