Begin caching, implement commands

This commit is contained in:
2023-12-05 16:56:47 -05:00
parent 47300dbf89
commit a8aa8af3d3
14 changed files with 432 additions and 198 deletions

18
pkg/gitlab/gitlab.go Normal file
View File

@ -0,0 +1,18 @@
package gitlab
import "github.com/xanzy/go-gitlab"
type Client struct {
gitlab *gitlab.Client
}
func NewGitlabClient(host, token string) (*Client, error) {
client, err := gitlab.NewClient(token, gitlab.WithBaseURL(host))
if err != nil {
return nil, err
}
gitlabClient := &Client{
gitlab: client,
}
return gitlabClient, nil
}

View File

@ -1,31 +0,0 @@
package manager
import "fmt"
type Manager struct {
Config *ManagerConfig
GitLabHost string
gitLabToken string
}
type ManagerParams struct {
GitLabHost string
GitLabToken string
ConfigFile string
}
// Returns a new instance of project manager
// with optional overrides for common settings
// More complex configuration is provided in the
// configuration file
func NewManager(p *ManagerParams) *Manager {
return &Manager{
Config: NewConfigFromFile(p.ConfigFile),
GitLabHost: p.GitLabHost,
gitLabToken: p.GitLabToken,
}
}
func (m *Manager) String() string {
return fmt.Sprintf("%+v", *m)
}

View File

@ -1,29 +0,0 @@
package manager
import (
"os"
"time"
"golang.org/x/exp/slog"
)
const (
managerDefCacheFile = "/tmp/gitlab_project-manager_cache"
managerDefConfigFile = "~/.config/project-manager/config.yaml"
managerDefProjectsPath = "~/work/projects"
)
type ManagerConfig struct {
CacheTTL time.Duration `yaml:"cacheTTL" json:"cacheTTL" default:"48h"`
CacheFile string `yaml:"cacheFile" json:"cacheFile"`
ConfigFile string `yaml:"configFile" json:"configFile"`
ProjectsPath string `yaml:"projectsPath" json:"projectsPath"`
}
func NewConfigFromFile(file string) *ManagerConfig {
_, err := os.Open(file)
if err != nil {
slog.Warn("Skipping config file, can't read", "err", err)
}
return &ManagerConfig{}
}