refactor platform -> forge
This commit is contained in:
parent
0e5fed0bbd
commit
1a01c9ecea
|
@ -6,9 +6,9 @@ fs:
|
|||
# See mount.fuse(8) for the full list of options.
|
||||
#mountoptions: nodev,nosuid
|
||||
|
||||
# The git platform to use as the backend.
|
||||
# Must be one of "gitlab", or "github"
|
||||
platform: gitlab
|
||||
# The git forge to use as the backend.
|
||||
# Must be one of "gitlab" or "github"
|
||||
forge: gitlab
|
||||
|
||||
gitlab:
|
||||
# The gitlab url.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fs:
|
||||
mountpoint: /tmp/gitlabfs/test/mnt/gitlab
|
||||
mountoptions: nodev
|
||||
platform: gitlab
|
||||
forge: gitlab
|
||||
|
||||
gitlab:
|
||||
url: https://example.com
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
PlatformGitlab = "gitlab"
|
||||
PlatformGithub = "github"
|
||||
ForgeGitlab = "gitlab"
|
||||
ForgeGithub = "github"
|
||||
|
||||
PullMethodHTTP = "http"
|
||||
PullMethodSSH = "ssh"
|
||||
|
@ -30,7 +30,7 @@ type (
|
|||
FSConfig struct {
|
||||
Mountpoint string `yaml:"mountpoint,omitempty"`
|
||||
MountOptions string `yaml:"mountoptions,omitempty"`
|
||||
Platform string `yaml:"platform,omitempty"`
|
||||
Forge string `yaml:"forge,omitempty"`
|
||||
}
|
||||
GitlabClientConfig struct {
|
||||
URL string `yaml:"url,omitempty"`
|
||||
|
@ -76,7 +76,7 @@ func LoadConfig(configPath string) (*Config, error) {
|
|||
FS: FSConfig{
|
||||
Mountpoint: "",
|
||||
MountOptions: "nodev,nosuid",
|
||||
Platform: "",
|
||||
Forge: "",
|
||||
},
|
||||
Gitlab: GitlabClientConfig{
|
||||
URL: "https://gitlab.com",
|
||||
|
@ -119,9 +119,9 @@ func LoadConfig(configPath string) (*Config, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// validate platform is set
|
||||
if config.FS.Platform != PlatformGithub && config.FS.Platform != PlatformGitlab {
|
||||
return nil, fmt.Errorf("fs.platform must be either \"%v\", or \"%v\"", PlatformGitlab, PlatformGithub)
|
||||
// validate forge is set
|
||||
if config.FS.Forge != ForgeGithub && config.FS.Forge != ForgeGitlab {
|
||||
return nil, fmt.Errorf("fs.forge must be either \"%v\", or \"%v\"", ForgeGitlab, ForgeGithub)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestLoadConfig(t *testing.T) {
|
|||
FS: config.FSConfig{
|
||||
Mountpoint: "/tmp/gitlabfs/test/mnt/gitlab",
|
||||
MountOptions: "nodev",
|
||||
Platform: "gitlab",
|
||||
Forge: "gitlab",
|
||||
},
|
||||
Gitlab: config.GitlabClientConfig{
|
||||
URL: "https://example.com",
|
||||
|
@ -70,7 +70,7 @@ func TestMakeGitConfig(t *testing.T) {
|
|||
"ValidConfig": {
|
||||
input: &config.Config{
|
||||
FS: config.FSConfig{
|
||||
Platform: "gitlab",
|
||||
Forge: "gitlab",
|
||||
},
|
||||
Git: config.GitClientConfig{
|
||||
CloneLocation: "/tmp",
|
||||
|
@ -95,7 +95,7 @@ func TestMakeGitConfig(t *testing.T) {
|
|||
"InvalidOnClone": {
|
||||
input: &config.Config{
|
||||
FS: config.FSConfig{
|
||||
Platform: "gitlab",
|
||||
Forge: "gitlab",
|
||||
},
|
||||
Git: config.GitClientConfig{
|
||||
CloneLocation: "/tmp",
|
||||
|
@ -132,7 +132,7 @@ func TestMakeGitlabConfig(t *testing.T) {
|
|||
"ValidConfig": {
|
||||
input: &config.Config{
|
||||
FS: config.FSConfig{
|
||||
Platform: "gitlab",
|
||||
Forge: "gitlab",
|
||||
},
|
||||
Gitlab: config.GitlabClientConfig{
|
||||
URL: "https://gitlab.com",
|
||||
|
@ -157,7 +157,7 @@ func TestMakeGitlabConfig(t *testing.T) {
|
|||
"InvalidPullMethod": {
|
||||
input: &config.Config{
|
||||
FS: config.FSConfig{
|
||||
Platform: "gitlab",
|
||||
Forge: "gitlab",
|
||||
},
|
||||
Gitlab: config.GitlabClientConfig{
|
||||
URL: "https://gitlab.com",
|
||||
|
|
|
@ -39,7 +39,7 @@ func newGroupNodeFromSource(source GroupSource, param *FSParam) (*groupNode, err
|
|||
}
|
||||
|
||||
func (n *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
||||
groups, repositories, err := n.param.GitPlatform.FetchGroupContent(n.source.GetGroupID())
|
||||
groups, repositories, err := n.param.GitForge.FetchGroupContent(n.source.GetGroupID())
|
||||
if err != nil {
|
||||
n.param.logger.Error(err.Error())
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (n *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||
}
|
||||
|
||||
func (n *groupNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
|
||||
groups, repositories, err := n.param.GitPlatform.FetchGroupContent(n.source.GetGroupID())
|
||||
groups, repositories, err := n.param.GitForge.FetchGroupContent(n.source.GetGroupID())
|
||||
if err != nil {
|
||||
n.param.logger.Error(err.Error())
|
||||
} else {
|
||||
|
|
|
@ -26,14 +26,14 @@ type GitClient interface {
|
|||
FetchLocalRepositoryPath(source RepositorySource) (string, error)
|
||||
}
|
||||
|
||||
type GitPlatform interface {
|
||||
type GitForge interface {
|
||||
FetchRootGroupContent() (map[string]GroupSource, error)
|
||||
FetchGroupContent(gid uint64) (map[string]GroupSource, map[string]RepositorySource, error)
|
||||
}
|
||||
|
||||
type FSParam struct {
|
||||
GitClient GitClient
|
||||
GitPlatform GitPlatform
|
||||
GitClient GitClient
|
||||
GitForge GitForge
|
||||
|
||||
logger *slog.Logger
|
||||
staticInoChan chan uint64
|
||||
|
@ -77,7 +77,7 @@ func Start(logger *slog.Logger, mountpoint string, mountoptions []string, param
|
|||
}
|
||||
|
||||
func (n *rootNode) OnAdd(ctx context.Context) {
|
||||
rootGroups, err := n.param.GitPlatform.FetchRootGroupContent()
|
||||
rootGroups, err := n.param.GitForge.FetchRootGroupContent()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
16
main.go
16
main.go
|
@ -8,10 +8,10 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/badjware/gitlabfs/config"
|
||||
"github.com/badjware/gitlabfs/forges/github"
|
||||
"github.com/badjware/gitlabfs/forges/gitlab"
|
||||
"github.com/badjware/gitlabfs/fstree"
|
||||
"github.com/badjware/gitlabfs/git"
|
||||
"github.com/badjware/gitlabfs/platforms/github"
|
||||
"github.com/badjware/gitlabfs/platforms/gitlab"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -65,23 +65,23 @@ func main() {
|
|||
}
|
||||
gitClient, _ := git.NewClient(logger, *gitClientParam)
|
||||
|
||||
var gitPlatformClient fstree.GitPlatform
|
||||
if loadedConfig.FS.Platform == config.PlatformGitlab {
|
||||
var gitForgeClient fstree.GitForge
|
||||
if loadedConfig.FS.Forge == config.ForgeGitlab {
|
||||
// Create the gitlab client
|
||||
GitlabClientConfig, err := config.MakeGitlabConfig(loadedConfig)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
gitPlatformClient, _ = gitlab.NewClient(logger, *GitlabClientConfig)
|
||||
} else if loadedConfig.FS.Platform == config.PlatformGithub {
|
||||
gitForgeClient, _ = gitlab.NewClient(logger, *GitlabClientConfig)
|
||||
} else if loadedConfig.FS.Forge == config.ForgeGithub {
|
||||
// Create the github client
|
||||
GithubClientConfig, err := config.MakeGithubConfig(loadedConfig)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
gitPlatformClient, _ = github.NewClient(logger, *GithubClientConfig)
|
||||
gitForgeClient, _ = github.NewClient(logger, *GithubClientConfig)
|
||||
}
|
||||
|
||||
// Start the filesystem
|
||||
|
@ -89,7 +89,7 @@ func main() {
|
|||
logger,
|
||||
mountpoint,
|
||||
parsedMountoptions,
|
||||
&fstree.FSParam{GitClient: gitClient, GitPlatform: gitPlatformClient},
|
||||
&fstree.FSParam{GitClient: gitClient, GitForge: gitForgeClient},
|
||||
*debug,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue