Update config, add manual cache unlocking

This commit is contained in:
2023-12-29 10:24:12 -05:00
parent ea0157a997
commit 156ddc2009
13 changed files with 141 additions and 50 deletions

View File

@ -5,7 +5,7 @@ import "time"
type Config struct {
Editor editorConfig `yaml:"editor" json:"editor"`
GitlabHost string `yaml:"gitlabHost" json:"gitlabHost"`
GitlabToken string `yaml:"gitlabToken" json:"gitlabToken"`
GitlabToken string `yaml:"gitlabToken,omitempty" json:"gitlabToken,omitempty"`
LogLevel string `yaml:"logLevel" json:"logLevel" enum:"info,warn,debug,error"`
ProjectPath string `yaml:"projectPath" json:"projectPath"`
Cache cacheConfig `yaml:"cache" json:"cache"`
@ -15,9 +15,9 @@ type Config struct {
}
type editorConfig struct {
DisplayName string `yaml:"displanName,omitempty" json:"displanName"`
Binary string `yaml:"binary,omitempty" json:"binary"`
OpenFlags string `yaml:"openFlags,omitempty" json:"openFlags"`
DisplayName string `yaml:"displanName,omitempty" json:"displanName,omitempty"`
Binary string `yaml:"binary,omitempty" json:"binary,omitempty"`
OpenFlags string `yaml:"openFlags,omitempty" json:"openFlags,omitempty"`
OpenDirectory bool `yaml:"openDirectory" json:"openDirectory" description:"Don't open well-known files, open directory"`
}
@ -26,9 +26,12 @@ type loadConfig struct {
}
type cacheConfig struct {
Ttl time.Duration `yaml:"ttl,omitempty" json:"ttl,omitempty"`
File string `yaml:"file,omitempty" json:"file,omitempty"`
Load loadConfig `yaml:"load" json:"load"`
Ttl time.Duration `yaml:"ttl,omitempty" json:"ttl,omitempty"`
File string `yaml:"file,omitempty" json:"file,omitempty"`
Load loadConfig `yaml:"load" json:"load"`
Unlock struct {
Force bool `yaml:"force" json:"force"`
} `yaml:"unlock" json:"unlock"`
Clear struct {
ClearAliases bool `yaml:"clearAliases,omitempty" json:"clearAliases,omitempty"`
} `yaml:"clear,omitempty" json:"clear,omitempty"`

View File

@ -31,6 +31,7 @@ type Project struct {
AvatarURL string
LastActivityAt time.Time
Readme string
Language *string
gitRepo *git.Repository
}
@ -196,12 +197,33 @@ func (c *Client) handleProjects(projects []*gitlab.Project) []*Project {
AvatarURL: project.AvatarURL,
LastActivityAt: *project.LastActivityAt,
Readme: project.ReadmeURL,
Language: c.GetProjectLanguage(project),
}
pList = append(pList, p)
}
return pList
}
// A nil return indicates an API error or GitLab doesn't know what
// language the project uses.
func (c *Client) GetProjectLanguage(project *gitlab.Project) *string {
l, _, e := c.gitlab.Projects.GetProjectLanguages(project.ID, gitlab.WithContext(c.Ctx))
if e != nil {
pterm.Error.Printfln("Failed requesting project languages: %s", e.Error())
return nil
}
var mainLang *string
var mostUsed float32
for name, p := range *l {
if p > mostUsed {
mainLang = &name
}
}
return mainLang
}
func NewGitlabClient(ctx context.Context, host, token string) (*Client, error) {
client, err := gitlab.NewClient(token, gitlab.WithBaseURL(host))
if err != nil {