From 09a9219fcd0d464d3d6b9e4b758ca8fb4ea2f6f7 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 15 Dec 2020 21:44:29 +0000 Subject: [PATCH] Add outdated flag to UpdateConfig to stop notification spam --- app/models/packages.py | 7 ++++++ app/tasks/importtasks.py | 37 +++++++++++++++++----------- migrations/versions/4585ce5147b8_.py | 24 ++++++++++++++++++ utils/create_migration.sh | 2 +- 4 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 migrations/versions/4585ce5147b8_.py diff --git a/app/models/packages.py b/app/models/packages.py index 0e48a5f8..260f9e2b 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -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) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index a69ba1c6..4ba26f58 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -323,24 +323,33 @@ def check_update_config(package_id): config = package.update_config ref = None + hash = get_commit_hash(package.repo, ref) + if config.last_commit == hash: + return - if config.last_commit != hash: - if config.make_release: - rel = PackageRelease() - rel.package = package - rel.title = hash[0:5] - rel.url = "" - rel.task_id = uuid() - db.session.add(rel) - db.session.commit() + if not config.last_commit: + config.last_commit = hash + db.session.commit() + return - makeVCSRelease.apply_async((rel.id, ref), task_id=rel.task_id) + if config.make_release: + rel = PackageRelease() + rel.package = package + rel.title = hash[0:5] + rel.url = "" + rel.task_id = uuid() + db.session.add(rel) + db.session.commit() - else: - 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())) + makeVCSRelease.apply_async((rel.id, ref), task_id=rel.task_id) + + 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())) config.last_commit = hash db.session.commit() diff --git a/migrations/versions/4585ce5147b8_.py b/migrations/versions/4585ce5147b8_.py new file mode 100644 index 00000000..16db8c5d --- /dev/null +++ b/migrations/versions/4585ce5147b8_.py @@ -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') diff --git a/utils/create_migration.sh b/utils/create_migration.sh index 59aaea01..4c739371 100755 --- a/utils/create_migration.sh +++ b/utils/create_migration.sh @@ -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)