Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
feat(config): add option for new entry
Browse files Browse the repository at this point in the history
  • Loading branch information
rande committed Mar 3, 2016
1 parent 9ece57d commit 3e8fdcd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion commands/project_build_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *ProjectBuildArtifactCommand) Run(args []string) int {
}

config := helper.NewConfig()
client := gitlab.NewGitlab(config.Host, config.ApiPath, config.Token)
client := gitlab.NewGitlab(config.Gitlab.Host, config.Gitlab.ApiPath, config.Gitlab.Token)

project, err := helper.GetProject(args[0], client)

Expand Down
2 changes: 1 addition & 1 deletion commands/project_builds_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *ProjectBuildsListCommand) Run(args []string) int {
}

config := helper.NewConfig()
client := gitlab.NewGitlab(config.Host, config.ApiPath, config.Token)
client := gitlab.NewGitlab(config.Gitlab.Host, config.Gitlab.ApiPath, config.Gitlab.Token)

project, err := helper.GetProject(args[0], client)

Expand Down
4 changes: 2 additions & 2 deletions commands/project_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func (c *ProjectsListCommand) Run(args []string) int {

config := helper.NewConfig()

gitlab := gitlab.NewGitlab(config.Host, config.ApiPath, config.Token)
client := gitlab.NewGitlab(config.Gitlab.Host, config.Gitlab.ApiPath, config.Gitlab.Token)

c.Ui.Output("Trying to find project from options")

projects, err := gitlab.Projects()
projects, err := client.Projects()

if err != nil {
c.Ui.Error(err.Error())
Expand Down
25 changes: 20 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@ package gitlab_ci_helper

import "os"

type Config struct {
type GitLabConfig struct {
Host string `json:"host"`
Token string `json:"token"`
ApiPath string `json:"api_path"`
}

type MailerConfig struct {
SubjectPrefix string `json:"subject"`
Sender string `json:"sender"`
Dest []string `json:"dest"`
Host string `json:"host"`
Username string `json:"username"`
Password string `json:"password"`
}

type Config struct {
Gitlab *GitLabConfig `json:"gitlab"`
}

func NewConfig() *Config {
c := &Config{
gitlab := &GitLabConfig{
Host: os.Getenv("GITLAB_HOST"),
Token: os.Getenv("GITLAB_TOKEN"),
ApiPath: os.Getenv("GITLAB_API_PATH"),
}

if c.ApiPath == "" {
c.ApiPath = "/api/v3"
if gitlab.ApiPath == "" {
gitlab.ApiPath = "/api/v3"
}

return c
return &Config{
Gitlab: gitlab,
}
}

0 comments on commit 3e8fdcd

Please sign in to comment.