layerindex: Add actual_branch to forms and views

For layers which do not follow standard branch names (including
the inclusive naming move away from "master" to "main") we have
the actual_branch field set in a LayerBranch object. Previously
this was only exposed via the admin interface.

Allow layer maintainers (including upon submitting a new layer)
to set the 'Actual branch' in the web UI.

Add a check to make sure the actual_branch is a valid branch
name using 'git check-ref-format --branch <actual_branch>'
since we are not using full refs.

[YOCTO #8008]

NOTE:
  Only existing LayerBranches will be editable. A new layer
  can be submitted with a different branch for "master", but
  only the "master" LayerBranch will be created.

  Further changes to the update.py script will be needed to
  make creation of new stable branches with an actual_branch
  possible.

Signed-off-by: Tim Orling <tim.orling@konsulko.com>
This commit is contained in:
Tim Orling 2023-12-22 12:49:57 -08:00
parent 203bbdb44f
commit 083c234764
2 changed files with 20 additions and 0 deletions

View File

@ -76,6 +76,7 @@ LayerMaintainerFormSet = inlineformset_factory(LayerBranch, LayerMaintainer, for
class EditLayerForm(StyledModelForm): class EditLayerForm(StyledModelForm):
# Additional form fields # Additional form fields
vcs_subdir = forms.CharField(label='Repository subdirectory', max_length=40, required=False, help_text='Subdirectory within the repository where the layer is located, if not in the root (usually only used if the repository contains more than one layer)') vcs_subdir = forms.CharField(label='Repository subdirectory', max_length=40, required=False, help_text='Subdirectory within the repository where the layer is located, if not in the root (usually only used if the repository contains more than one layer)')
actual_branch = forms.CharField(label='Actual branch', max_length=80, required=False, help_text='Name of the actual branch in the repository matching the core branch (e.g. the development branch is "master" by default)')
deps = forms.ModelMultipleChoiceField(label='Other layers this layer depends upon', queryset=LayerItem.objects.filter(comparison=False), required=False) deps = forms.ModelMultipleChoiceField(label='Other layers this layer depends upon', queryset=LayerItem.objects.filter(comparison=False), required=False)
captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'}) captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'})
@ -98,11 +99,16 @@ class EditLayerForm(StyledModelForm):
field_order.pop(field_order.index('vcs_subdir')) field_order.pop(field_order.index('vcs_subdir'))
name_pos = field_order.index('vcs_url') + 1 name_pos = field_order.index('vcs_url') + 1
field_order.insert(name_pos, 'vcs_subdir') field_order.insert(name_pos, 'vcs_subdir')
# Ensure actual branch appears after repo subdir
field_order.pop(field_order.index('actual_branch'))
name_pos = name_pos + 1
field_order.insert(name_pos, 'actual_branch')
new_fields = OrderedDict() new_fields = OrderedDict()
for field in field_order: for field in field_order:
new_fields[field] = self.fields[field] new_fields[field] = self.fields[field]
self.fields = new_fields self.fields = new_fields
self.fields['vcs_subdir'].initial = layerbranch.vcs_subdir self.fields['vcs_subdir'].initial = layerbranch.vcs_subdir
self.fields['actual_branch'].initial = layerbranch.actual_branch
self.was_saved = False self.was_saved = False
self.allow_base_type = allow_base_type self.allow_base_type = allow_base_type
@ -178,6 +184,15 @@ class EditLayerForm(StyledModelForm):
val(usage) val(usage)
return usage return usage
def clean_actual_branch(self):
import subprocess
actual_branch = self.cleaned_data['actual_branch'].strip()
process = subprocess.Popen(["git", "check-ref-format", "--branch", actual_branch])
exit_status = process.wait()
if exit_status != 0:
raise forms.ValidationError("Actual branch should be a valid git branch short name")
return actual_branch
class EditNoteForm(StyledModelForm): class EditNoteForm(StyledModelForm):
class Meta: class Meta:

View File

@ -162,6 +162,11 @@ def edit_layer_view(request, template_name, branch='master', slug=None):
layerbranch.vcs_subdir = new_subdir layerbranch.vcs_subdir = new_subdir
reset_last_rev = True reset_last_rev = True
layerbranch.save() layerbranch.save()
new_actual_branch = form.cleaned_data['actual_branch']
if layerbranch.actual_branch != new_actual_branch:
layerbranch.actual_branch = new_actual_branch
reset_last_rev = True
layerbranch.save()
maintainerformset.save() maintainerformset.save()
if slug: if slug:
new_deps = form.cleaned_data['deps'] new_deps = form.cleaned_data['deps']