Skip to content

Commit

Permalink
Adding the scm_track_submodules option which should fix the ansible#7846
Browse files Browse the repository at this point in the history


Signed-off-by: mazhead <mazhead@gmail.com>
  • Loading branch information
mazhead committed Apr 12, 2021
1 parent 311c443 commit c6eb7da
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 3 deletions.
3 changes: 2 additions & 1 deletion awx/api/serializers.py
Expand Up @@ -1350,6 +1350,7 @@ class Meta:
'scm_branch',
'scm_refspec',
'scm_clean',
'scm_track_submodules',
'scm_delete_on_update',
'credential',
'timeout',
Expand Down Expand Up @@ -1497,7 +1498,7 @@ def get_field_from_model_or_attrs(fd):
)

if get_field_from_model_or_attrs('scm_type') == '':
for fd in ('scm_update_on_launch', 'scm_delete_on_update', 'scm_clean'):
for fd in ('scm_update_on_launch', 'scm_delete_on_update', 'scm_track_submodules', 'scm_clean'):
if get_field_from_model_or_attrs(fd):
raise serializers.ValidationError({fd: _('Update options must be set to false for manual projects.')})
return super(ProjectSerializer, self).validate(attrs)
Expand Down
37 changes: 37 additions & 0 deletions awx/main/migrations/0136_scm_track_submodules.py
@@ -0,0 +1,37 @@
# Generated by Django 2.2.16 on 2021-02-02 14:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
<<<<<<< HEAD:awx/main/migrations/0136_scm_track_submodules.py
('main', '0135_schedule_sort_fallback_to_id'),
=======
('main', '0131_undo_org_polymorphic_ee'),
>>>>>>> Update and rename 0124_scm_track_submodules.py to 0132_scm_track_submodules.py:awx/main/migrations/0132_scm_track_submodules.py
]

operations = [
migrations.AddField(
model_name='Project',
name='scm_track_submodules',
field=models.BooleanField(help_text='Track submodule latest commit on specified branch.'),
),
migrations.AddField(
model_name='ProjectUpdate',
name='scm_track_submodules',
field=models.BooleanField(help_text='Track submodule latest commit on specified branch.'),
),
migrations.AlterField(
model_name='project',
name='scm_track_submodules',
field=models.BooleanField(default=False, help_text='Track submodules latest commits on defined branch.'),
),
migrations.AlterField(
model_name='projectupdate',
name='scm_track_submodules',
field=models.BooleanField(default=False, help_text='Track submodules latest commits on defined branch.'),
),
]
4 changes: 4 additions & 0 deletions awx/main/models/projects.py
Expand Up @@ -115,6 +115,10 @@ def get_local_path_choices(cls):
default=False,
help_text=_('Delete the project before syncing.'),
)
scm_track_submodules = models.BooleanField(
default=False,
help_text=_('Track submodules latest commits on defined branch.'),
)
credential = models.ForeignKey(
'Credential',
related_name='%(class)ss',
Expand Down
1 change: 1 addition & 0 deletions awx/main/tasks.py
Expand Up @@ -2026,6 +2026,7 @@ def build_extra_vars_file(self, project_update, private_data_dir):
'scm_url': scm_url,
'scm_branch': scm_branch,
'scm_clean': project_update.scm_clean,
'scm_track_submodules': project_update.scm_track_submodules,
'roles_enabled': galaxy_creds_are_defined and settings.AWX_ROLES_ENABLED,
'collections_enabled': galaxy_creds_are_defined and settings.AWX_COLLECTIONS_ENABLED,
}
Expand Down
2 changes: 2 additions & 0 deletions awx/playbooks/project_update.yml
Expand Up @@ -12,6 +12,7 @@
# scm_password: password (only for svn/insights)
# scm_accept_hostkey: true/false (only for git, set automatically)
# scm_refspec: a refspec to fetch in addition to obtaining version
# scm_track_submodules: true/false
# roles_enabled: Value of the global setting to enable roles downloading
# collections_enabled: Value of the global setting to enable collections downloading
# awx_version: Current running version of the awx or tower as a string
Expand All @@ -36,6 +37,7 @@
version: "{{scm_branch|quote}}"
refspec: "{{scm_refspec|default(omit)}}"
force: "{{scm_clean}}"
track_submodules: "{{scm_track_submodules|default(omit)}}"
accept_hostkey: "{{scm_accept_hostkey|default(omit)}}"
register: git_result

Expand Down
Expand Up @@ -18,6 +18,7 @@ function PromptProjectDetail({ i18n, resource }) {
scm_branch,
scm_clean,
scm_delete_on_update,
scm_track_submodules,
scm_refspec,
scm_type,
scm_update_on_launch,
Expand All @@ -30,6 +31,7 @@ function PromptProjectDetail({ i18n, resource }) {
if (
scm_clean ||
scm_delete_on_update ||
scm_track_submodules ||
scm_update_on_launch ||
allow_override
) {
Expand All @@ -39,6 +41,11 @@ function PromptProjectDetail({ i18n, resource }) {
{scm_delete_on_update && (
<ListItem>{i18n._(t`Delete on Update`)}</ListItem>
)}
{scm_track_submodules && (
<ListItem>
{i18n._(t`Track submodules latest commit on branch`)}
</ListItem>
)}
{scm_update_on_launch && (
<ListItem>{i18n._(t`Update Revision on Launch`)}</ListItem>
)}
Expand Down
3 changes: 2 additions & 1 deletion awx/ui_next/src/components/PromptDetail/data.project.json
Expand Up @@ -96,6 +96,7 @@
"scm_refspec":"refs/",
"scm_clean":true,
"scm_delete_on_update":true,
"scm_track_submodules":false,
"credential":9,
"timeout":0,
"scm_revision":"",
Expand All @@ -111,4 +112,4 @@
"last_update_failed":false,
"last_updated":"2020-03-11T20:18:14Z",
"default_environment": 1
}
}
Expand Up @@ -18,6 +18,7 @@ describe('<ProjectAdd />', () => {
scm_type: 'git',
scm_url: 'https://foo.bar',
scm_clean: true,
scm_track_submodules: false,
credential: 100,
local_path: '',
organization: { id: 2, name: 'Bar' },
Expand Down
Expand Up @@ -36,6 +36,7 @@ function ProjectDetail({ project, i18n }) {
scm_branch,
scm_clean,
scm_delete_on_update,
scm_track_submodules,
scm_refspec,
scm_type,
scm_update_on_launch,
Expand All @@ -61,6 +62,7 @@ function ProjectDetail({ project, i18n }) {
if (
scm_clean ||
scm_delete_on_update ||
scm_track_submodules ||
scm_update_on_launch ||
allow_override
) {
Expand All @@ -70,6 +72,11 @@ function ProjectDetail({ project, i18n }) {
{scm_delete_on_update && (
<ListItem>{i18n._(t`Delete on Update`)}</ListItem>
)}
{scm_track_submodules && (
<ListItem>
{i18n._(t`Track submodules latest commit on branch`)}
</ListItem>
)}
{scm_update_on_launch && (
<ListItem>{i18n._(t`Update Revision on Launch`)}</ListItem>
)}
Expand Down
Expand Up @@ -70,6 +70,7 @@ describe('<ProjectDetail />', () => {
scm_refspec: 'refs/remotes/*',
scm_clean: true,
scm_delete_on_update: true,
scm_track_submodules: false,
credential: 100,
status: 'successful',
organization: 10,
Expand Down Expand Up @@ -141,6 +142,7 @@ describe('<ProjectDetail />', () => {
scm_type: '',
scm_clean: false,
scm_delete_on_update: false,
scm_track_submodules: false,
scm_update_on_launch: false,
allow_override: false,
created: '',
Expand Down
Expand Up @@ -19,6 +19,7 @@ describe('<ProjectEdit />', () => {
scm_type: 'git',
scm_url: 'https://foo.bar',
scm_clean: true,
scm_track_submodules: false,
credential: 100,
local_path: 'bar',
organization: 2,
Expand Down
3 changes: 2 additions & 1 deletion awx/ui_next/src/screens/Project/data.project.json
Expand Up @@ -104,6 +104,7 @@
"scm_refspec": "",
"scm_clean": false,
"scm_delete_on_update": false,
"scm_track_submodules": false,
"credential": null,
"timeout": 0,
"scm_revision": "f5de82382e756b87143f3511c7c6c006d941830d",
Expand All @@ -119,4 +120,4 @@
"last_update_failed": false,
"last_updated": "2019-09-30T18:06:34.713654Z",
"execution_environment": 1
}
}
3 changes: 3 additions & 0 deletions awx/ui_next/src/screens/Project/shared/ProjectForm.jsx
Expand Up @@ -84,6 +84,7 @@ function ProjectFormFields({
credential: '',
scm_clean: false,
scm_delete_on_update: false,
scm_track_submodules: false,
scm_update_on_launch: false,
allow_override: false,
scm_update_cache_timeout: 0,
Expand Down Expand Up @@ -308,6 +309,7 @@ function ProjectForm({ i18n, project, submitError, ...props }) {
credential: '',
scm_clean: false,
scm_delete_on_update: false,
scm_track_submodules: false,
scm_update_on_launch: false,
allow_override: false,
scm_update_cache_timeout: 0,
Expand Down Expand Up @@ -365,6 +367,7 @@ function ProjectForm({ i18n, project, submitError, ...props }) {
scm_branch: project.scm_branch || '',
scm_clean: project.scm_clean || false,
scm_delete_on_update: project.scm_delete_on_update || false,
scm_track_submodules: project.scm_track_submodules || false,
scm_refspec: project.scm_refspec || '',
scm_type:
project.scm_type === ''
Expand Down
Expand Up @@ -17,6 +17,7 @@ describe('<ProjectForm />', () => {
scm_type: 'git',
scm_url: 'https://foo.bar',
scm_clean: true,
scm_track_submodules: false,
credential: 100,
organization: 2,
scm_update_on_launch: true,
Expand Down
Expand Up @@ -84,6 +84,19 @@ export const ScmTypeOptions = withI18n()(
of time required to complete an update.`
)}
/>
<CheckboxField
id="option-scm-track-submodules"
name="scm_track_submodules"
label={i18n._(t`Track submodules`)}
tooltip={i18n._(
t`if yes, submodules will track the latest commit on
their master branch (or other branch specified in
.gitmodules). If no, submodules will be kept at
the revision specified by the main project.
This is equivalent to specifying the --remote
flag to git submodule update.`
)}
/>
<CheckboxField
id="option-scm-update-on-launch"
name="scm_update_on_launch"
Expand Down
1 change: 1 addition & 0 deletions awx/ui_next/src/types.js
Expand Up @@ -159,6 +159,7 @@ export const Project = shape({
scm_refspec: string,
scm_clean: bool,
scm_delete_on_update: bool,
scm_track_submodules: bool,
credential: number,
status: oneOf([
'new',
Expand Down
8 changes: 8 additions & 0 deletions awx_collection/plugins/modules/tower_project.py
Expand Up @@ -78,6 +78,11 @@
- Remove the repository completely before updating.
type: bool
default: 'no'
scm_track_submodules:
description:
- Track submodules latest commit on specified branch.
type: bool
default: 'no'
scm_update_on_launch:
description:
- Before an update to the local repository before launching a job with this project.
Expand Down Expand Up @@ -245,6 +250,7 @@ def main():
credential=dict(aliases=['scm_credential']),
scm_clean=dict(type='bool', default=False),
scm_delete_on_update=dict(type='bool', default=False),
scm_track_submodules=dict(type='bool', default=False),
scm_update_on_launch=dict(type='bool', default=False),
scm_update_cache_timeout=dict(type='int', default=0),
allow_override=dict(type='bool', aliases=['scm_allow_override']),
Expand Down Expand Up @@ -345,6 +351,7 @@ def main():
'scm_refspec',
'scm_clean',
'scm_delete_on_update',
"scm_track_submodules",
'timeout',
'scm_update_cache_timeout',
'custom_virtualenv',
Expand Down Expand Up @@ -380,3 +387,4 @@ def main():

if __name__ == '__main__':
main()

1 change: 1 addition & 0 deletions awxkit/awxkit/api/pages/projects.py
Expand Up @@ -35,6 +35,7 @@ def payload(self, organization, scm_type='git', **kwargs):
'local_path',
'scm_clean',
'scm_delete_on_update',
'scm_track_submodules',
'scm_update_cache_timeout',
'scm_update_on_launch',
'scm_refspec',
Expand Down

0 comments on commit c6eb7da

Please sign in to comment.