Skip to content

Commit

Permalink
🧹 add namespace to gitlab project
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed Sep 17, 2023
1 parent 4cd2cbd commit 27574be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
28 changes: 28 additions & 0 deletions resources/packs/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gitlab

import (
"errors"
"net/url"
"strconv"

"go.mondoo.com/cnquery/motor/providers"
Expand Down Expand Up @@ -82,6 +83,7 @@ func (g *mqlGitlabGroup) GetProjects() ([]interface{}, error) {
"id", int64(prj.ID),
"name", prj.Name,
"path", prj.Path,
"namespace", prj.Namespace.Name,
"description", prj.Description,
"visibility", string(prj.Visibility),
)
Expand All @@ -98,3 +100,29 @@ func (g *mqlGitlabProject) id() (string, error) {
id, _ := g.Id()
return "gitlab.project/" + strconv.FormatInt(id, 10), nil
}

// init initializes the gitlab project with the arguments
func (g *mqlGitlabProject) init(args *resources.Args) (*resources.Args, GitlabProject, error) {
if len(*args) > 2 {
return args, nil, nil
}

gt, err := gitlabProvider(g.MotorRuntime.Motor.Provider)
if err != nil {
return nil, nil, err
}

project, _, err := gt.Client().Projects.GetProject(url.QueryEscape(gt.GroupPath)+url.QueryEscape(gt.ProjectPath), nil)
if err != nil {
return nil, nil, err
}

(*args)["id"] = int64(project.ID)
(*args)["name"] = project.Name
(*args)["path"] = project.Path
(*args)["namespace"] = project.Namespace.Name
(*args)["description"] = project.Description
(*args)["visibility"] = string(project.Visibility)

return args, nil, nil
}
6 changes: 4 additions & 2 deletions resources/packs/gitlab/gitlab.lr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "../core/core.lr"
option go_package = "go.mondoo.com/cnquery/resources/packs/gitlab"

// GitLab Group
gitlab.group {
gitlab.group @defaults("path") {
// Group ID
id int
// Group name
Expand All @@ -21,13 +21,15 @@ gitlab.group {
}

// GitLab Project
gitlab.project {
gitlab.project @defaults("name namespace") {
// Project ID
id int
// Project name
name string
// Project path
path string
// Project namespace
namespace string
// Project description
description string
// The project's visibility level. Can be private, internal, or public.
Expand Down

0 comments on commit 27574be

Please sign in to comment.