Add ability to bulk create releases for outdated packages

This commit is contained in:
rubenwardy 2021-01-30 22:58:55 +00:00
parent a0cd155730
commit db09b8eb84
3 changed files with 62 additions and 6 deletions

@ -14,14 +14,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from celery import uuid
from flask import *
from flask_login import current_user, login_required
from sqlalchemy import or_
from sqlalchemy.sql.operators import is_
from app.models import *
from app.querybuilder import QueryBuilder
from app.utils import get_int_or_abort
from app.utils import get_int_or_abort, addNotification, addAuditLog
from app.tasks.importtasks import makeVCSRelease
bp = Blueprint("todo", __name__)
@ -176,6 +177,52 @@ def view_user(username=None):
needs_tags=needs_tags, topics_to_add=topics_to_add)
@bp.route("/users/<username>/update-configs/apply-all/", methods=["POST"])
@login_required
def apply_all_updates(username):
user: User = User.query.filter_by(username=username).first()
if not user:
abort(404)
if current_user != user and not current_user.rank.atLeast(UserRank.EDITOR):
abort(403)
outdated_packages = user.maintained_packages \
.filter(Package.state != PackageState.DELETED,
Package.update_config.has(PackageUpdateConfig.outdated_at.isnot(None))) \
.order_by(db.asc(Package.title)).all()
for package in outdated_packages:
if not package.checkPerm(current_user, Permission.MAKE_RELEASE):
continue
if package.releases.filter(or_(PackageRelease.task_id.isnot(None),
PackageRelease.commit_hash==package.update_config.last_commit)).count():
continue
title = package.update_config.get_title()
ref = package.update_config.get_ref()
rel = PackageRelease()
rel.package = package
rel.title = title
rel.url = ""
rel.task_id = uuid()
db.session.add(rel)
db.session.commit()
makeVCSRelease.apply_async((rel.id, ref),
task_id=rel.task_id)
msg = "Created release {} (Applied all Git Update Config)".format(rel.title)
addNotification(package.maintainers, current_user, NotificationType.PACKAGE_EDIT, msg,
rel.getEditURL(), package)
addAuditLog(AuditSeverity.NORMAL, current_user, msg, package.getDetailsURL(), package)
db.session.commit()
return redirect(url_for("todo.view_user", username=username))
@bp.route("/todo/outdated/")
@login_required
def outdated():

@ -995,7 +995,11 @@ class PackageUpdateConfig(db.Model):
else:
return "New tag {} found on the Git repo.".format(self.last_tag)
def get_title(self):
return self.last_tag or self.outdated_at.strftime("%Y-%m-%d")
def get_ref(self):
return self.last_tag or self.last_commit
def get_create_release_url(self):
title = self.last_tag or self.outdated_at.strftime("%Y-%m-%d")
ref = self.last_tag or self.last_commit
return self.package.getCreateReleaseURL(title=title, ref=ref)
return self.package.getCreateReleaseURL(title=self.get_title(), ref=self.get_ref())

@ -31,9 +31,14 @@
{% endfor %}
</div>
<a class="btn btn-secondary float-right" href="/help/update_config/">Help</a>
<a class="btn btn-secondary float-right mr-2" href="{{ url_for('packages.bulk_update_config', username=user.username) }}">See all Update Settings</a>
{% if outdated_packages %}
<form class="float-right mr-2" method="post" action="{{ url_for('todo.apply_all_updates', username=user.username) }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input class="btn btn-primary" type="submit" value="{{ _("Create All Releases") }}" />
</form>
{% endif %}
<h2>{{ _("Potentially Outdated Packages") }}</h2>
<p class="alert alert-info">
{{ _("New: Git Update Detection has been set up on all packages to send notifications.") }}<br />