From 64a09fa534f9c4389f088d93e0d5c1f18b801093 Mon Sep 17 00:00:00 2001 From: Victoria Jeffrey Date: Wed, 27 Sep 2023 02:01:38 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20fallback=20to=20directly=20fetch?= =?UTF-8?q?ing=20a=20project=20if=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- motor/discovery/gitlab/gitlab.go | 8 +++++++- motor/providers/gitlab/platform.go | 10 +++++++++- resources/packs/gitlab/gitlab.go | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/motor/discovery/gitlab/gitlab.go b/motor/discovery/gitlab/gitlab.go index 8472354040..d29f603bd3 100644 --- a/motor/discovery/gitlab/gitlab.go +++ b/motor/discovery/gitlab/gitlab.go @@ -81,11 +81,17 @@ func (r *Resolver) Resolve(ctx context.Context, root *asset.Asset, pCfg *provide if err != nil { return nil, err } + clonedConfig := pCfg.Clone() + if clonedConfig.Options == nil { + clonedConfig.Options = map[string]string{} + } + clonedConfig.Options["project-id"] = strconv.Itoa(project.ID) + projectAsset := &asset.Asset{ PlatformIds: []string{identifier}, Name: name, Platform: pf, - Connections: []*providers.Config{pCfg}, // pass-in the current config + Connections: []*providers.Config{clonedConfig}, // pass-in the current config State: asset.State_STATE_ONLINE, } diff --git a/motor/providers/gitlab/platform.go b/motor/providers/gitlab/platform.go index 40abbbc5de..e9b36394d7 100644 --- a/motor/providers/gitlab/platform.go +++ b/motor/providers/gitlab/platform.go @@ -86,7 +86,7 @@ func (t *Provider) Project() (*gitlab.Project, error) { pid = t.ProjectId } - project, _, err := t.Client().Projects.GetProject(pid, nil) + project, err := t.GetProjectById(pid) if err != nil { return nil, err } @@ -94,6 +94,14 @@ func (t *Provider) Project() (*gitlab.Project, error) { return project, err } +func (t *Provider) GetProjectById(pid interface{}) (*gitlab.Project, error) { + project, _, err := t.Client().Projects.GetProject(pid, nil) + if err != nil { + return nil, err + } + return project, err +} + func (p *Provider) PlatformInfo() (*platform.Platform, error) { if projectName := p.opts["project"]; projectName != "" { return GitLabProjectPlatform, nil diff --git a/resources/packs/gitlab/gitlab.go b/resources/packs/gitlab/gitlab.go index 152731b750..8a4e550813 100644 --- a/resources/packs/gitlab/gitlab.go +++ b/resources/packs/gitlab/gitlab.go @@ -151,8 +151,23 @@ func (g *mqlGitlabProject) init(args *resources.Args) (*resources.Args, GitlabPr return args, proj, nil } } + // try to fetch it directly + gt, err := gitlabProvider(g.MotorRuntime.Motor.Provider) + if err != nil { + return nil, nil, err + } + prj, err := gt.GetProjectById(projectId) + if err != nil { + return nil, nil, errors.New("project not found") + } - return nil, nil, errors.New("project not found") + (*args)["id"] = int64(prj.ID) + (*args)["name"] = prj.Name + (*args)["path"] = prj.Path + (*args)["namespace"] = prj.Namespace.Name + (*args)["description"] = prj.Description + (*args)["visibility"] = string(prj.Visibility) + return args, nil, nil } func getAssetIdentifier(runtime *resources.Runtime, t string) *string {