hide archived project by default
prefix archived project name with a "." by default so they appear hidden on the filesystem. At the same time, added the configuration gitlab.archived_project_handling to set how archived projects are handled
This commit is contained in:
parent
6d0d3fdfc0
commit
2d0a62dc45
|
@ -27,6 +27,13 @@ gitlab:
|
||||||
# A list of the user ids to expose their personal projects in the filesystem.
|
# A list of the user ids to expose their personal projects in the filesystem.
|
||||||
user_ids: []
|
user_ids: []
|
||||||
|
|
||||||
|
# Set how archived projects are handled.
|
||||||
|
# If set to "show", it will add them to the filesystem and treat them like any other repository
|
||||||
|
# If set to "hide", it will add them to the filesystem, but prefix the symlink with a "."
|
||||||
|
# If set to "ignore", it will make them absent from the filesystem
|
||||||
|
# Default to "hide"
|
||||||
|
archived_project_handling: hide
|
||||||
|
|
||||||
# If set to true, the user the api token belongs to will automatically be added to the list of users exposed by the filesystem.
|
# If set to true, the user the api token belongs to will automatically be added to the list of users exposed by the filesystem.
|
||||||
include_current_user: true
|
include_current_user: true
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ func LoadConfig(configPath string) (*Config, error) {
|
||||||
PullMethod: "http",
|
PullMethod: "http",
|
||||||
GroupIDs: []int{9970},
|
GroupIDs: []int{9970},
|
||||||
UserIDs: []int{},
|
UserIDs: []int{},
|
||||||
|
ArchivedProjectHandling: "hide",
|
||||||
IncludeCurrentUser: true,
|
IncludeCurrentUser: true,
|
||||||
},
|
},
|
||||||
Git: git.GitClientParam{
|
Git: git.GitClientParam{
|
||||||
|
@ -85,5 +86,10 @@ func MakeGitlabConfig(config *Config) (*gitlab.GitlabClientConfig, error) {
|
||||||
return nil, fmt.Errorf("pull_method must be either \"%v\" or \"%v\"", gitlab.PullMethodHTTP, gitlab.PullMethodSSH)
|
return nil, fmt.Errorf("pull_method must be either \"%v\" or \"%v\"", gitlab.PullMethodHTTP, gitlab.PullMethodSSH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse archive_handing
|
||||||
|
if config.Gitlab.ArchivedProjectHandling != gitlab.ArchivedProjectShow && config.Gitlab.ArchivedProjectHandling != gitlab.ArchivedProjectHide && config.Gitlab.ArchivedProjectHandling != gitlab.ArchivedProjectIgnore {
|
||||||
|
return nil, fmt.Errorf("pull_method must be either \"%v\", \"%v\" or \"%v\"", gitlab.ArchivedProjectShow, gitlab.ArchivedProjectHide, gitlab.ArchivedProjectIgnore)
|
||||||
|
}
|
||||||
|
|
||||||
return &config.Gitlab, nil
|
return &config.Gitlab, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ func TestLoadConfig(t *testing.T) {
|
||||||
PullMethod: "ssh",
|
PullMethod: "ssh",
|
||||||
GroupIDs: []int{123},
|
GroupIDs: []int{123},
|
||||||
UserIDs: []int{456},
|
UserIDs: []int{456},
|
||||||
|
ArchivedProjectHandling: "hide",
|
||||||
IncludeCurrentUser: true,
|
IncludeCurrentUser: true,
|
||||||
},
|
},
|
||||||
Git: git.GitClientParam{
|
Git: git.GitClientParam{
|
||||||
|
@ -119,31 +120,48 @@ func TestMakeGitlabConfig(t *testing.T) {
|
||||||
input: &config.Config{
|
input: &config.Config{
|
||||||
Gitlab: gitlab.GitlabClientConfig{
|
Gitlab: gitlab.GitlabClientConfig{
|
||||||
URL: "https://gitlab.com",
|
URL: "https://gitlab.com",
|
||||||
|
PullMethod: "http",
|
||||||
Token: "",
|
Token: "",
|
||||||
GroupIDs: []int{9970},
|
GroupIDs: []int{9970},
|
||||||
UserIDs: []int{},
|
UserIDs: []int{},
|
||||||
|
ArchivedProjectHandling: "hide",
|
||||||
IncludeCurrentUser: true,
|
IncludeCurrentUser: true,
|
||||||
PullMethod: "http",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &gitlab.GitlabClientConfig{
|
expected: &gitlab.GitlabClientConfig{
|
||||||
URL: "https://gitlab.com",
|
URL: "https://gitlab.com",
|
||||||
|
PullMethod: "http",
|
||||||
Token: "",
|
Token: "",
|
||||||
GroupIDs: []int{9970},
|
GroupIDs: []int{9970},
|
||||||
UserIDs: []int{},
|
UserIDs: []int{},
|
||||||
|
ArchivedProjectHandling: "hide",
|
||||||
IncludeCurrentUser: true,
|
IncludeCurrentUser: true,
|
||||||
PullMethod: "http",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"InvalidPullMethod": {
|
"InvalidPullMethod": {
|
||||||
input: &config.Config{
|
input: &config.Config{
|
||||||
Gitlab: gitlab.GitlabClientConfig{
|
Gitlab: gitlab.GitlabClientConfig{
|
||||||
URL: "https://gitlab.com",
|
URL: "https://gitlab.com",
|
||||||
|
PullMethod: "invalid",
|
||||||
|
Token: "",
|
||||||
|
GroupIDs: []int{9970},
|
||||||
|
UserIDs: []int{},
|
||||||
|
ArchivedProjectHandling: "hide",
|
||||||
|
IncludeCurrentUser: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
"InvalidArchiveHandling": {
|
||||||
|
input: &config.Config{
|
||||||
|
Gitlab: gitlab.GitlabClientConfig{
|
||||||
|
URL: "https://gitlab.com",
|
||||||
|
PullMethod: "http",
|
||||||
Token: "",
|
Token: "",
|
||||||
GroupIDs: []int{9970},
|
GroupIDs: []int{9970},
|
||||||
UserIDs: []int{},
|
UserIDs: []int{},
|
||||||
IncludeCurrentUser: true,
|
IncludeCurrentUser: true,
|
||||||
PullMethod: "invalid",
|
ArchivedProjectHandling: "invalid",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: nil,
|
expected: nil,
|
||||||
|
|
|
@ -13,6 +13,10 @@ import (
|
||||||
const (
|
const (
|
||||||
PullMethodHTTP = "http"
|
PullMethodHTTP = "http"
|
||||||
PullMethodSSH = "ssh"
|
PullMethodSSH = "ssh"
|
||||||
|
|
||||||
|
ArchivedProjectShow = "show"
|
||||||
|
ArchivedProjectHide = "hide"
|
||||||
|
ArchivedProjectIgnore = "ignore"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitlabClientConfig struct {
|
type GitlabClientConfig struct {
|
||||||
|
@ -20,6 +24,7 @@ type GitlabClientConfig struct {
|
||||||
Token string `yaml:"token,omitempty"`
|
Token string `yaml:"token,omitempty"`
|
||||||
GroupIDs []int `yaml:"group_ids,omitempty"`
|
GroupIDs []int `yaml:"group_ids,omitempty"`
|
||||||
UserIDs []int `yaml:"user_ids,omitempty"`
|
UserIDs []int `yaml:"user_ids,omitempty"`
|
||||||
|
ArchivedProjectHandling string `yaml:"archived_project_handling,omitempty"`
|
||||||
IncludeCurrentUser bool `yaml:"include_current_user,omitempty"`
|
IncludeCurrentUser bool `yaml:"include_current_user,omitempty"`
|
||||||
PullMethod string `yaml:"pull_method,omitempty"`
|
PullMethod string `yaml:"pull_method,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,9 @@ func (c *gitlabClient) fetchGroupContent(group *Group) (map[string]fstree.GroupS
|
||||||
}
|
}
|
||||||
for _, gitlabProject := range gitlabProjects {
|
for _, gitlabProject := range gitlabProjects {
|
||||||
project := c.newProjectFromGitlabProject(gitlabProject)
|
project := c.newProjectFromGitlabProject(gitlabProject)
|
||||||
childProjects[project.Name] = &project
|
if project != nil {
|
||||||
|
childProjects[project.Path] = project
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if response.CurrentPage >= response.TotalPages {
|
if response.CurrentPage >= response.TotalPages {
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package gitlab
|
package gitlab
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/xanzy/go-gitlab"
|
"github.com/xanzy/go-gitlab"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
ID int
|
ID int
|
||||||
Name string
|
Path string
|
||||||
CloneURL string
|
CloneURL string
|
||||||
DefaultBranch string
|
DefaultBranch string
|
||||||
}
|
}
|
||||||
|
@ -23,11 +25,14 @@ func (p *Project) GetDefaultBranch() string {
|
||||||
return p.DefaultBranch
|
return p.DefaultBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *gitlabClient) newProjectFromGitlabProject(project *gitlab.Project) Project {
|
func (c *gitlabClient) newProjectFromGitlabProject(project *gitlab.Project) *Project {
|
||||||
// https://godoc.org/github.com/xanzy/go-gitlab#Project
|
// https://godoc.org/github.com/xanzy/go-gitlab#Project
|
||||||
|
if c.ArchivedProjectHandling == ArchivedProjectIgnore && project.Archived {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
p := Project{
|
p := Project{
|
||||||
ID: project.ID,
|
ID: project.ID,
|
||||||
Name: project.Path,
|
Path: project.Path,
|
||||||
DefaultBranch: project.DefaultBranch,
|
DefaultBranch: project.DefaultBranch,
|
||||||
}
|
}
|
||||||
if p.DefaultBranch == "" {
|
if p.DefaultBranch == "" {
|
||||||
|
@ -38,5 +43,8 @@ func (c *gitlabClient) newProjectFromGitlabProject(project *gitlab.Project) Proj
|
||||||
} else {
|
} else {
|
||||||
p.CloneURL = project.HTTPURLToRepo
|
p.CloneURL = project.HTTPURLToRepo
|
||||||
}
|
}
|
||||||
return p
|
if c.ArchivedProjectHandling == ArchivedProjectHide && project.Archived {
|
||||||
|
p.Path = path.Join(path.Dir(p.Path), "."+path.Base(p.Path))
|
||||||
|
}
|
||||||
|
return &p
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,9 @@ func (c *gitlabClient) fetchUserContent(user *User) (map[string]fstree.GroupSour
|
||||||
}
|
}
|
||||||
for _, gitlabProject := range gitlabProjects {
|
for _, gitlabProject := range gitlabProjects {
|
||||||
project := c.newProjectFromGitlabProject(gitlabProject)
|
project := c.newProjectFromGitlabProject(gitlabProject)
|
||||||
childProjects[project.Name] = &project
|
if project != nil {
|
||||||
|
childProjects[project.Path] = project
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if response.CurrentPage >= response.TotalPages {
|
if response.CurrentPage >= response.TotalPages {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue