refactor(blogo,plugins): move gitea plugin to plugins package
This commit is contained in:
2
blogo/plugins/gitea/TODO.md
Normal file
2
blogo/plugins/gitea/TODO.md
Normal file
@@ -0,0 +1,2 @@
|
||||
- [ ] Handle symlinks
|
||||
- [ ] Handle submodules
|
||||
@@ -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) {
|
||||
@@ -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
|
||||
}
|
||||
@@ -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 {
|
||||
Reference in New Issue
Block a user