diff --git a/pkg/registry/apis/provisioning/resources/parser.go b/pkg/registry/apis/provisioning/resources/parser.go index 9148a38f7e0..bf634b81956 100644 --- a/pkg/registry/apis/provisioning/resources/parser.go +++ b/pkg/registry/apis/provisioning/resources/parser.go @@ -228,9 +228,13 @@ func (r *Parser) Parse(ctx context.Context, info *repository.FileInfo, validate } func (f *ParsedResource) ToSaveBytes() ([]byte, error) { - // TODO... should use the validated one? - obj := f.Obj.Object - delete(obj, "metadata") + // TODO? should we use the dryRun (validated) version? + obj := make(map[string]any) + for k, v := range f.Obj.Object { + if k != "metadata" { + obj[k] = v + } + } switch path.Ext(f.Info.Path) { // JSON pretty print diff --git a/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx b/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx index dbec204d1cd..0c44cd2e69a 100644 --- a/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx +++ b/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx @@ -22,7 +22,7 @@ import { SaveDashboardFormCommonOptions } from './SaveDashboardForm'; import { DashboardChangeInfo } from './shared'; type FormData = { - ref: string; + ref?: string; path: string; comment?: string; repo: string; @@ -54,12 +54,12 @@ function getDefaultValues(meta: DashboardMeta, repository = '') { } const getDefaultWorkflow = (config?: RepositorySpec) => { - return config?.github?.branchWorkflow ? WorkflowOption.PullRequest : WorkflowOption.Branch; + return config?.github?.branchWorkflow ? WorkflowOption.PullRequest : WorkflowOption.Direct; }; function getWorkflowOptions(branch = 'main') { return [ - { label: `Commit to ${branch}`, value: WorkflowOption.Branch }, + { label: `Commit to ${branch}`, value: WorkflowOption.Direct }, { label: 'Create pull request', value: WorkflowOption.PullRequest }, ]; } @@ -127,14 +127,15 @@ export function SaveProvisionedDashboard({ drawer, changeInfo, dashboard }: Prop return; } + // The dashboard spec const saveModel = dashboard.getSaveAsModel({ isNew: isNew, title: title, description: description, }); - if (workflow === WorkflowOption.Branch) { - ref = repositoryConfig?.github?.branch || 'main'; + if (workflow === WorkflowOption.Direct) { + ref = undefined; } action({ ref, name: repo, path, message: comment, body: saveModel }); diff --git a/public/app/features/provisioning/types.ts b/public/app/features/provisioning/types.ts index 8603b34af50..b33ae57c758 100644 --- a/public/app/features/provisioning/types.ts +++ b/public/app/features/provisioning/types.ts @@ -13,6 +13,6 @@ export interface ProvisioningPreview { } export enum WorkflowOption { - Branch = 'branch', + Direct = 'direct', PullRequest = 'pr', } diff --git a/public/app/features/provisioning/utils/git.ts b/public/app/features/provisioning/utils/git.ts index 447832011ff..6905e69d418 100644 --- a/public/app/features/provisioning/utils/git.ts +++ b/public/app/features/provisioning/utils/git.ts @@ -16,8 +16,8 @@ export function createPRLink(spec?: RepositorySpec, dashboardName?: string, ref? * 5. The branch name cannot include the following characters: `~`, `^`, `:`, `?`, `*`, `[`, `\`, or `]`. * 6. The branch name must have at least one character and must not be empty. */ -export function validateBranchName(branchName: string) { +export function validateBranchName(branchName?: string) { const branchNameRegex = /^(?!\/|.*\/\/|.*\.\.|.*@{)(?!.*[~^:?*[\]\\]).+(?