Add outdated flag to UpdateConfig to stop notification spam

This commit is contained in:
rubenwardy 2020-12-15 21:44:29 +00:00
parent c8406b45d4
commit 09a9219fcd
4 changed files with 55 additions and 15 deletions

@ -856,6 +856,10 @@ class PackageRelease(db.Model):
assert self.task_id is None and self.url is not None and self.url != ""
self.approved = True
if self.package.update_config:
self.package.update_config.outdated = False
return True
def checkPerm(self, user, perm):
@ -948,5 +952,8 @@ class PackageUpdateConfig(db.Model):
last_commit = db.Column(db.String(41), nullable=True, default=None)
# Set to true when an outdated notification is sent. Set to false when a release is created
outdated = db.Column(db.Boolean, nullable=False, default=False)
trigger = db.Column(db.Enum(PackageUpdateTrigger), nullable=False, default=PackageUpdateTrigger.COMMIT)
make_release = db.Column(db.Boolean, nullable=False, default=False)

@ -323,9 +323,16 @@ def check_update_config(package_id):
config = package.update_config
ref = None
hash = get_commit_hash(package.repo, ref)
if config.last_commit != hash:
hash = get_commit_hash(package.repo, ref)
if config.last_commit == hash:
return
if not config.last_commit:
config.last_commit = hash
db.session.commit()
return
if config.make_release:
rel = PackageRelease()
rel.package = package
@ -337,7 +344,9 @@ def check_update_config(package_id):
makeVCSRelease.apply_async((rel.id, ref), task_id=rel.task_id)
else:
elif not config.outdated:
config.outdated = True
post_system_thread(package, "New commit detected, package outdated?",
"Commit {} was detected on the Git repository.\n\n[Change update configuration]({})" \
.format(hash[0:5], package.getUpdateConfigURL()))

@ -0,0 +1,24 @@
"""empty message
Revision ID: 4585ce5147b8
Revises: 105d4c740ad6
Create Date: 2020-12-15 21:35:18.982716
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '4585ce5147b8'
down_revision = '105d4c740ad6'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('package_update_config', sa.Column('outdated', sa.Boolean(), nullable=False, server_default="false"))
def downgrade():
op.drop_column('package_update_config', 'outdated')

@ -2,7 +2,7 @@
# Create a database migration, and copy it back to the host.
docker exec contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db revision"
docker exec contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate"
docker exec -u root contentdb_app_1 sh -c "cp /home/cdb/migrations/versions/* /source/migrations/versions/"
USER=$(whoami)