Merge pull request !2787 from rhodecode-enterprise-ce feature/setting-to-pre-populate-branch-in-pr
Changes from branch: Feature/setting to pre populate branch in pr
This commit is contained in:
commit
2e4a6ec5d7
9 changed files with 101 additions and 8 deletions
9
Makefile
9
Makefile
|
|
@ -233,4 +233,11 @@ ruff-format:
|
|||
else \
|
||||
echo "No Python files changed."; \
|
||||
fi
|
||||
@rm -f .changed_files
|
||||
@rm -f .changed_files
|
||||
|
||||
.PHONY: upgrade-db
|
||||
# upgrade-db: Apply database migrations using rc-upgrade-db
|
||||
upgrade-db:
|
||||
/usr/local/bin/rhodecode_bin/bin/rc-upgrade-db \
|
||||
/home/rhodecode/rhodecode-enterprise-ce/.dev/dev.ini \
|
||||
--force-yes
|
||||
|
|
@ -100,7 +100,7 @@ PYRAMID_SETTINGS = {}
|
|||
EXTENSIONS = {}
|
||||
|
||||
__version__ = ".".join((str(each) for each in VERSION[:3]))
|
||||
__dbversion__ = 117 # defines current db version for migrations
|
||||
__dbversion__ = 118 # defines current db version for migrations
|
||||
__license__ = "AGPLv3, and Commercial License"
|
||||
__author__ = "RhodeCode GmbH"
|
||||
__url__ = "https://code.rhodecode.com"
|
||||
|
|
|
|||
|
|
@ -907,6 +907,7 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
|
|||
branch=branch_ref,
|
||||
bookmark=bookmark_ref,
|
||||
translator=self.request.translate,
|
||||
prepopulate_branch=True, # Always pre-populate for source repo
|
||||
)
|
||||
except CommitDoesNotExistError as e:
|
||||
log.exception(e)
|
||||
|
|
@ -921,7 +922,14 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
|
|||
# change default if we have a parent repo
|
||||
default_target_repo = source_repo.parent
|
||||
|
||||
target_repo_data = PullRequestModel().generate_repo_data(default_target_repo, translator=self.request.translate)
|
||||
# Get the target branch pre-population setting
|
||||
prepopulate_target_branch = self._get_repo_setting(
|
||||
default_target_repo, "rhodecode_pr_target_branch_prepopulate", True
|
||||
)
|
||||
|
||||
target_repo_data = PullRequestModel().generate_repo_data(
|
||||
default_target_repo, translator=self.request.translate, prepopulate_branch=prepopulate_target_branch
|
||||
)
|
||||
|
||||
selected_source_ref = source_repo_data["refs"]["selected_ref"]
|
||||
title_source_ref = ""
|
||||
|
|
@ -936,6 +944,7 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
|
|||
"source_refs_json": ext_json.str_json(source_repo_data),
|
||||
"target_repo_name": default_target_repo.repo_name,
|
||||
"target_refs_json": ext_json.str_json(target_repo_data),
|
||||
"pr_target_branch_prepopulate": prepopulate_target_branch,
|
||||
}
|
||||
c.default_source_ref = selected_source_ref
|
||||
|
||||
|
|
@ -958,7 +967,12 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
|
|||
if not target_perm:
|
||||
raise HTTPNotFound()
|
||||
|
||||
return PullRequestModel().generate_repo_data(repo, translator=self.request.translate)
|
||||
# Get the target branch pre-population setting for the target repo
|
||||
prepopulate_target_branch = self._get_repo_setting(repo, "pr_target_branch_prepopulate", True)
|
||||
|
||||
return PullRequestModel().generate_repo_data(
|
||||
repo, translator=self.request.translate, prepopulate_branch=prepopulate_target_branch
|
||||
)
|
||||
|
||||
@LoginRequired()
|
||||
@NotAnonymous()
|
||||
|
|
|
|||
50
rhodecode/lib/dbmigrate/versions/118_version_5_7_0.py
Normal file
50
rhodecode/lib/dbmigrate/versions/118_version_5_7_0.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import logging
|
||||
from sqlalchemy import *
|
||||
|
||||
from rhodecode.lib.dbmigrate.versions import _reset_base
|
||||
from rhodecode.model import meta, init_model_encryption
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
"""
|
||||
Upgrade operations go here.
|
||||
Don't create your own engine; bind migrate_engine to your metadata
|
||||
"""
|
||||
_reset_base(migrate_engine)
|
||||
|
||||
from rhodecode.lib.dbmigrate.schema import db_4_20_0_1 as db
|
||||
|
||||
init_model_encryption(db)
|
||||
|
||||
# Add default PR target branch pre-population setting
|
||||
fixups(db, meta.Session)
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
pass
|
||||
|
||||
|
||||
def fixups(models, _SESSION):
|
||||
def get_by_name(cls, key):
|
||||
return cls.query().filter(cls.app_settings_name == key).scalar()
|
||||
|
||||
def create_or_update(cls, key, val="True", type_="bool"):
|
||||
res = get_by_name(cls, key)
|
||||
if not res:
|
||||
res = cls(key, val, type_)
|
||||
print(f"Creating new setting: {key} = {val}")
|
||||
else:
|
||||
print(f"Setting {key} already exists, skipping")
|
||||
return res
|
||||
|
||||
# Add global default setting
|
||||
setting_name = "pr_target_branch_prepopulate"
|
||||
setting_value = "True" # Default to True to maintain existing behavior
|
||||
setting_type = "bool"
|
||||
|
||||
sett = create_or_update(models.RhodeCodeSetting, setting_name, setting_value, setting_type)
|
||||
_SESSION().add(sett)
|
||||
_SESSION().commit()
|
||||
|
|
@ -453,6 +453,9 @@ class _BaseVcsSettingsForm(formencode.Schema):
|
|||
# cache
|
||||
rhodecode_diff_cache = v.StringBoolean(if_missing=False)
|
||||
|
||||
# Pull Request settings
|
||||
rhodecode_pr_target_branch_prepopulate = v.StringBoolean(if_missing=False)
|
||||
|
||||
|
||||
def ApplicationUiSettingsForm(localizer):
|
||||
_ = localizer
|
||||
|
|
|
|||
|
|
@ -2053,13 +2053,19 @@ class PullRequestModel(BaseModel):
|
|||
workspace_id = "pr-%s" % pull_request.pull_request_id
|
||||
return workspace_id
|
||||
|
||||
def generate_repo_data(self, repo, commit_id=None, branch=None, bookmark=None, translator=None):
|
||||
def generate_repo_data(
|
||||
self, repo, commit_id=None, branch=None, bookmark=None, translator=None, prepopulate_branch=True
|
||||
):
|
||||
from rhodecode.model.repo import RepoModel
|
||||
|
||||
all_refs, selected_ref = self._get_repo_pullrequest_sources(
|
||||
repo.scm_instance(), commit_id=commit_id, branch=branch, bookmark=bookmark, translator=translator
|
||||
)
|
||||
|
||||
# If branch pre-population is disabled, don't auto-select any branch
|
||||
if not prepopulate_branch:
|
||||
selected_ref = None
|
||||
|
||||
refs_select2 = []
|
||||
for element in all_refs:
|
||||
children = [{"id": x[0], "text": x[1]} for x in element[0]]
|
||||
|
|
|
|||
|
|
@ -457,6 +457,7 @@ class VcsSettingsModel(object):
|
|||
"git_close_branch_before_merging",
|
||||
"git_merge_strategy_selector",
|
||||
"diff_cache",
|
||||
"pr_target_branch_prepopulate",
|
||||
)
|
||||
|
||||
HOOKS_SETTINGS = (
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@
|
|||
</div>
|
||||
<div class="label">
|
||||
<span class="help-block">${_('This feature is available in RhodeCode EE edition only. Contact {sales_email} to obtain a trial license.').format(sales_email='<a href="mailto:sales@rhodecode.com">sales@rhodecode.com</a>')|n}</span>
|
||||
<div>
|
||||
</div>
|
||||
%else:
|
||||
<div class="checkbox">
|
||||
${h.checkbox('rhodecode_auto_merge_enabled' + suffix, 'True', **kwargs)}
|
||||
|
|
@ -234,6 +234,14 @@
|
|||
<div class="label">
|
||||
<span class="help-block">${_('During the update of a pull request, the position of inline comments will be updated and outdated inline comments will be hidden.')}</span>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
${h.checkbox('rhodecode_pr_target_branch_prepopulate' + suffix, 'True', **kwargs)}
|
||||
<label for="rhodecode_pr_target_branch_prepopulate${suffix}">${_('Pre-populate target branch when creating pull requests')}</label>
|
||||
</div>
|
||||
<div class="label">
|
||||
<span class="help-block">${_('When enabled, the target branch field will be automatically populated when creating pull requests. Disable this to prevent expensive diff calculations on repositories with many divergent branches.')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
% endif
|
||||
|
|
@ -299,6 +307,8 @@
|
|||
## <div class="label">
|
||||
## <span class="help-block">${_('Use rebase instead of creating a merge commit when merging via web interface.')}</span>
|
||||
## </div>
|
||||
## Hidden field for commented-out setting to prevent validation errors
|
||||
${h.hidden('rhodecode_git_use_rebase_for_merging' + suffix, 'False')}
|
||||
|
||||
<div class="checkbox">
|
||||
${h.checkbox('rhodecode_git_close_branch_before_merging' + suffix, 'True', **kwargs)}
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@
|
|||
var defaultSourceRepoData = ${c.default_repo_data['source_refs_json']|n};
|
||||
var defaultTargetRepo = '${c.default_repo_data['target_repo_name']}';
|
||||
var defaultTargetRepoData = ${c.default_repo_data['target_refs_json']|n};
|
||||
var prTargetBranchPrepopulate = ${'true' if c.default_repo_data['pr_target_branch_prepopulate'] else 'false'};
|
||||
|
||||
var $pullRequestForm = $('#pull_request_form');
|
||||
var $pullRequestSubmit = $('#pr_submit', $pullRequestForm);
|
||||
|
|
@ -530,8 +531,9 @@
|
|||
$('#switch_base').html("<a class=\"tooltip\" title=\"{0}\" href=\"{1}\">Switch sides</a>".format(title, prLink))
|
||||
|
||||
// generate dynamic select2 for refs.
|
||||
initTargetRefs(repoData['refs']['select2_refs'],
|
||||
repoData['refs']['selected_ref']);
|
||||
// Only pre-populate target branch if the setting allows it
|
||||
var selectedRef = prTargetBranchPrepopulate ? repoData['refs']['selected_ref'] : null;
|
||||
initTargetRefs(repoData['refs']['select2_refs'], selectedRef);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue