Skip to content

Commit

Permalink
Add support for Gitlab in command
Browse files Browse the repository at this point in the history
  • Loading branch information
matsest committed Dec 25, 2019
1 parent cdcd55c commit 13ad308
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
6 changes: 6 additions & 0 deletions command/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ type Env struct {
// GitHubToken is a personal access token for GitHub.
// This allows access to a private repository.
GitHubToken string `envconfig:"GITHUB_TOKEN"`
// GitLabBaseURL is a URL for GitLab API requests.
// Defaults to the public GitLab API.
GitLabBaseURL string `envconfig:"GITLAB_BASE_URL" default:"https://gitlab.com/api/v4/"`
// GitLabToken is a personal access token for GitLab.
// This is needed for public and private projects on all instances.
GitLabToken string `envconfig:"GITLAB_TOKEN"`
}
6 changes: 6 additions & 0 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func newRelease(sourceType string, source string) (release.Release, error) {
Token: env.GitHubToken,
}
return release.NewGitHubRelease(source, config)
case "gitlab":
config := release.GitLabConfig{
BaseURL: env.GitLabBaseURL,
Token: env.GitLabToken,
}
return release.NewGitLabRelease(source, config)
default:
return nil, fmt.Errorf("failed to new release data source. unknown type: %s", sourceType)
}
Expand Down
23 changes: 4 additions & 19 deletions command/release_latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"context"
"fmt"
"os"
"strings"

flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -39,22 +38,6 @@ func (c *ReleaseLatestCommand) Run(args []string) int {
c.UI.Error(err.Error())
return 1
}
// else if GitLab (flag?)
token := os.Getenv("GITLAB_API_TOKEN")
if token == "" {
c.UI.Error(fmt.Sprintf("Could not set GitLab API token from env var GITLAB_API_TOKEN."))
c.UI.Error(c.Help())
return 1
}
// ok: create gitlabrelease
r, err = release.NewGitLabRelease(owner, repo, token)
if err != nil {
c.UI.Error(err.Error())
return 1
}
// if custom url (flag) url = ...
//r.SetGitLabURL(url)
// end gitlab if

v, err := r.Latest(context.Background())
if err != nil {
Expand All @@ -74,13 +57,15 @@ Usage: tfupdate release latest [options] <SOURCE>
Arguments
SOURCE A path of release data source.
Valid format depends on --source-type option.
- github:
- github or gitlab:
owner/repo
e.g. terraform-providers/terraform-provider-aws
Options:
-s --source-type A type of release data source.
Valid value is only github. (default: github)
Valid values are
- github (default)
- gitlab
`
return strings.TrimSpace(helpText)
}
Expand Down

0 comments on commit 13ad308

Please sign in to comment.