Git Sync: Allow user disable push to configured branch (#113564)

* Git Sync: Allow user disable push to configured branch
This commit is contained in:
Yunwen Zheng
2025-11-07 09:24:34 -05:00
committed by GitHub
parent 1ca95cda4a
commit 8b6cc211e9
7 changed files with 53 additions and 1 deletions
@@ -38,6 +38,7 @@ import { getHasTokenInstructions } from '../utils/git';
import { getRepositoryTypeConfig, isGitProvider } from '../utils/repositoryTypes';
import { ConfigFormGithubCollapse } from './ConfigFormGithubCollapse';
import { EnablePushToConfiguredBranchOption } from './EnablePushToConfiguredBranchOption';
import { getDefaultValues } from './defaults';
// This needs to be a function for translations to work
@@ -303,6 +304,7 @@ export function ConfigForm({ data }: ConfigFormProps) {
onChange: (e) => {
if (e.target.checked) {
setValue('prWorkflow', false);
setValue('enablePushToConfiguredBranch', false);
}
},
})}
@@ -324,6 +326,13 @@ export function ConfigForm({ data }: ConfigFormProps) {
/>
</Field>
)}
{isGitBased && (
<EnablePushToConfiguredBranchOption<RepositoryFormData>
register={register}
registerName="enablePushToConfiguredBranch"
readOnly={readOnly}
/>
)}
{type === 'github' && <ConfigFormGithubCollapse register={register} />}
{isGitBased && (
@@ -0,0 +1,28 @@
import { FieldValues, UseFormRegister, Path } from 'react-hook-form';
import { t } from '@grafana/i18n';
import { Checkbox, Field } from '@grafana/ui';
export function EnablePushToConfiguredBranchOption<T extends FieldValues>({
register,
registerName,
readOnly,
}: {
register: UseFormRegister<T>;
registerName: Path<T>;
readOnly: boolean;
}) {
return (
<Field noMargin>
<Checkbox
disabled={readOnly}
{...register(registerName)}
label={t('provisioning.enable-push-to-configured-branch-label', 'Enable push to configured branch')}
description={t(
'provisioning.enable-push-to-configured-branch-description',
'Allow direct commits to the configured branch.'
)}
/>
</Field>
);
}
@@ -31,6 +31,7 @@ export function getDefaultValues({
target: defaultTarget,
intervalSeconds: 60,
},
enablePushToConfiguredBranch: true,
};
}
return specToData(repository);
@@ -5,6 +5,7 @@ import { Trans, t } from '@grafana/i18n';
import { Checkbox, Field, Input, Stack, Text, TextLink } from '@grafana/ui';
import { useGetFrontendSettingsQuery } from 'app/api/clients/provisioning/v0alpha1';
import { EnablePushToConfiguredBranchOption } from '../Config/EnablePushToConfiguredBranchOption';
import { checkImageRenderer, checkImageRenderingAllowed, checkPublicAccess } from '../GettingStarted/features';
import { isGitProvider } from '../utils/repositoryTypes';
@@ -68,6 +69,7 @@ export const FinishStep = memo(function FinishStep() {
onChange: (e) => {
if (e.target.checked) {
setValue('repository.prWorkflow', false);
setValue('repository.enablePushToConfiguredBranch', false);
}
},
})}
@@ -90,6 +92,14 @@ export const FinishStep = memo(function FinishStep() {
</Field>
)}
{isGitBased && (
<EnablePushToConfiguredBranchOption<WizardFormData>
register={register}
readOnly={readOnly}
registerName="repository.enablePushToConfiguredBranch"
/>
)}
{isGithub && imageRenderingAllowed && (
<Field noMargin>
<Checkbox
@@ -44,6 +44,7 @@ export type RepositoryFormData = Omit<RepositorySpec, 'workflows' | RepositorySp
LocalRepositoryConfig & {
readOnly: boolean;
prWorkflow: boolean;
enablePushToConfiguredBranch: boolean;
// top-level inline secure value
token?: string;
};
@@ -6,7 +6,7 @@ export const getWorkflows = (data: RepositoryFormData): RepositorySpec['workflow
if (data.readOnly) {
return [];
}
const workflows: RepositorySpec['workflows'] = ['write'];
const workflows: RepositorySpec['workflows'] = data.enablePushToConfiguredBranch ? ['write'] : [];
if (!data.prWorkflow) {
return workflows;
@@ -69,6 +69,7 @@ export const specToData = (spec: RepositorySpec): RepositoryFormData => {
generateDashboardPreviews: spec.github?.generateDashboardPreviews || false,
readOnly: !spec.workflows.length,
prWorkflow: spec.workflows.includes('branch'),
enablePushToConfiguredBranch: spec.workflows.includes('write'),
});
};
+2
View File
@@ -11510,6 +11510,8 @@
"empty-state": {
"no-jobs": "No jobs..."
},
"enable-push-to-configured-branch-description": "Allow direct commits to the configured branch.",
"enable-push-to-configured-branch-label": "Enable push to configured branch",
"enhanced-features": {
"description": "Get the most out of your GitHub integration with these optional add-ons",
"description-instant-updates": "Get instant updates in Grafana as soon as changes are committed. Review and approve changes using pull requests before they go live.",