Skip to content

Commit

Permalink
🧹 fallback to directly fetching a project if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Sep 27, 2023
1 parent ad1c9d3 commit 64a09fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
8 changes: 7 additions & 1 deletion motor/discovery/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
10 changes: 9 additions & 1 deletion motor/providers/gitlab/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ 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
}
t.ProjectId = project.ID
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
Expand Down
17 changes: 16 additions & 1 deletion resources/packs/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 64a09fa

Please sign in to comment.