POC/Provisioning: Fix writing directly to a branch (#98948)

This commit is contained in:
Ryan McKinley authored and GitHub committed 2025-01-14 15:17:37 +03:00
1 parent c8f85b04a9
commit 437fea30a3
4 files changed
+16 -11

No files matched your search

@@ -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
@@ -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 });
+1 -1
View File
@@ -13,6 +13,6 @@ export interface ProvisioningPreview {
}
export enum WorkflowOption {
Branch = 'branch',
Direct = 'direct',
PullRequest = 'pr',
}
@@ -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 = /^(?!\/|.*\/\/|.*\.\.|.*@{)(?!.*[~^:?*[\]\\]).+(?<!\/|\.|\s)$/;
return branchNameRegex.test(branchName);
return branchName && branchNameRegex.test(branchName!);
}