Skip to content

Commit

Permalink
add git repo to watches creating
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Dec 18, 2024
1 parent 5099e8c commit 6f3682e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions xray/services/utils/watchbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
WatchRepositoriesAll WatchRepositoriesType = "all"
// WatchRepositoriesByName is the option where repositories are selected by name to be watched
WatchRepositoriesByName WatchRepositoriesType = "byname"

WatchGitRepository = "gitRepository"
)

// WatchBuildType defines the type of filter for a builds on a watch
Expand Down Expand Up @@ -57,9 +59,10 @@ type WatchParams struct {
Description string
Active bool

Repositories WatchRepositoriesParams
Repositories WatchRepositoriesParams
GitRepositories WatchGitRepositoryParams
Builds WatchBuildsParams

Builds WatchBuildsParams
Policies []AssignedPolicy
}

Expand All @@ -76,6 +79,10 @@ type WatchRepositoryAll struct {
Filters watchFilters
}

type WatchGitRepositoryParams struct {
Resources []string
}

// WatchRepository is used to define a specific repository in a watch
type WatchRepository struct {
Name string
Expand Down Expand Up @@ -192,9 +199,26 @@ func CreateBody(params WatchParams) (*WatchBody, error) {
return nil, err
}

err = configureGitRepositories(&payloadBody, params)
if err != nil {
return nil, err
}

return &payloadBody, nil
}

func configureGitRepositories(payloadBody *WatchBody, params WatchParams) error {

Check failure on line 210 in xray/services/utils/watchbody.go

View workflow job for this annotation

GitHub Actions / Static-Check

configureGitRepositories - result 0 (error) is always nil (unparam)
for _, gitRepoResource := range params.GitRepositories.Resources {
gitRepo := watchProjectResourcesElement{
Type: WatchGitRepository,
BinMgrID: "default",
Name: gitRepoResource,
}
payloadBody.ProjectResources.Resources = append(payloadBody.ProjectResources.Resources, gitRepo)
}
return nil
}

func configureRepositories(payloadBody *WatchBody, params WatchParams) error {
// Filters needs to be an empty array for Xray to accept the payload.

Expand Down

0 comments on commit 6f3682e

Please sign in to comment.