From dce3a858e34667bbef1da99521e69030a93afed5 Mon Sep 17 00:00:00 2001 From: xuwu Date: Thu, 26 May 2022 22:52:43 +0800 Subject: [PATCH 1/4] feat: gitlab enhancement --- .../plugins/gitlab-repo-scaffolding-golang.md | 12 +++-- docs/plugins/gitlabci-generic.md | 8 +-- docs/plugins/gitlabci-golang.md | 6 ++- .../plugin/common/reposcaffolding/options.go | 10 +++- .../pkg/plugin/gitlabci/generic/create.go | 2 +- .../pkg/plugin/gitlabci/generic/delete.go | 2 +- .../pkg/plugin/gitlabci/generic/generic.go | 5 ++ .../pkg/plugin/gitlabci/generic/options.go | 1 + internal/pkg/plugin/gitlabci/generic/read.go | 2 +- .../pkg/plugin/gitlabci/generic/update.go | 2 +- internal/pkg/plugin/gitlabci/golang/create.go | 2 +- internal/pkg/plugin/gitlabci/golang/delete.go | 2 +- .../pkg/plugin/gitlabci/golang/gitlabci.go | 1 + internal/pkg/plugin/gitlabci/golang/read.go | 2 +- internal/pkg/plugin/gitlabci/golang/update.go | 2 +- .../reposcaffolding/gitlab/golang/delete.go | 2 +- .../reposcaffolding/gitlab/golang/golang.go | 30 +++++++++--- .../reposcaffolding/gitlab/golang/read.go | 32 +++++++----- pkg/util/gitlab/gitlab.go | 39 +++++++++++++-- pkg/util/gitlab/project.go | 49 ++++++++++++++++--- 20 files changed, 161 insertions(+), 50 deletions(-) diff --git a/docs/plugins/gitlab-repo-scaffolding-golang.md b/docs/plugins/gitlab-repo-scaffolding-golang.md index 6c3db4275..dcf6e7dda 100644 --- a/docs/plugins/gitlab-repo-scaffolding-golang.md +++ b/docs/plugins/gitlab-repo-scaffolding-golang.md @@ -33,12 +33,16 @@ tools: options: # the repo's owner. It should be case-sensitive here; strictly use your GitLab user name; please change the value below. owner: YOUR_GITLAB_USERNAME - # the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored. - org: YOUR_ORGANIZATION_NAME + # the repo's org or group (If it's a subgroup, the value is `groupname/subgroup`). If you set this property, then the new repo will be created under the org or group you're given, and the "owner" setting above will be ignored. + org: YOUR_ORG_OR_GROUP_NAME # the repo which you'd like to create; please change the value below. repo: YOUR_REPO_NAME # the branch of the repo you'd like to hold the code branch: main + # the visibility of the generated project, its value can be `public` or `private` or `internal` + visibility: private + # if you are using self-hosted gitlab, set this value to your site address, otherwise set it to null + baseURL: https://yourselfhost.com # the image repo you'd like to push the container image; please change the value below. image_repo: YOUR_DOCKERHUB_USERNAME/YOUR_DOCKERHUB_REPOSITORY ``` @@ -46,7 +50,7 @@ tools: Replace the following from the config above: - `YOUR_GITLAB_USERNAME` -- `YOUR_ORGANIZATION_NAME` +- `YOUR_ORG_OR_GROUP_NAME` - `YOUR_REPO_NAME` - `YOUR_DOCKERHUB_USERNAME` - `YOUR_DOCKERHUB_REPOSITORY` @@ -57,7 +61,7 @@ You have to specify either "owner" or "org". ## Outputs -This plugin has three outputs: +This plugin has four outputs: - `org` - `owner` diff --git a/docs/plugins/gitlabci-generic.md b/docs/plugins/gitlabci-generic.md index 94af124cc..d987138f5 100644 --- a/docs/plugins/gitlabci-generic.md +++ b/docs/plugins/gitlabci-generic.md @@ -26,11 +26,13 @@ tools: dependsOn: [] # options for the plugin options: - # owner/repo; "path with namespace" is only GitLab API's way of saying the same thing; please change the values below. - pathWithNamespace: YOUR_GITLAB_USERNAME/YOUR_GITLAB_REPO_NAME + # owner/repo or group/repo or group/subgroup/repo; "path with namespace" is only GitLab API's way of saying the same thing; please change the values below. + pathWithNamespace: YOUR_GITLAB_USERNAME_OR_GROUP/YOUR_GITLAB_REPO_NAME # main branch of the repo (to which branch the plugin will submit the workflows) branch: main - # url of the GitLab CI template + # if you are using self-hosted gitlab, set this value to your site address, otherwise set it to null + baseURL: https://yourselfhost.com + # url of the GitLab CI template, if your templateURL: https://someplace.com/to/download/your/template # custom variables keys and values templateVariables: diff --git a/docs/plugins/gitlabci-golang.md b/docs/plugins/gitlabci-golang.md index b78946fc2..a6ceb3c92 100644 --- a/docs/plugins/gitlabci-golang.md +++ b/docs/plugins/gitlabci-golang.md @@ -24,10 +24,12 @@ tools: dependsOn: [] # options for the plugin options: - # owner/repo; "path with namespace" is only GitLab API's way of saying the same thing; please change the values below. - pathWithNamespace: YOUR_GITLAB_USERNAME/YOUR_GITLAB_REPO_NAME + # owner/repo or group/repo or group/subgroup/repo; "path with namespace" is only GitLab API's way of saying the same thing; please change the values below. + pathWithNamespace: YOUR_GITLAB_USERNAME_OR_GROUP/YOUR_GITLAB_REPO_NAME # main branch of the repo (to which branch the plugin will submit the workflows) branch: main + # if you are using self-hosted gitlab, set this value to your site address, otherwise set it to null + baseURL: https://yourselfhost.com ``` All parameters are mandatory. diff --git a/internal/pkg/plugin/common/reposcaffolding/options.go b/internal/pkg/plugin/common/reposcaffolding/options.go index 488df8644..78a331b9e 100644 --- a/internal/pkg/plugin/common/reposcaffolding/options.go +++ b/internal/pkg/plugin/common/reposcaffolding/options.go @@ -2,6 +2,7 @@ package reposcaffolding import ( "fmt" + "path/filepath" "github.com/devstream-io/devstream/pkg/util/validator" ) @@ -12,7 +13,9 @@ type Options struct { Repo string `validate:"required"` Branch string `validate:"required"` PathWithNamespace string + BaseURL string `validate:"omitempty,url"` ImageRepo string `mapstructure:"image_repo"` + Visibility string `validate:"omitempty,oneof=public private internal"` } // Validate validates the options provided by the core. @@ -20,7 +23,12 @@ func Validate(opts *Options) []error { retErrors := make([]error, 0) retErrors = append(retErrors, validator.Struct(opts)...) // set PathWithNamespace for GitLab. GitHub won't need to use this - opts.PathWithNamespace = fmt.Sprintf("%s/%s", opts.Owner, opts.Repo) + // opts.PathWithNamespace = fmt.Sprintf("%s/%s", opts.Owner, opts.Repo) + if opts.Org != "" { + opts.PathWithNamespace = filepath.Clean(fmt.Sprintf("%s/%s", opts.Org, opts.Repo)) + } else { + opts.PathWithNamespace = filepath.Clean(fmt.Sprintf("%s/%s", opts.Owner, opts.Repo)) + } return retErrors } diff --git a/internal/pkg/plugin/gitlabci/generic/create.go b/internal/pkg/plugin/gitlabci/generic/create.go index ab7462a6a..cf4b9ec5b 100644 --- a/internal/pkg/plugin/gitlabci/generic/create.go +++ b/internal/pkg/plugin/gitlabci/generic/create.go @@ -42,7 +42,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) { } // commit file - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return nil, err } diff --git a/internal/pkg/plugin/gitlabci/generic/delete.go b/internal/pkg/plugin/gitlabci/generic/delete.go index 09ad9327b..847f3c5d7 100644 --- a/internal/pkg/plugin/gitlabci/generic/delete.go +++ b/internal/pkg/plugin/gitlabci/generic/delete.go @@ -22,7 +22,7 @@ func Delete(options map[string]interface{}) (bool, error) { return false, fmt.Errorf("opts are illegal") } - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return false, err } diff --git a/internal/pkg/plugin/gitlabci/generic/generic.go b/internal/pkg/plugin/gitlabci/generic/generic.go index 7417fd059..ed013f672 100644 --- a/internal/pkg/plugin/gitlabci/generic/generic.go +++ b/internal/pkg/plugin/gitlabci/generic/generic.go @@ -1,6 +1,7 @@ package generic import ( + "fmt" "io" "net/http" ) @@ -26,6 +27,10 @@ func download(url string) (string, error) { } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return "", fmt.Errorf("failed to download template: %s %s", url, resp.Status) + } + resBytes, err := io.ReadAll(resp.Body) if err != nil { return "", err diff --git a/internal/pkg/plugin/gitlabci/generic/options.go b/internal/pkg/plugin/gitlabci/generic/options.go index 81999f6d5..3942e32c0 100644 --- a/internal/pkg/plugin/gitlabci/generic/options.go +++ b/internal/pkg/plugin/gitlabci/generic/options.go @@ -5,5 +5,6 @@ type Options struct { PathWithNamespace string `validate:"required"` Branch string `validate:"required"` TemplateURL string `validate:"required"` + BaseURL string `validate:"omitempty,url"` TemplateVariables map[string]interface{} } diff --git a/internal/pkg/plugin/gitlabci/generic/read.go b/internal/pkg/plugin/gitlabci/generic/read.go index bb3077253..575067d29 100644 --- a/internal/pkg/plugin/gitlabci/generic/read.go +++ b/internal/pkg/plugin/gitlabci/generic/read.go @@ -22,7 +22,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) { return nil, fmt.Errorf("opts are illegal") } - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return nil, err } diff --git a/internal/pkg/plugin/gitlabci/generic/update.go b/internal/pkg/plugin/gitlabci/generic/update.go index 1165164b2..c50181209 100644 --- a/internal/pkg/plugin/gitlabci/generic/update.go +++ b/internal/pkg/plugin/gitlabci/generic/update.go @@ -42,7 +42,7 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) { } // update file - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return nil, err } diff --git a/internal/pkg/plugin/gitlabci/golang/create.go b/internal/pkg/plugin/gitlabci/golang/create.go index 089310e45..876a3f151 100644 --- a/internal/pkg/plugin/gitlabci/golang/create.go +++ b/internal/pkg/plugin/gitlabci/golang/create.go @@ -26,7 +26,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) { return nil, fmt.Errorf("opts are illegal") } - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return nil, err } diff --git a/internal/pkg/plugin/gitlabci/golang/delete.go b/internal/pkg/plugin/gitlabci/golang/delete.go index 91db8ee71..31be7788b 100644 --- a/internal/pkg/plugin/gitlabci/golang/delete.go +++ b/internal/pkg/plugin/gitlabci/golang/delete.go @@ -24,7 +24,7 @@ func Delete(options map[string]interface{}) (bool, error) { } return false, fmt.Errorf("opts are illegal") } - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return false, err } diff --git a/internal/pkg/plugin/gitlabci/golang/gitlabci.go b/internal/pkg/plugin/gitlabci/golang/gitlabci.go index 9616f3cde..e0ef7e57b 100644 --- a/internal/pkg/plugin/gitlabci/golang/gitlabci.go +++ b/internal/pkg/plugin/gitlabci/golang/gitlabci.go @@ -8,6 +8,7 @@ const ( type Options struct { PathWithNamespace string `validate:"required"` Branch string `validate:"required"` + BaseURL string `validate:"omitempty,url"` } func buildState(opts *Options) map[string]interface{} { diff --git a/internal/pkg/plugin/gitlabci/golang/read.go b/internal/pkg/plugin/gitlabci/golang/read.go index bd03e3580..e0a68819f 100644 --- a/internal/pkg/plugin/gitlabci/golang/read.go +++ b/internal/pkg/plugin/gitlabci/golang/read.go @@ -23,7 +23,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) { } return nil, fmt.Errorf("opts are illegal") } - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return nil, err } diff --git a/internal/pkg/plugin/gitlabci/golang/update.go b/internal/pkg/plugin/gitlabci/golang/update.go index 454754a61..73edaede7 100644 --- a/internal/pkg/plugin/gitlabci/golang/update.go +++ b/internal/pkg/plugin/gitlabci/golang/update.go @@ -26,7 +26,7 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) { return nil, fmt.Errorf("opts are illegal") } - client, err := gitlab.NewClient() + client, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return nil, err } diff --git a/internal/pkg/plugin/reposcaffolding/gitlab/golang/delete.go b/internal/pkg/plugin/reposcaffolding/gitlab/golang/delete.go index a7b8afbd6..a81b7fd4c 100644 --- a/internal/pkg/plugin/reposcaffolding/gitlab/golang/delete.go +++ b/internal/pkg/plugin/reposcaffolding/gitlab/golang/delete.go @@ -27,7 +27,7 @@ func Delete(options map[string]interface{}) (bool, error) { } func uninstall(opts *rs.Options) (bool, error) { - c, err := gitlab.NewClient() + c, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return false, err } diff --git a/internal/pkg/plugin/reposcaffolding/gitlab/golang/golang.go b/internal/pkg/plugin/reposcaffolding/gitlab/golang/golang.go index 32944e196..0e152d001 100644 --- a/internal/pkg/plugin/reposcaffolding/gitlab/golang/golang.go +++ b/internal/pkg/plugin/reposcaffolding/gitlab/golang/golang.go @@ -32,15 +32,21 @@ type Repo struct { func pushToRemote(repoPath string, opts *rs.Options) error { // create a GitLab client - c, err := gitlab.NewClient() + c, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return err } var retErr error + createProjOpts := &gitlab.CreateProjectOptions{ + Name: opts.Repo, + Branch: opts.Branch, + Namespace: opts.Org, + Visibility: opts.Visibility, + } // create the project - if err := c.CreateProject(opts.Repo, opts.Branch); err != nil { + if err := c.CreateProject(createProjOpts); err != nil { log.Errorf("Failed to create repo: %s.", err) return err } @@ -51,9 +57,10 @@ func pushToRemote(repoPath string, opts *rs.Options) error { if retErr == nil { return } + log.Errorf("Failed to push to remote: %s.", retErr) // need to clean the repo created when retErr != nil - if err := c.DeleteProject(opts.Repo); err != nil { - log.Errorf("Failed to delete the repo %s: %s.", opts.Repo, err) + if err := c.DeleteProject(opts.PathWithNamespace); err != nil { + log.Errorf("Failed to delete the repo %s: %s.", opts.PathWithNamespace, err) } }() @@ -87,7 +94,6 @@ func walkLocalRepoPath(repoPath string, opts *rs.Options, c *gitlab.Client) erro if err != nil { return err } - gitlabPath := strings.Join(strings.Split(path, "/")[2:], "/") files[gitlabPath] = content return nil @@ -115,10 +121,18 @@ func buildState(opts *rs.Options) map[string]interface{} { outputs["owner"] = opts.Owner outputs["org"] = opts.Org outputs["repo"] = opts.Repo - if opts.Owner != "" { - outputs["repoURL"] = fmt.Sprintf("https://gitlab.com/%s/%s.git", opts.Owner, opts.Repo) + + var gitlabURL string + if opts.BaseURL != "" { + gitlabURL = opts.BaseURL + } else { + gitlabURL = gitlab.DefaultGitlabHost + } + + if opts.Org != "" { + outputs["repoURL"] = fmt.Sprintf("%s/%s/%s.git", gitlabURL, opts.Org, opts.Repo) } else { - outputs["repoURL"] = fmt.Sprintf("https://gitlab.com/%s/%s.git", opts.Org, opts.Repo) + outputs["repoURL"] = fmt.Sprintf("%s/%s/%s.git", gitlabURL, opts.Owner, opts.Repo) } res["outputs"] = outputs diff --git a/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go b/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go index 6dd9c6066..e0346a084 100644 --- a/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go +++ b/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go @@ -27,7 +27,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) { } func buildReadState(opts *rs.Options) (map[string]interface{}, error) { - c, err := gitlab.NewClient() + c, err := gitlab.NewClient(gitlab.WithBaseURL(opts.BaseURL)) if err != nil { return nil, err } @@ -41,21 +41,29 @@ func buildReadState(opts *rs.Options) (map[string]interface{}, error) { } res := make(map[string]interface{}) - res["owner"] = project.Owner.Username - res["org"] = project.Owner.Organization - res["repoName"] = project.Name - outputs := make(map[string]interface{}) - if opts.Owner == "" { - outputs["owner"] = opts.Owner - } else { + + log.Debugf("GitLab Project is: %#v\n", project) + + // if opts.BaseURL != "" { + // res["baseURL"] = opts.BaseURL + // } else { + // res["baseURL"] = strings.TrimSuffix(strings.ReplaceAll(project.WebURL, opts.PathWithNamespace, ""), "/") + // } + + if project.Owner != nil { + log.Debugf("GitLab Project Owner is: %#v\n", project.Owner) + res["owner"] = project.Owner.Username + res["org"] = project.Owner.Organization outputs["owner"] = project.Owner.Username - } - if opts.Org == "" { - outputs["org"] = opts.Org - } else { outputs["org"] = project.Owner.Organization + } else { + res["owner"] = opts.Owner + res["org"] = opts.Org + outputs["owner"] = opts.Owner + outputs["org"] = opts.Org } + res["repoName"] = project.Name outputs["repo"] = project.Name outputs["repoURL"] = project.HTTPURLToRepo res["outputs"] = outputs diff --git a/pkg/util/gitlab/gitlab.go b/pkg/util/gitlab/gitlab.go index 30f27429f..17c053f7d 100644 --- a/pkg/util/gitlab/gitlab.go +++ b/pkg/util/gitlab/gitlab.go @@ -1,7 +1,7 @@ package gitlab import ( - "fmt" + "errors" "os" "github.com/xanzy/go-gitlab" @@ -11,11 +11,24 @@ import ( var client *Client +const ( + DefaultGitlabHost = "https://gitlab.com" +) + +type OptionFunc func(*Client) + +func WithBaseURL(baseURL string) OptionFunc { + return func(c *Client) { + c.baseURL = baseURL + } +} + type Client struct { + baseURL string *gitlab.Client } -func NewClient() (*Client, error) { +func NewClient(opts ...OptionFunc) (*Client, error) { if client != nil { log.Debug("Use a cached client.") return client, nil @@ -23,12 +36,28 @@ func NewClient() (*Client, error) { token := os.Getenv("GITLAB_TOKEN") if token == "" { - return nil, fmt.Errorf("failed to read GITLAB_TOKEN from environment variable") + return nil, errors.New("failed to read GITLAB_TOKEN from environment variable") } - client, err := gitlab.NewClient(token) + + c := &Client{} + + for _, opt := range opts { + opt(c) + } + + var err error + + if c.baseURL == "" { + c.Client, err = gitlab.NewClient(token) + } else { + c.Client, err = gitlab.NewClient(token, gitlab.WithBaseURL(c.baseURL)) + + } + if err != nil { return nil, err } - return &Client{Client: client}, nil + return c, nil + } diff --git a/pkg/util/gitlab/project.go b/pkg/util/gitlab/project.go index 335d47987..ea81b9810 100644 --- a/pkg/util/gitlab/project.go +++ b/pkg/util/gitlab/project.go @@ -9,19 +9,56 @@ import ( // https://docs.gitlab.com/ee/api/projects.html // https://github.com/xanzy/go-gitlab/blob/master/projects.go -func (c *Client) CreateProject(repoName, branch string) error { - log.Debugf("Repo to be created: %s", repoName) +type CreateProjectOptions struct { + Name string + Namespace string + Branch string + Visibility string +} + +// func (c *Client) CreateProject(repoName, branch string) error { +func (c *Client) CreateProject(opts *CreateProjectOptions) error { + log.Debugf("Repo to be created: %s", opts.Name) + + var err error + var res *gitlab.Group + var groupId int + + gitlabGetGroupOptions := &gitlab.GetGroupOptions{} + + if opts.Namespace != "" { + res, _, err = c.Groups.GetGroup(opts.Namespace, gitlabGetGroupOptions) + if err != nil { + return err + } + groupId = res.ID + } + + log.Debugf("Group: %#v\n", res) p := &gitlab.CreateProjectOptions{ - Name: gitlab.String(repoName), + Name: gitlab.String(opts.Name), Description: gitlab.String("Bootstrapped by DevStream."), MergeRequestsEnabled: gitlab.Bool(true), SnippetsEnabled: gitlab.Bool(true), - Visibility: gitlab.Visibility(gitlab.PublicVisibility), - DefaultBranch: gitlab.String(branch), + DefaultBranch: gitlab.String(opts.Branch), } - _, _, err := c.Projects.CreateProject(p) + switch opts.Visibility { + case "public": + p.Visibility = gitlab.Visibility(gitlab.PublicVisibility) + case "internal": + p.Visibility = gitlab.Visibility(gitlab.InternalVisibility) + case "private": + p.Visibility = gitlab.Visibility(gitlab.PrivateVisibility) + default: + p.Visibility = gitlab.Visibility(gitlab.PublicVisibility) + } + + if groupId != 0 { + p.NamespaceID = gitlab.Int(groupId) + } + _, _, err = c.Projects.CreateProject(p) if err != nil { return err } From 69914031e9ca0f8dbf1c0710c5302d6a4f3de099 Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Mon, 30 May 2022 15:05:18 +0800 Subject: [PATCH 2/4] docs: update gitlab-repo-scaffolding-golang doc --- docs/plugins/gitlab-repo-scaffolding-golang.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/plugins/gitlab-repo-scaffolding-golang.md b/docs/plugins/gitlab-repo-scaffolding-golang.md index dcf6e7dda..d482d17fc 100644 --- a/docs/plugins/gitlab-repo-scaffolding-golang.md +++ b/docs/plugins/gitlab-repo-scaffolding-golang.md @@ -33,15 +33,15 @@ tools: options: # the repo's owner. It should be case-sensitive here; strictly use your GitLab user name; please change the value below. owner: YOUR_GITLAB_USERNAME - # the repo's org or group (If it's a subgroup, the value is `groupname/subgroup`). If you set this property, then the new repo will be created under the org or group you're given, and the "owner" setting above will be ignored. + # the repo's org or group (if subgroup, the value is `groupname/subgroup`.) If you set this property, the new repo will be created under the org or group, and the "owner" setting above will be ignored. org: YOUR_ORG_OR_GROUP_NAME # the repo which you'd like to create; please change the value below. repo: YOUR_REPO_NAME # the branch of the repo you'd like to hold the code branch: main - # the visibility of the generated project, its value can be `public` or `private` or `internal` + # the visibility of the created project. Value can be `public`, `private`, or `internal`. visibility: private - # if you are using self-hosted gitlab, set this value to your site address, otherwise set it to null + # set to null if you are using GitLab cloud. For self-hosted GitLab, set this value to your GitLab URL. baseURL: https://yourselfhost.com # the image repo you'd like to push the container image; please change the value below. image_repo: YOUR_DOCKERHUB_USERNAME/YOUR_DOCKERHUB_REPOSITORY @@ -66,4 +66,4 @@ This plugin has four outputs: - `org` - `owner` - `repo` -- `repoURL` (example: "https://gitlab.com/ironcore864/dtm-app-test.git") \ No newline at end of file +- `repoURL` (example: "https://gitlab.com/ironcore864/dtm-app-test.git") From bbfe7ef10df83f3829d831c9a9142f1250099575 Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Mon, 30 May 2022 15:06:23 +0800 Subject: [PATCH 3/4] chore: deleting dead code --- internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go b/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go index e0346a084..30ca6e337 100644 --- a/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go +++ b/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go @@ -45,12 +45,6 @@ func buildReadState(opts *rs.Options) (map[string]interface{}, error) { log.Debugf("GitLab Project is: %#v\n", project) - // if opts.BaseURL != "" { - // res["baseURL"] = opts.BaseURL - // } else { - // res["baseURL"] = strings.TrimSuffix(strings.ReplaceAll(project.WebURL, opts.PathWithNamespace, ""), "/") - // } - if project.Owner != nil { log.Debugf("GitLab Project Owner is: %#v\n", project.Owner) res["owner"] = project.Owner.Username From d88326303ac39be1568ff91a9b5ad9a573f94385 Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Mon, 30 May 2022 15:07:22 +0800 Subject: [PATCH 4/4] chore: minor update of logging format --- internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go b/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go index 30ca6e337..52875c414 100644 --- a/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go +++ b/internal/pkg/plugin/reposcaffolding/gitlab/golang/read.go @@ -46,7 +46,7 @@ func buildReadState(opts *rs.Options) (map[string]interface{}, error) { log.Debugf("GitLab Project is: %#v\n", project) if project.Owner != nil { - log.Debugf("GitLab Project Owner is: %#v\n", project.Owner) + log.Debugf("GitLab project owner is: %#v.\n", project.Owner) res["owner"] = project.Owner.Username res["org"] = project.Owner.Organization outputs["owner"] = project.Owner.Username