mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-566 Support GitLab projects as list
This commit is contained in:
@@ -73,5 +73,5 @@ func (widget *Widget) displayStats(project *GitlabProject) string {
|
||||
}
|
||||
|
||||
func (widget *Widget) title(project *GitlabProject) string {
|
||||
return fmt.Sprintf("[green]%s [white]", project.Path)
|
||||
return fmt.Sprintf("[green]%s [white]", project.path)
|
||||
}
|
||||
|
||||
@@ -5,18 +5,17 @@ import (
|
||||
)
|
||||
|
||||
type GitlabProject struct {
|
||||
gitlab *glb.Client
|
||||
Path string
|
||||
client *glb.Client
|
||||
path string
|
||||
|
||||
MergeRequests []*glb.MergeRequest
|
||||
RemoteProject *glb.Project
|
||||
}
|
||||
|
||||
func NewGitlabProject(name string, namespace string, gitlab *glb.Client) *GitlabProject {
|
||||
path := namespace + "/" + name
|
||||
func NewGitlabProject(projectPath string, client *glb.Client) *GitlabProject {
|
||||
project := GitlabProject{
|
||||
gitlab: gitlab,
|
||||
Path: path,
|
||||
client: client,
|
||||
path: projectPath,
|
||||
}
|
||||
|
||||
return &project
|
||||
@@ -73,7 +72,7 @@ func (project *GitlabProject) myApprovalRequests(username string) []*glb.MergeRe
|
||||
mrs := []*glb.MergeRequest{}
|
||||
|
||||
for _, mr := range project.MergeRequests {
|
||||
approvers, _, err := project.gitlab.MergeRequests.GetMergeRequestApprovals(project.Path, mr.IID)
|
||||
approvers, _, err := project.client.MergeRequests.GetMergeRequestApprovals(project.path, mr.IID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -93,7 +92,7 @@ func (project *GitlabProject) loadMergeRequests() ([]*glb.MergeRequest, error) {
|
||||
State: &state,
|
||||
}
|
||||
|
||||
mrs, _, err := project.gitlab.MergeRequests.ListProjectMergeRequests(project.Path, &opts)
|
||||
mrs, _, err := project.client.MergeRequests.ListProjectMergeRequests(project.path, &opts)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -103,7 +102,7 @@ func (project *GitlabProject) loadMergeRequests() ([]*glb.MergeRequest, error) {
|
||||
}
|
||||
|
||||
func (project *GitlabProject) loadRemoteProject() (*glb.Project, error) {
|
||||
projectsitory, _, err := project.gitlab.Projects.GetProject(project.Path, nil)
|
||||
projectsitory, _, err := project.client.Projects.GetProject(project.path, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -9,25 +9,27 @@ import (
|
||||
|
||||
const defaultTitle = "GitLab"
|
||||
|
||||
// Settings defines the configuration properties for this module
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string `help:"A GitLab personal access token. Requires at least api access."`
|
||||
domain string `help:"Your GitLab corporate domain."`
|
||||
projects map[string]interface{} `help:"A list of key/value pairs each describing a GitLab project to fetch data for." values:"Key: The name of the project. Value: The namespace of the project."`
|
||||
username string `help:"Your GitLab username. Used to figure out which requests require your approval"`
|
||||
apiKey string `help:"A GitLab personal access token. Requires at least api access."`
|
||||
domain string `help:"Your GitLab corporate domain."`
|
||||
projects []string `help:"A list of key/value pairs each describing a GitLab project to fetch data for." values:"Key: The name of the project. Value: The namespace of the project."`
|
||||
username string `help:"Your GitLab username. Used to figure out which requests require your approval"`
|
||||
}
|
||||
|
||||
// NewSettingsFromYAML creates a new settings instance from a YAML config block
|
||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
|
||||
|
||||
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_GITLAB_TOKEN"))),
|
||||
domain: ymlConfig.UString("domain"),
|
||||
projects: ymlConfig.UMap("projects"),
|
||||
username: ymlConfig.UString("username"),
|
||||
}
|
||||
|
||||
settings.projects = cfg.ParseAsMapOrList(ymlConfig, "projects")
|
||||
|
||||
return &settings
|
||||
}
|
||||
|
||||
@@ -61,11 +61,11 @@ func (widget *Widget) HelpText() string {
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) buildProjectCollection(projectData map[string]interface{}) []*GitlabProject {
|
||||
func (widget *Widget) buildProjectCollection(projectData []string) []*GitlabProject {
|
||||
gitlabProjects := []*GitlabProject{}
|
||||
|
||||
for name, namespace := range projectData {
|
||||
project := NewGitlabProject(name, namespace.(string), widget.gitlab)
|
||||
for _, projectPath := range projectData {
|
||||
project := NewGitlabProject(projectPath, widget.gitlab)
|
||||
gitlabProjects = append(gitlabProjects, project)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user