From 8e4be891c507cca4519be61653ba5b31f9983570 Mon Sep 17 00:00:00 2001 From: Daniele Stefano Ferru Date: Thu, 27 Nov 2025 16:06:03 +0100 Subject: [PATCH] Provisioning: add URL and Path in setting response (#114534) * Provisioning: add URL and Path in setting response * linting * marking fields as non-required --- .../pkg/apis/provisioning/v0alpha1/settings.go | 6 ++++++ .../provisioning/v0alpha1/zz_generated.openapi.go | 14 ++++++++++++++ .../rtkq/provisioning/v0alpha1/endpoints.gen.ts | 4 ++++ pkg/registry/apis/provisioning/routes.go | 4 ++++ .../provisioning.grafana.app-v0alpha1.json | 8 ++++++++ pkg/tests/apis/provisioning/repository_test.go | 13 +++++++++++++ 6 files changed, 49 insertions(+) diff --git a/apps/provisioning/pkg/apis/provisioning/v0alpha1/settings.go b/apps/provisioning/pkg/apis/provisioning/v0alpha1/settings.go index ee5d264fd83..3031bde77cb 100644 --- a/apps/provisioning/pkg/apis/provisioning/v0alpha1/settings.go +++ b/apps/provisioning/pkg/apis/provisioning/v0alpha1/settings.go @@ -43,6 +43,12 @@ type RepositoryView struct { // For git, this is the target branch Branch string `json:"branch,omitempty"` + // For git, this is the target URL + URL string `json:"url,omitempty"` + + // For git, this is the target path + Path string `json:"path,omitempty"` + // The supported workflows Workflows []Workflow `json:"workflows"` } diff --git a/apps/provisioning/pkg/apis/provisioning/v0alpha1/zz_generated.openapi.go b/apps/provisioning/pkg/apis/provisioning/v0alpha1/zz_generated.openapi.go index 18c385ce59c..9a4a99d703a 100644 --- a/apps/provisioning/pkg/apis/provisioning/v0alpha1/zz_generated.openapi.go +++ b/apps/provisioning/pkg/apis/provisioning/v0alpha1/zz_generated.openapi.go @@ -1690,6 +1690,20 @@ func schema_pkg_apis_provisioning_v0alpha1_RepositoryView(ref common.ReferenceCa Format: "", }, }, + "url": { + SchemaProps: spec.SchemaProps{ + Description: "For git, this is the target URL", + Type: []string{"string"}, + Format: "", + }, + }, + "path": { + SchemaProps: spec.SchemaProps{ + Description: "For git, this is the target path", + Type: []string{"string"}, + Format: "", + }, + }, "workflows": { SchemaProps: spec.SchemaProps{ Description: "The supported workflows", diff --git a/packages/grafana-api-clients/src/clients/rtkq/provisioning/v0alpha1/endpoints.gen.ts b/packages/grafana-api-clients/src/clients/rtkq/provisioning/v0alpha1/endpoints.gen.ts index 67bdca12d27..7ef1fc4fc91 100644 --- a/packages/grafana-api-clients/src/clients/rtkq/provisioning/v0alpha1/endpoints.gen.ts +++ b/packages/grafana-api-clients/src/clients/rtkq/provisioning/v0alpha1/endpoints.gen.ts @@ -1581,6 +1581,8 @@ export type RepositoryView = { branch?: string; /** The k8s name for this repository */ name: string; + /** For git, this is the target path */ + path?: string; /** When syncing, where values are saved Possible enum values: @@ -1598,6 +1600,8 @@ export type RepositoryView = { - `"gitlab"` - `"local"` */ type: 'bitbucket' | 'git' | 'github' | 'gitlab' | 'local'; + /** For git, this is the target URL */ + url?: string; /** The supported workflows */ workflows: ('branch' | 'write')[]; }; diff --git a/pkg/registry/apis/provisioning/routes.go b/pkg/registry/apis/provisioning/routes.go index 4ffefcdfdbb..494d47d16e7 100644 --- a/pkg/registry/apis/provisioning/routes.go +++ b/pkg/registry/apis/provisioning/routes.go @@ -172,6 +172,8 @@ func (b *APIBuilder) handleSettings(w http.ResponseWriter, r *http.Request) { for i, val := range all { branch := val.Branch() + url := val.URL() + path := val.Path() settings.Items[i] = provisioning.RepositoryView{ Name: val.Name, @@ -179,6 +181,8 @@ func (b *APIBuilder) handleSettings(w http.ResponseWriter, r *http.Request) { Type: val.Spec.Type, Target: val.Spec.Sync.Target, Branch: branch, + URL: url, + Path: path, Workflows: val.Spec.Workflows, } } diff --git a/pkg/tests/apis/openapi_snapshots/provisioning.grafana.app-v0alpha1.json b/pkg/tests/apis/openapi_snapshots/provisioning.grafana.app-v0alpha1.json index bdfa6ce9490..f99b8f60738 100644 --- a/pkg/tests/apis/openapi_snapshots/provisioning.grafana.app-v0alpha1.json +++ b/pkg/tests/apis/openapi_snapshots/provisioning.grafana.app-v0alpha1.json @@ -4309,6 +4309,10 @@ "type": "string", "default": "" }, + "path": { + "description": "For git, this is the target path", + "type": "string" + }, "target": { "description": "When syncing, where values are saved\n\nPossible enum values:\n - `\"folder\"` Resources will be saved into a folder managed by this repository It will contain a copy of everything from the remote The folder k8s name will be the same as the repository k8s name\n - `\"instance\"` Resources are saved in the global context Only one repository may specify the `instance` target When this exists, the UI will promote writing to the instance repo rather than the grafana database (where possible)", "type": "string", @@ -4335,6 +4339,10 @@ "local" ] }, + "url": { + "description": "For git, this is the target URL", + "type": "string" + }, "workflows": { "description": "The supported workflows", "type": "array", diff --git a/pkg/tests/apis/provisioning/repository_test.go b/pkg/tests/apis/provisioning/repository_test.go index 273d78c4e99..d7850c52d0a 100644 --- a/pkg/tests/apis/provisioning/repository_test.go +++ b/pkg/tests/apis/provisioning/repository_test.go @@ -136,6 +136,19 @@ func TestIntegrationProvisioning_CreatingAndGetting(t *testing.T) { return } + for _, i := range settings.Items { + switch i.Type { + case provisioning.LocalRepositoryType: + assert.Equal(collect, i.Path, helper.ProvisioningPath) + case provisioning.GitHubRepositoryType: + assert.Equal(collect, i.URL, "https://github.com/grafana/grafana-git-sync-demo") + assert.Equal(collect, i.Path, "grafana/") + default: + assert.NotEmpty(collect, i.Path) + assert.NotEmpty(collect, i.URL) + } + } + assert.ElementsMatch(collect, []provisioning.RepositoryType{ provisioning.LocalRepositoryType, provisioning.GitHubRepositoryType,