diff --git a/resources/packs/gitlab/gitlab.go b/resources/packs/gitlab/gitlab.go index cc7743c6bd..8ecf319e17 100644 --- a/resources/packs/gitlab/gitlab.go +++ b/resources/packs/gitlab/gitlab.go @@ -112,7 +112,7 @@ func (g *mqlGitlabProject) init(args *resources.Args) (*resources.Args, GitlabPr return nil, nil, err } - project, _, err := gt.Client().Projects.GetProject(url.QueryEscape(gt.GroupPath)+url.QueryEscape(gt.ProjectPath), nil) + project, _, err := gt.Client().Projects.GetProject(url.QueryEscape(gt.GroupPath)+"/"+url.QueryEscape(gt.ProjectPath), nil) if err != nil { return nil, nil, err } diff --git a/resources/packs/gitlab/gitlab.lr.go b/resources/packs/gitlab/gitlab.lr.go index bbe71cf0df..b01c2a6c8a 100644 --- a/resources/packs/gitlab/gitlab.lr.go +++ b/resources/packs/gitlab/gitlab.lr.go @@ -356,6 +356,7 @@ type GitlabProject interface { Id() (int64, error) Name() (string, error) Path() (string, error) + Namespace() (string, error) Description() (string, error) Visibility() (string, error) } @@ -375,6 +376,15 @@ func newGitlabProject(runtime *resources.Runtime, args *resources.Args) (interfa // User hooks var err error res := mqlGitlabProject{runtime.NewResource("gitlab.project")} + var existing GitlabProject + args, existing, err = res.init(args) + if err != nil { + return nil, err + } + if existing != nil { + return existing, nil + } + // assign all named fields var id string @@ -398,6 +408,10 @@ func newGitlabProject(runtime *resources.Runtime, args *resources.Args) (interfa if _, ok := val.(string); !ok { return nil, errors.New("Failed to initialize \"gitlab.project\", its \"path\" argument has the wrong type (expected type \"string\")") } + case "namespace": + if _, ok := val.(string); !ok { + return nil, errors.New("Failed to initialize \"gitlab.project\", its \"namespace\" argument has the wrong type (expected type \"string\")") + } case "description": if _, ok := val.(string); !ok { return nil, errors.New("Failed to initialize \"gitlab.project\", its \"description\" argument has the wrong type (expected type \"string\")") @@ -442,6 +456,9 @@ func (s *mqlGitlabProject) Validate() error { if _, ok := s.Cache.Load("path"); !ok { return errors.New("Initialized \"gitlab.project\" resource without a \"path\". This field is required.") } + if _, ok := s.Cache.Load("namespace"); !ok { + return errors.New("Initialized \"gitlab.project\" resource without a \"namespace\". This field is required.") + } if _, ok := s.Cache.Load("description"); !ok { return errors.New("Initialized \"gitlab.project\" resource without a \"description\". This field is required.") } @@ -462,6 +479,8 @@ func (s *mqlGitlabProject) Register(name string) error { return nil case "path": return nil + case "namespace": + return nil case "description": return nil case "visibility": @@ -481,6 +500,8 @@ func (s *mqlGitlabProject) Field(name string) (interface{}, error) { return s.Name() case "path": return s.Path() + case "namespace": + return s.Namespace() case "description": return s.Description() case "visibility": @@ -538,6 +559,22 @@ func (s *mqlGitlabProject) Path() (string, error) { return tres, nil } +// Namespace accessor autogenerated +func (s *mqlGitlabProject) Namespace() (string, error) { + res, ok := s.Cache.Load("namespace") + if !ok || !res.Valid { + return "", errors.New("\"gitlab.project\" failed: no value provided for static field \"namespace\"") + } + if res.Error != nil { + return "", res.Error + } + tres, ok := res.Data.(string) + if !ok { + return "", fmt.Errorf("\"gitlab.project\" failed to cast field \"namespace\" to the right type (string): %#v", res) + } + return tres, nil +} + // Description accessor autogenerated func (s *mqlGitlabProject) Description() (string, error) { res, ok := s.Cache.Load("description") @@ -580,6 +617,8 @@ func (s *mqlGitlabProject) MqlCompute(name string) error { return nil case "path": return nil + case "namespace": + return nil case "description": return nil case "visibility": diff --git a/resources/packs/gitlab/info/gitlab.lr.json b/resources/packs/gitlab/info/gitlab.lr.json index bbb3e3d9dc..e64d03037a 100644 --- a/resources/packs/gitlab/info/gitlab.lr.json +++ b/resources/packs/gitlab/info/gitlab.lr.json @@ -1 +1 @@ -{"resources":{"gitlab.group":{"id":"gitlab.group","name":"gitlab.group","fields":{"description":{"name":"description","type":"\u0007","is_mandatory":true,"title":"Group description"},"id":{"name":"id","type":"\u0005","is_mandatory":true,"title":"Group ID"},"name":{"name":"name","type":"\u0007","is_mandatory":true,"title":"Group name"},"path":{"name":"path","type":"\u0007","is_mandatory":true,"title":"Group path"},"projects":{"name":"projects","type":"\u0019\u001bgitlab.project","title":"List all projects that belong to the group"},"requireTwoFactorAuthentication":{"name":"requireTwoFactorAuthentication","type":"\u0004","is_mandatory":true,"title":"Require all users in this group to setup Two-factor authentication."},"visibility":{"name":"visibility","type":"\u0007","is_mandatory":true,"title":"Group visibility. Can be private, internal, or public."}},"title":"GitLab Group"},"gitlab.project":{"id":"gitlab.project","name":"gitlab.project","fields":{"description":{"name":"description","type":"\u0007","is_mandatory":true,"title":"Project description"},"id":{"name":"id","type":"\u0005","is_mandatory":true,"title":"Project ID"},"name":{"name":"name","type":"\u0007","is_mandatory":true,"title":"Project name"},"path":{"name":"path","type":"\u0007","is_mandatory":true,"title":"Project path"},"visibility":{"name":"visibility","type":"\u0007","is_mandatory":true,"title":"The project's visibility level. Can be private, internal, or public."}},"title":"GitLab Project"}}} \ No newline at end of file +{"resources":{"gitlab.group":{"id":"gitlab.group","name":"gitlab.group","fields":{"description":{"name":"description","type":"\u0007","is_mandatory":true,"title":"Group description"},"id":{"name":"id","type":"\u0005","is_mandatory":true,"title":"Group ID"},"name":{"name":"name","type":"\u0007","is_mandatory":true,"title":"Group name"},"path":{"name":"path","type":"\u0007","is_mandatory":true,"title":"Group path"},"projects":{"name":"projects","type":"\u0019\u001bgitlab.project","title":"List all projects that belong to the group"},"requireTwoFactorAuthentication":{"name":"requireTwoFactorAuthentication","type":"\u0004","is_mandatory":true,"title":"Require all users in this group to setup Two-factor authentication."},"visibility":{"name":"visibility","type":"\u0007","is_mandatory":true,"title":"Group visibility. Can be private, internal, or public."}},"title":"GitLab Group","defaults":"path"},"gitlab.project":{"id":"gitlab.project","name":"gitlab.project","fields":{"description":{"name":"description","type":"\u0007","is_mandatory":true,"title":"Project description"},"id":{"name":"id","type":"\u0005","is_mandatory":true,"title":"Project ID"},"name":{"name":"name","type":"\u0007","is_mandatory":true,"title":"Project name"},"namespace":{"name":"namespace","type":"\u0007","is_mandatory":true,"title":"Project namespace"},"path":{"name":"path","type":"\u0007","is_mandatory":true,"title":"Project path"},"visibility":{"name":"visibility","type":"\u0007","is_mandatory":true,"title":"The project's visibility level. Can be private, internal, or public."}},"title":"GitLab Project","defaults":"name namespace"}}} \ No newline at end of file