mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 14:37:36 +01:00
Add ability to bulk set update config
This commit is contained in:
parent
b7814d9541
commit
a0cd155730
@ -265,6 +265,29 @@ class PackageUpdateConfigFrom(FlaskForm):
|
||||
disable = SubmitField("Disable Automation")
|
||||
|
||||
|
||||
def set_update_config(package, form):
|
||||
if package.update_config is None:
|
||||
package.update_config = PackageUpdateConfig()
|
||||
db.session.add(package.update_config)
|
||||
|
||||
form.populate_obj(package.update_config)
|
||||
package.update_config.ref = nonEmptyOrNone(form.ref.data)
|
||||
package.update_config.make_release = form.action.data == "make_release"
|
||||
|
||||
if package.update_config.last_commit is None:
|
||||
last_release = package.releases.first()
|
||||
if last_release and last_release.commit_hash:
|
||||
package.update_config.last_commit = last_release.commit_hash
|
||||
|
||||
package.update_config.outdated_at = None
|
||||
package.update_config.auto_created = False
|
||||
|
||||
db.session.commit()
|
||||
|
||||
if package.update_config.last_commit is None:
|
||||
check_update_config.delay(package.id)
|
||||
|
||||
|
||||
@bp.route("/packages/<author>/<name>/update-config/", methods=["GET", "POST"])
|
||||
@login_required
|
||||
@is_package_page
|
||||
@ -291,26 +314,7 @@ def update_config(package):
|
||||
db.session.delete(package.update_config)
|
||||
db.session.commit()
|
||||
else:
|
||||
if package.update_config is None:
|
||||
package.update_config = PackageUpdateConfig()
|
||||
db.session.add(package.update_config)
|
||||
|
||||
form.populate_obj(package.update_config)
|
||||
package.update_config.ref = nonEmptyOrNone(form.ref.data)
|
||||
package.update_config.make_release = form.action.data == "make_release"
|
||||
|
||||
if package.update_config.last_commit is None:
|
||||
last_release = package.releases.first()
|
||||
if last_release and last_release.commit_hash:
|
||||
package.update_config.last_commit = last_release.commit_hash
|
||||
|
||||
package.update_config.outdated_at = None
|
||||
package.update_config.auto_created = False
|
||||
|
||||
db.session.commit()
|
||||
|
||||
if package.update_config.last_commit is None:
|
||||
check_update_config.delay(package.id)
|
||||
set_update_config(package, form)
|
||||
|
||||
if not form.disable.data and package.releases.count() == 0:
|
||||
flash("Now, please create an initial release", "success")
|
||||
@ -334,9 +338,13 @@ def setup_releases(package):
|
||||
return render_template("packages/release_wizard.html", package=package)
|
||||
|
||||
|
||||
@bp.route("/users/<username>/update-configs/")
|
||||
@bp.route("/user/update-configs/")
|
||||
@bp.route("/users/<username>/update-configs/", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def bulk_update_config(username):
|
||||
def bulk_update_config(username=None):
|
||||
if username is None:
|
||||
return redirect(url_for("packages.bulk_update_config", username=current_user.username))
|
||||
|
||||
user: User = User.query.filter_by(username=username).first()
|
||||
if not user:
|
||||
abort(404)
|
||||
@ -344,9 +352,16 @@ def bulk_update_config(username):
|
||||
if current_user != user and not current_user.rank.atLeast(UserRank.EDITOR):
|
||||
abort(403)
|
||||
|
||||
confs = user.maintained_packages \
|
||||
form = PackageUpdateConfigFrom()
|
||||
if form.validate_on_submit():
|
||||
for package in user.packages.filter(Package.state != PackageState.DELETED, Package.repo.isnot(None)).all():
|
||||
set_update_config(package, form)
|
||||
|
||||
return redirect(url_for("packages.bulk_update_config", username=username))
|
||||
|
||||
confs = user.packages \
|
||||
.filter(Package.state != PackageState.DELETED,
|
||||
Package.update_config.has()) \
|
||||
.order_by(db.asc(Package.title)).all()
|
||||
|
||||
return render_template("packages/bulk_update_conf.html", user=user, confs=confs)
|
||||
return render_template("packages/bulk_update_conf.html", user=user, confs=confs, form=form)
|
||||
|
@ -7,7 +7,32 @@
|
||||
{% block content %}
|
||||
<a class="btn btn-secondary float-right" href="/help/update_config/">Help</a>
|
||||
<h1 class="mb-5">{{ self.title() }}</h1>
|
||||
<h2>{{ _("Packages with Update Settings") }}</h2>
|
||||
|
||||
{% from "macros/todo.html" import render_outdated_packages %}
|
||||
{{ render_outdated_packages(confs, current_user, show_config=True) }}
|
||||
|
||||
{% if form %}
|
||||
<h2 class="mt-5">{{ _("Bulk Set Update Settings") }}</h2>
|
||||
<p class="alert alert-danger">
|
||||
{{ _("This will set the update settings for all packages with a Git repo.") }}
|
||||
</p>
|
||||
|
||||
{% from "macros/forms.html" import render_field, render_submit_field, render_radio_field %}
|
||||
<form method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{{ render_radio_field(form.trigger) }}
|
||||
|
||||
{{ render_field(form.ref, placeholder=_("Leave blank to use default branch"),
|
||||
pattern="[A-Za-z0-9/._-]+", class_="mt-3",
|
||||
hint=_("Currently, the branch name field is only used by the New Commit trigger.")) }}
|
||||
|
||||
{{ render_radio_field(form.action) }}
|
||||
|
||||
<p class="mt-4">
|
||||
{{ render_submit_field(form.submit) }}
|
||||
</p>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user