mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 10:27:34 -02:30
Allow modify scm branch override
* Source Control Branch was not being displayed as part of the JobTemplate Edit, since the project did not have the variable `allow_override` as part of the summary_fields. * Add source control details for JobDetail and WorkflowJobTemplateDetail See: https://github.com/ansible/awx/issues/8788
This commit is contained in:
@@ -150,7 +150,7 @@ SUMMARIZABLE_FK_FIELDS = {
|
|||||||
'group': DEFAULT_SUMMARY_FIELDS,
|
'group': DEFAULT_SUMMARY_FIELDS,
|
||||||
'default_environment': DEFAULT_SUMMARY_FIELDS + ('image',),
|
'default_environment': DEFAULT_SUMMARY_FIELDS + ('image',),
|
||||||
'execution_environment': DEFAULT_SUMMARY_FIELDS + ('image',),
|
'execution_environment': DEFAULT_SUMMARY_FIELDS + ('image',),
|
||||||
'project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
|
'project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type', 'allow_override'),
|
||||||
'source_project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
|
'source_project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
|
||||||
'project_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed'),
|
'project_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed'),
|
||||||
'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'kubernetes', 'credential_type_id'),
|
'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'kubernetes', 'credential_type_id'),
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ const QS_CONFIG = getQSConfig('project', {
|
|||||||
function ProjectLookup({
|
function ProjectLookup({
|
||||||
helperTextInvalid,
|
helperTextInvalid,
|
||||||
autoPopulate,
|
autoPopulate,
|
||||||
|
|
||||||
isValid,
|
isValid,
|
||||||
onChange,
|
onChange,
|
||||||
required,
|
required,
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ function JobDetail({ job }) {
|
|||||||
source_workflow_job,
|
source_workflow_job,
|
||||||
execution_environment: executionEnvironment,
|
execution_environment: executionEnvironment,
|
||||||
} = job.summary_fields;
|
} = job.summary_fields;
|
||||||
|
const { scm_branch: scmBranch } = job;
|
||||||
const [errorMsg, setErrorMsg] = useState();
|
const [errorMsg, setErrorMsg] = useState();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
@@ -224,6 +225,13 @@ function JobDetail({ job }) {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{scmBranch && (
|
||||||
|
<Detail
|
||||||
|
dataCy="source-control-branch"
|
||||||
|
label={t`Source Control Branch`}
|
||||||
|
value={scmBranch}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Detail label={t`Revision`} value={job.scm_revision} />
|
<Detail label={t`Revision`} value={job.scm_revision} />
|
||||||
<Detail label={t`Playbook`} value={job.playbook} />
|
<Detail label={t`Playbook`} value={job.playbook} />
|
||||||
<Detail label={t`Limit`} value={job.limit} />
|
<Detail label={t`Limit`} value={job.limit} />
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ describe('<JobDetail />', () => {
|
|||||||
assertDetail('Job Slice', '0/1');
|
assertDetail('Job Slice', '0/1');
|
||||||
assertDetail('Credentials', 'SSH: Demo Credential');
|
assertDetail('Credentials', 'SSH: Demo Credential');
|
||||||
assertDetail('Machine Credential', 'SSH: Machine cred');
|
assertDetail('Machine Credential', 'SSH: Machine cred');
|
||||||
|
assertDetail('Source Control Branch', 'main');
|
||||||
|
|
||||||
const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail');
|
const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail');
|
||||||
expect(executionEnvironment).toHaveLength(1);
|
expect(executionEnvironment).toHaveLength(1);
|
||||||
|
|||||||
@@ -103,6 +103,7 @@
|
|||||||
"inventory": 1,
|
"inventory": 1,
|
||||||
"project": 6,
|
"project": 6,
|
||||||
"playbook": "chatty_tasks.yml",
|
"playbook": "chatty_tasks.yml",
|
||||||
|
"scm_branch": "main",
|
||||||
"forks": 0,
|
"forks": 0,
|
||||||
"limit": "",
|
"limit": "",
|
||||||
"verbosity": 0,
|
"verbosity": 0,
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ function ProjectFormFields({
|
|||||||
project_base_dir,
|
project_base_dir,
|
||||||
project_local_paths,
|
project_local_paths,
|
||||||
formik,
|
formik,
|
||||||
|
|
||||||
setCredentials,
|
setCredentials,
|
||||||
credentials,
|
credentials,
|
||||||
scmTypeOptions,
|
scmTypeOptions,
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ function WorkflowJobTemplateDetail({ template }) {
|
|||||||
related,
|
related,
|
||||||
webhook_credential,
|
webhook_credential,
|
||||||
webhook_key,
|
webhook_key,
|
||||||
|
scm_branch: scmBranch,
|
||||||
} = template;
|
} = template;
|
||||||
|
|
||||||
const urlOrigin = window.location.origin;
|
const urlOrigin = window.location.origin;
|
||||||
@@ -130,6 +131,13 @@ function WorkflowJobTemplateDetail({ template }) {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{scmBranch && (
|
||||||
|
<Detail
|
||||||
|
dataCy="source-control-branch"
|
||||||
|
label={t`Source Control Branch`}
|
||||||
|
value={scmBranch}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{summary_fields?.execution_environment && (
|
{summary_fields?.execution_environment && (
|
||||||
<Detail
|
<Detail
|
||||||
label={t`Execution Environment`}
|
label={t`Execution Environment`}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ describe('<WorkflowJobTemplateDetail/>', () => {
|
|||||||
webhook_service: 'Github',
|
webhook_service: 'Github',
|
||||||
webhook_key: 'Foo webhook key',
|
webhook_key: 'Foo webhook key',
|
||||||
execution_environment: 4,
|
execution_environment: 4,
|
||||||
|
scm_branch: 'main',
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -109,6 +110,11 @@ describe('<WorkflowJobTemplateDetail/>', () => {
|
|||||||
prop: 'value',
|
prop: 'value',
|
||||||
value: 'http://localhost/api/v2/workflow_job_templates/45/github/',
|
value: 'http://localhost/api/v2/workflow_job_templates/45/github/',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
element: 'Detail[label="Source Control Branch"]',
|
||||||
|
prop: 'value',
|
||||||
|
value: 'main',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
element: "Detail[label='Webhook Service']",
|
element: "Detail[label='Webhook Service']",
|
||||||
prop: 'value',
|
prop: 'value',
|
||||||
|
|||||||
@@ -313,10 +313,11 @@ function JobTemplateForm({
|
|||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
id="template-scm-branch"
|
id="template-scm-branch"
|
||||||
{...scmField}
|
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
scmHelpers.setValue(value);
|
scmHelpers.setValue(value);
|
||||||
}}
|
}}
|
||||||
|
value={scmField.value}
|
||||||
|
aria-label={t`source control branch`}
|
||||||
/>
|
/>
|
||||||
</FieldWithPrompt>
|
</FieldWithPrompt>
|
||||||
)}
|
)}
|
||||||
@@ -660,6 +661,7 @@ JobTemplateForm.defaultProps = {
|
|||||||
inventory: undefined,
|
inventory: undefined,
|
||||||
project: undefined,
|
project: undefined,
|
||||||
playbook: '',
|
playbook: '',
|
||||||
|
scm_branch: '',
|
||||||
summary_fields: {
|
summary_fields: {
|
||||||
inventory: null,
|
inventory: null,
|
||||||
labels: { results: [] },
|
labels: { results: [] },
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ describe('<JobTemplateForm />', () => {
|
|||||||
project: {
|
project: {
|
||||||
id: 3,
|
id: 3,
|
||||||
name: 'qux',
|
name: 'qux',
|
||||||
|
allow_override: false,
|
||||||
},
|
},
|
||||||
labels: {
|
labels: {
|
||||||
results: [
|
results: [
|
||||||
@@ -113,7 +114,7 @@ describe('<JobTemplateForm />', () => {
|
|||||||
ProjectsAPI.readDetail.mockReturnValue({
|
ProjectsAPI.readDetail.mockReturnValue({
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
id: 1,
|
id: 1,
|
||||||
allow_override: true,
|
allow_override: false,
|
||||||
});
|
});
|
||||||
ProjectsAPI.readPlaybooks.mockReturnValue({
|
ProjectsAPI.readPlaybooks.mockReturnValue({
|
||||||
data: ['debug.yml'],
|
data: ['debug.yml'],
|
||||||
@@ -152,6 +153,30 @@ describe('<JobTemplateForm />', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not render source control branch when allow_override is false', async () => {
|
||||||
|
let wrapper;
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<JobTemplateForm
|
||||||
|
template={mockData}
|
||||||
|
handleSubmit={jest.fn()}
|
||||||
|
handleCancel={jest.fn()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
expect(wrapper.find('TextInputBase#template-scm-branch').length).toEqual(0);
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('ProjectLookup').invoke('onChange')({
|
||||||
|
id: 4,
|
||||||
|
name: 'project',
|
||||||
|
allow_override: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
expect(wrapper.find('TextInputBase#template-scm-branch').length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('should update form values on input changes', async () => {
|
test('should update form values on input changes', async () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
|||||||
@@ -186,10 +186,11 @@ function WorkflowJobTemplateForm({
|
|||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
id="wfjt-scm-branch"
|
id="wfjt-scm-branch"
|
||||||
{...scmField}
|
value={scmField.value}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
scmHelpers.setValue(value);
|
scmHelpers.setValue(value);
|
||||||
}}
|
}}
|
||||||
|
aria-label={t`source control branch`}
|
||||||
/>
|
/>
|
||||||
</FieldWithPrompt>
|
</FieldWithPrompt>
|
||||||
<ExecutionEnvironmentLookup
|
<ExecutionEnvironmentLookup
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ export const JobTemplate = shape({
|
|||||||
job_type: oneOf(['run', 'check']),
|
job_type: oneOf(['run', 'check']),
|
||||||
playbook: string,
|
playbook: string,
|
||||||
project: number,
|
project: number,
|
||||||
|
scm_branch: string,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const WorkFlowJobTemplate = shape({
|
export const WorkFlowJobTemplate = shape({
|
||||||
|
|||||||
Reference in New Issue
Block a user