From 47cc155b06c950fe49973755c99b5af0d8360970 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:16:31 +0100 Subject: [PATCH 01/28] upgrade pyttman to 1.3.2 --- requirements.txt | Bin 1248 -> 1244 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index a823ead938842444f45d5c9cb38efc3697a2fcea..a83ee0d8513cd0868d7ed5a44246aacf3e5dcdce 100644 GIT binary patch delta 14 VcmaFBd53eu6=p`G%{Q6Z838U31t0(b delta 18 Zcmcb^`G9l76=qfg20aGD%~zS(838`Z1$_Vj From f2871247f8a3502e3374ecc3fcb174fc20045b75 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:17:27 +0100 Subject: [PATCH 02/28] Migration: added migration file to change datatype for name of recipe --- ...hange_list_field_to_string_field_recipe.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py diff --git a/jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py b/jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py new file mode 100644 index 0000000..24a470a --- /dev/null +++ b/jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py @@ -0,0 +1,19 @@ +from jarvis.abilities.recipes.models import Recipe +from jarvis.migrations import expose + + +def upgrade(): + for recipe in Recipe.objects.all(): + if isinstance(recipe.name, list): + recipe.name = " ".join(recipe.name) + recipe.save() + + +def downgrade(): + for recipe in Recipe.objects.all(): + if isinstance(recipe.name, str): + recipe.name = recipe.name.split() + recipe.save() + + +expose() From 6adfaf44005ca1b3cdc894bc872541f142b69d53 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:17:54 +0100 Subject: [PATCH 03/28] New file for automated migrations, work in progress --- jarvis/migrations/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 jarvis/migrations/__init__.py diff --git a/jarvis/migrations/__init__.py b/jarvis/migrations/__init__.py new file mode 100644 index 0000000..beb73e3 --- /dev/null +++ b/jarvis/migrations/__init__.py @@ -0,0 +1,17 @@ +import sys + +upgrade = downgrade = lambda: None + + +def expose(): + # Parse args and run the upgrade or downgrade function + args = set(sys.argv[1:]) + if not {"upgrade", "downgrade"} & args: + print("Please provide an argument: 'upgrade' or 'downgrade'") + sys.exit(1) + elif args & {"upgrade"}: + print("Running upgrade...") + upgrade() + elif args & {"downgrade"}: + print("Running downgrade...") + downgrade() From 16615de4ce8703ff4d793c75b6755118bc0a91c5 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:18:49 +0100 Subject: [PATCH 04/28] Improved search for recipes by name --- jarvis/abilities/recipes/intents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis/abilities/recipes/intents.py b/jarvis/abilities/recipes/intents.py index 3c864d4..4d54b98 100644 --- a/jarvis/abilities/recipes/intents.py +++ b/jarvis/abilities/recipes/intents.py @@ -46,7 +46,7 @@ def respond(self, message: Message) -> Reply | ReplyStream: query = Recipe.objects.filter(url__contains=vendor) if keyword: keyword = keyword.lower() - query = query.filter(name__in=keyword.split()) + query = query.filter(name__icontains=keyword) if not (matching_recipes := query.all()): return Reply("Jag hittade inga recept med det namnet.") stream = ReplyStream() From 5405963d9ad7af05ac24871d7f919df0ecc1e01e Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:19:03 +0100 Subject: [PATCH 05/28] Visualize recipes better, call the 'pretty' method --- jarvis/abilities/recipes/intents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis/abilities/recipes/intents.py b/jarvis/abilities/recipes/intents.py index 4d54b98..a3c5662 100644 --- a/jarvis/abilities/recipes/intents.py +++ b/jarvis/abilities/recipes/intents.py @@ -51,5 +51,5 @@ def respond(self, message: Message) -> Reply | ReplyStream: return Reply("Jag hittade inga recept med det namnet.") stream = ReplyStream() for recipe in matching_recipes: - stream.put(Reply(recipe.url)) + stream.put(Reply(recipe)) return stream From 8babdd033512f894cf1ee7219c15c48c509b7b0a Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:19:18 +0100 Subject: [PATCH 06/28] improved search for recipes --- jarvis/abilities/recipes/intents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis/abilities/recipes/intents.py b/jarvis/abilities/recipes/intents.py index a3c5662..6cb65fb 100644 --- a/jarvis/abilities/recipes/intents.py +++ b/jarvis/abilities/recipes/intents.py @@ -34,7 +34,7 @@ class GetRecipes(Intent): lead = ("sök", "visa", "hitta") trail = ("recept",) - name = StringEntityField(prefixes=("med",), span=10) + name = StringEntityField(prefixes=("med", "på"), span=10) from_vendor = StringEntityField(prefixes=("från",)) def respond(self, message: Message) -> Reply | ReplyStream: From 3b457b4756200729c7697bd1ae8b6ba1485219d9 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:25:35 +0100 Subject: [PATCH 07/28] Added 'Comment' to Recipe model --- jarvis/abilities/recipes/models.py | 1 + .../00000002_add_comment_stringfield.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 jarvis/migrations/00000002_add_comment_stringfield.py diff --git a/jarvis/abilities/recipes/models.py b/jarvis/abilities/recipes/models.py index 6412d5d..068e442 100644 --- a/jarvis/abilities/recipes/models.py +++ b/jarvis/abilities/recipes/models.py @@ -15,6 +15,7 @@ class Recipe(me.Document): user = me.ReferenceField("User", required=False) url = me.StringField(required=True) name = me.ListField(required=True) + comment = me.StringField(required=False) @property def pretty(self): diff --git a/jarvis/migrations/00000002_add_comment_stringfield.py b/jarvis/migrations/00000002_add_comment_stringfield.py new file mode 100644 index 0000000..9ea9a9c --- /dev/null +++ b/jarvis/migrations/00000002_add_comment_stringfield.py @@ -0,0 +1,22 @@ +from mongoengine import StringField + +from jarvis.abilities.recipes.models import Recipe +from jarvis.migrations import expose + + +def upgrade(): + Recipe.comment = StringField(required=False) + for recipe in Recipe.objects.all(): + if hasattr(recipe, "comment"): + continue + recipe.comment = "" + + +def downgrade(): + for recipe in Recipe.objects.all(): + if isinstance(recipe.name, str): + recipe.name = recipe.name.split() + recipe.save() + + +expose() From 5b02091fdc72f63678d0d0c4dc250f2560c34a8a Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:25:51 +0100 Subject: [PATCH 08/28] Changed list field to stringfield for name in recipes --- jarvis/abilities/recipes/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis/abilities/recipes/models.py b/jarvis/abilities/recipes/models.py index 068e442..2bc8e9f 100644 --- a/jarvis/abilities/recipes/models.py +++ b/jarvis/abilities/recipes/models.py @@ -14,7 +14,7 @@ class Recipe(me.Document): created = me.DateTimeField(defalt=lambda: datetime.now()) user = me.ReferenceField("User", required=False) url = me.StringField(required=True) - name = me.ListField(required=True) + name = me.StringField(required=True) comment = me.StringField(required=False) @property From 43e230bcc05cdb336cc514a1b1ef99bc4844faa0 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:26:09 +0100 Subject: [PATCH 09/28] updated format for pretty output of recipe --- jarvis/abilities/recipes/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jarvis/abilities/recipes/models.py b/jarvis/abilities/recipes/models.py index 2bc8e9f..1472309 100644 --- a/jarvis/abilities/recipes/models.py +++ b/jarvis/abilities/recipes/models.py @@ -19,10 +19,11 @@ class Recipe(me.Document): @property def pretty(self): - name = " ".join(self.name) - output = f"**{name}**\n{self.url}" + output = f"**{self.name}**\n{self.url}" if self.user is not None: output += f"\nSkapad av {self.user.username}" + if self.comment: + output += f"\nKommentar:\n{self.comment}" return output def __str__(self): From 663b71b48d11427323e9b94761be81910d082da8 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 3 Jan 2024 19:27:32 +0100 Subject: [PATCH 10/28] ignore logs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b97131e..c00090d 100644 --- a/.gitignore +++ b/.gitignore @@ -129,3 +129,4 @@ dmypy.json .pyre/ .idea/ +/jarvis/logs/ From adae5f2481b7af275702c47d9ee517d675630566 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:14:11 +0100 Subject: [PATCH 11/28] upgraded to python 3.11 in prod --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1c1f67f..da780e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ #Create a ubuntu base image with python 3 installed. -FROM python:3.10 +FROM python:3.11 #Set the working directory WORKDIR / From a36d82dca867a4e23305934c6027dce5d55de437 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:14:22 +0100 Subject: [PATCH 12/28] run migrations when deploying --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index da780e8..c8341fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,5 +15,6 @@ RUN pip3 install -r requirements.txt #Expose the required port for MongoDB Atlas EXPOSE 42487 -#Run Jarvis with Pyttman CLI +# Run migrations and start Jarvis +CMD pyttman runfile jarvis jarvis/migrations/migrate.py upgrade CMD pyttman runclient jarvis \ No newline at end of file From e19cbda1aad10db703a8f3da1c98b41e132d1ba9 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:32:48 +0100 Subject: [PATCH 13/28] Build a custom migration engine, with 'upgrade', 'downgrade' and increment arguments ( +1, -13 , etc) for migrating the databse when making edits to schemas in the database --- __version__.py | 0 ...hange_list_field_to_string_field_recipe.py | 6 +- jarvis/migrations/__init__.py | 17 ---- jarvis/migrations/migrate.py | 88 +++++++++++++++++++ 4 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 __version__.py delete mode 100644 jarvis/migrations/__init__.py create mode 100644 jarvis/migrations/migrate.py diff --git a/__version__.py b/__version__.py new file mode 100644 index 0000000..e69de29 diff --git a/jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py b/jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py index 24a470a..a01407f 100644 --- a/jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py +++ b/jarvis/migrations/00000001_change_list_field_to_string_field_recipe.py @@ -1,5 +1,6 @@ from jarvis.abilities.recipes.models import Recipe -from jarvis.migrations import expose + +__doc__ = "Change the name field in Recipe to Text field instead of List field" def upgrade(): @@ -14,6 +15,3 @@ def downgrade(): if isinstance(recipe.name, str): recipe.name = recipe.name.split() recipe.save() - - -expose() diff --git a/jarvis/migrations/__init__.py b/jarvis/migrations/__init__.py deleted file mode 100644 index beb73e3..0000000 --- a/jarvis/migrations/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -import sys - -upgrade = downgrade = lambda: None - - -def expose(): - # Parse args and run the upgrade or downgrade function - args = set(sys.argv[1:]) - if not {"upgrade", "downgrade"} & args: - print("Please provide an argument: 'upgrade' or 'downgrade'") - sys.exit(1) - elif args & {"upgrade"}: - print("Running upgrade...") - upgrade() - elif args & {"downgrade"}: - print("Running downgrade...") - downgrade() diff --git a/jarvis/migrations/migrate.py b/jarvis/migrations/migrate.py new file mode 100644 index 0000000..149e9b1 --- /dev/null +++ b/jarvis/migrations/migrate.py @@ -0,0 +1,88 @@ +import inspect +import re +import sys +from importlib import import_module +from pathlib import Path + +from pyttman import app +from jarvis.models import MigrationVersion + + +if __name__ == "__main__": + # Set the path base dir to the current working directory + # so that the migrations module can be imported. + + migrations_dir = Path(app.settings.APP_BASE_DIR) / "migrations" + if not migrations_dir.exists(): + raise FileNotFoundError(f"Could not find migrations directory: " + f"{migrations_dir.as_posix()}") + + sys.path.append(migrations_dir.as_posix()) + + args = set(sys.argv[1:]) + if "current" in args: + # fill with zeros to 8 digits + print(f"{MigrationVersion.objects.first().version:08d}") + exit(0) + + steps_limit = sys.argv[-1] + steps_limit = re.sub("[+-]", "", steps_limit) + if steps_limit.isdigit(): + steps_limit = abs(int(steps_limit)) + else: + steps_limit = None + + if (version_cursor := MigrationVersion.objects.first()) is None: + version_cursor = MigrationVersion.objects.create() + + current_version = file_version = version_cursor.version + upgrade = "upgrade" in args + downgrade = "downgrade" in args + performed_migrations = 0 + + if upgrade: + migration_files = migrations_dir.glob("*.py") + elif downgrade: + migration_files = reversed(list(migrations_dir.glob("*.py"))) + else: + print("Please specify either 'upgrade' or 'downgrade' as an argument.") + exit(0) + + print("Running migrations...") + + for migration_file in migration_files: + if migration_file.name.startswith("00000000"): + continue + elif migration_file.name == "migrate.py": + continue + + try: + file_version_str = migration_file.name.split("_")[0] + file_version = int(file_version_str) + except ValueError: + raise ValueError(f"Could not parse version from migration file: " + f"{migration_file.as_posix()}") + + if upgrade and file_version > current_version: + method = "upgrade" + elif downgrade and file_version < current_version: + method = "downgrade" + else: + continue + + migration_module = import_module(migration_file.stem) + func = getattr(migration_module, method) + print(f" >> Running {method} in migration {file_version_str}: " + f"'{inspect.getdoc(migration_module)}'") + func() + performed_migrations += 1 + version_cursor.version = file_version + version_cursor.save() + + if steps_limit is not None and performed_migrations >= steps_limit: + break + + if performed_migrations == 0: + print("\nNo migrations to perform.") + else: + print(f"\nPerformed {performed_migrations} migrations.") From 748f5afe930aec1abf1077a35c0fd5639ac42aea Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:33:04 +0100 Subject: [PATCH 14/28] use new version of checkout in github actions --- .github/workflows/heroku_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/heroku_ci.yml b/.github/workflows/heroku_ci.yml index 799b4e9..212583c 100644 --- a/.github/workflows/heroku_ci.yml +++ b/.github/workflows/heroku_ci.yml @@ -13,7 +13,7 @@ jobs: steps: # Check-out your repository. - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 ### ⬇ IMPORTANT PART ⬇ ### From 4396f6e0877e0be76fa882ec1997a75c90f68c3d Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:33:14 +0100 Subject: [PATCH 15/28] New model for versioning migrations --- jarvis/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jarvis/models.py b/jarvis/models.py index df81ef8..c10441e 100644 --- a/jarvis/models.py +++ b/jarvis/models.py @@ -5,6 +5,14 @@ from pyttman.core.containers import Message +class MigrationVersion(me.Document): + """ + This model is used to keep track of the current + migration version of the database. + """ + version = me.IntField(required=True, default=0) + + class UserQuerySet(QuerySet): """ Custom metaclass for User queries From 5f37cac75d6e8a340ce5628a86d14cecefdbf731 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:35:06 +0100 Subject: [PATCH 16/28] first evaluate if migrations version table exists before trying to access it --- jarvis/migrations/migrate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jarvis/migrations/migrate.py b/jarvis/migrations/migrate.py index 149e9b1..fcbee05 100644 --- a/jarvis/migrations/migrate.py +++ b/jarvis/migrations/migrate.py @@ -12,6 +12,9 @@ # Set the path base dir to the current working directory # so that the migrations module can be imported. + if (version_cursor := MigrationVersion.objects.first()) is None: + version_cursor = MigrationVersion.objects.create() + migrations_dir = Path(app.settings.APP_BASE_DIR) / "migrations" if not migrations_dir.exists(): raise FileNotFoundError(f"Could not find migrations directory: " @@ -32,8 +35,6 @@ else: steps_limit = None - if (version_cursor := MigrationVersion.objects.first()) is None: - version_cursor = MigrationVersion.objects.create() current_version = file_version = version_cursor.version upgrade = "upgrade" in args From 606bb53db6fa3afd38e9de0119224ba4f6505fec Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:35:19 +0100 Subject: [PATCH 17/28] added 'comment' to debt --- jarvis/abilities/finance/ability.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jarvis/abilities/finance/ability.py b/jarvis/abilities/finance/ability.py index eaf353d..5eaa698 100644 --- a/jarvis/abilities/finance/ability.py +++ b/jarvis/abilities/finance/ability.py @@ -154,6 +154,7 @@ def register_debt(cls, message: Message) -> str: author_is_borrower = message.entities["author_is_borrower"] author_is_lender = message.entities["author_is_lender"] amount = message.entities["amount"] + comment = message.entities["comment"] if author_is_lender: # author_is_lender supersedes author_is_borrower @@ -175,7 +176,10 @@ def register_debt(cls, message: Message) -> str: "Försök igen :slight_smile:" # Create the debt entry - Debt.objects.create(borrower=borrower, lender=lender, amount=amount) + Debt.objects.create(borrower=borrower, + lender=lender, + amount=amount, + comment=comment) total_debt_balance = Debt.objects.filter( borrower=borrower, lender=lender ).sum("amount") From 644134d8aa5b015e1adf409f07ebfc7805dc41ef Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:36:42 +0100 Subject: [PATCH 18/28] added comment entity when creating debts --- jarvis/abilities/finance/intents.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jarvis/abilities/finance/intents.py b/jarvis/abilities/finance/intents.py index 1b30ec7..2d45b5f 100644 --- a/jarvis/abilities/finance/intents.py +++ b/jarvis/abilities/finance/intents.py @@ -136,6 +136,7 @@ class AddDebt(Intent): other_person = TextEntityField(valid_strings=SharedFinancesCalculator .enrolled_usernames) amount = IntEntityField() + comment = TextEntityField(span=10, prefixes=("för", "till")) def respond(self, message: Message) -> Reply | ReplyStream: if message.entities["amount"] is None: From a6825d1d09d9d63c7d747803e93b2d383f21a7f1 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:36:59 +0100 Subject: [PATCH 19/28] added comment to 'debt' model --- jarvis/abilities/finance/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jarvis/abilities/finance/models.py b/jarvis/abilities/finance/models.py index d2bb031..b537448 100644 --- a/jarvis/abilities/finance/models.py +++ b/jarvis/abilities/finance/models.py @@ -147,6 +147,7 @@ class Debt(me.Document): lender: User = me.ReferenceField(User, required=True) amount: float = me.FloatField(default=0.0) created: datetime = me.DateTimeField(default=lambda: datetime.now()) + comment = me.StringField(required=False) def __str__(self): """ @@ -157,8 +158,8 @@ def __str__(self): lender = f":bust_in_silhouette: **" \ f"{self.lender.username.capitalize()}**\n" amount = f":money_with_wings: **{self.amount}:-**\n" - - return lender + amount + sep + comment = f":speech_left: **{self.comment}**\n" if self.comment else "" + return lender + amount + comment + sep class AccountingEntry(me.Document): From 8379092fccce2f4d7d4c8ab5847c6cab8b01a1b3 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:37:17 +0100 Subject: [PATCH 20/28] Updated migrations with corrections --- ...002_add_comment_string_field_to_recipe.py} | 12 ++++------ ...000003_add_comment_string_field_to_debt.py | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) rename jarvis/migrations/{00000002_add_comment_stringfield.py => 00000002_add_comment_string_field_to_recipe.py} (70%) create mode 100644 jarvis/migrations/00000003_add_comment_string_field_to_debt.py diff --git a/jarvis/migrations/00000002_add_comment_stringfield.py b/jarvis/migrations/00000002_add_comment_string_field_to_recipe.py similarity index 70% rename from jarvis/migrations/00000002_add_comment_stringfield.py rename to jarvis/migrations/00000002_add_comment_string_field_to_recipe.py index 9ea9a9c..75caf80 100644 --- a/jarvis/migrations/00000002_add_comment_stringfield.py +++ b/jarvis/migrations/00000002_add_comment_string_field_to_recipe.py @@ -1,7 +1,7 @@ from mongoengine import StringField - from jarvis.abilities.recipes.models import Recipe -from jarvis.migrations import expose + +__doc__ = " Assign a 'comment' field to the Recipe model." def upgrade(): @@ -10,13 +10,11 @@ def upgrade(): if hasattr(recipe, "comment"): continue recipe.comment = "" + recipe.save() def downgrade(): for recipe in Recipe.objects.all(): - if isinstance(recipe.name, str): - recipe.name = recipe.name.split() + if hasattr(recipe, "comment"): + del recipe.comment recipe.save() - - -expose() diff --git a/jarvis/migrations/00000003_add_comment_string_field_to_debt.py b/jarvis/migrations/00000003_add_comment_string_field_to_debt.py new file mode 100644 index 0000000..d208055 --- /dev/null +++ b/jarvis/migrations/00000003_add_comment_string_field_to_debt.py @@ -0,0 +1,24 @@ +from mongoengine import StringField +from jarvis.abilities.finance.models import Debt + +column_to_add = StringField(required=False) +column_name = "comment" + +__doc__ = "Assign a 'comment' field to the Debt model." + + +def upgrade(): + Debt.comment = column_to_add + + for debt in Debt.objects.all(): + if hasattr(debt, column_name): + continue + debt.comment = "" + debt.save() + + +def downgrade(): + for debt in Debt.objects.all(): + if hasattr(debt, column_name): + del debt.comment + debt.save() From c0309d954c8fccb03b1692a05ca35db57567eb83 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:57:35 +0100 Subject: [PATCH 21/28] Updated procfile to run migrations --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 6933482..8b20f28 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -worker: pyttman runclient jarvis \ No newline at end of file +worker: pyttman runfile jarvis jarvis/migrations/migrate.py upgrade && pyttman runclient jarvis \ No newline at end of file From 3a99f2f84f71e4025f94fa471ceb5280b70d8040 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 01:57:56 +0100 Subject: [PATCH 22/28] run test or prod server, fetched from environment variable --- jarvis/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis/settings.py b/jarvis/settings.py index 2959c23..d75a7ae 100644 --- a/jarvis/settings.py +++ b/jarvis/settings.py @@ -12,7 +12,7 @@ DB_NAME_PROD = os.getenv("MONGO_DB_NAME_PROD") DB_NAME_DEV = os.getenv("MONGO_DB_NAME_DEV") APPEND_LOG_FILES = True -USE_TEST_SERVER = False +USE_TEST_SERVER = os.getenv("USE_TEST_SERVER") == "True" MIDDLEWARE = { From cee498079917dbb04546a774fbc86528eb8ed164 Mon Sep 17 00:00:00 2001 From: Simon Olofsson <36161882+dotchetter@users.noreply.github.com> Date: Thu, 4 Jan 2024 02:09:36 +0100 Subject: [PATCH 23/28] Create heroku_ci_staging.yml --- .github/workflows/heroku_ci_staging.yml | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/heroku_ci_staging.yml diff --git a/.github/workflows/heroku_ci_staging.yml b/.github/workflows/heroku_ci_staging.yml new file mode 100644 index 0000000..c3bc7cf --- /dev/null +++ b/.github/workflows/heroku_ci_staging.yml @@ -0,0 +1,60 @@ +# Your workflow name. +name: Automated CI/CD Heroku [STAGE] + +# Run workflow on every push to master branch. +on: + workflow_dispatch: {} + push: + branches: [develop] + +# Your workflows jobs. +jobs: + build: + runs-on: ubuntu-latest + steps: + # Check-out your repository. + - name: Checkout + uses: actions/checkout@v3 + + +### ⬇ IMPORTANT PART ⬇ ### + + - name: Build, Push and Release a Docker container to Heroku. # Your custom step name + uses: gonuit/heroku-docker-deploy@v1.3.3 # GitHub action name (leave it as it is). + with: + # Below you must provide variables for your Heroku app. + + # The email address associated with your Heroku account. + # If you don't want to use repository secrets (which is recommended) you can do: + # email: my.email@example.com + email: ${{ secrets.HEROKU_EMAIL }} + + # Heroku API key associated with provided user's email. + # Api Key is available under your Heroku account settings. + heroku_api_key: ${{ secrets.HEROKU_API_KEY }} + + # Name of the heroku application to which the build is to be sent. + heroku_app_name: ${{ secrets.HEROKU_APP_NAME_STAGE }} + + # (Optional, default: "./") + # Dockerfile directory. + # For example, if you have a Dockerfile in the root of your project, leave it as follows: + dockerfile_directory: ./ + + # (Optional, default: "Dockerfile") + # Dockerfile name. + dockerfile_name: Dockerfile + + # (Optional, default: "") + # Additional options of docker build command. + docker_options: "--no-cache" + + # (Optional, default: "web") + # Select the process type for which you want the docker container to be uploaded. + # By default, this argument is set to "web". + # For more information look at https://devcenter.heroku.com/articles/process-model + process_type: worker + + + +### ⬆ IMPORTANT PART ⬆ ### From 586fc2f88d0a54bc0cb8a4f4fa61c999bbf7dd92 Mon Sep 17 00:00:00 2001 From: Simon Olofsson <36161882+dotchetter@users.noreply.github.com> Date: Thu, 4 Jan 2024 02:13:22 +0100 Subject: [PATCH 24/28] Update heroku_ci_staging.yml --- .github/workflows/heroku_ci_staging.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/heroku_ci_staging.yml b/.github/workflows/heroku_ci_staging.yml index c3bc7cf..293715e 100644 --- a/.github/workflows/heroku_ci_staging.yml +++ b/.github/workflows/heroku_ci_staging.yml @@ -3,7 +3,6 @@ name: Automated CI/CD Heroku [STAGE] # Run workflow on every push to master branch. on: - workflow_dispatch: {} push: branches: [develop] From 8d921160b3498bce517abb0876d3c6deca30afb0 Mon Sep 17 00:00:00 2001 From: Simon Olofsson <36161882+dotchetter@users.noreply.github.com> Date: Thu, 4 Jan 2024 02:27:41 +0100 Subject: [PATCH 25/28] Update heroku_ci_staging.yml --- .github/workflows/heroku_ci_staging.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/heroku_ci_staging.yml b/.github/workflows/heroku_ci_staging.yml index 293715e..c3bc7cf 100644 --- a/.github/workflows/heroku_ci_staging.yml +++ b/.github/workflows/heroku_ci_staging.yml @@ -3,6 +3,7 @@ name: Automated CI/CD Heroku [STAGE] # Run workflow on every push to master branch. on: + workflow_dispatch: {} push: branches: [develop] From 00a85532049964f8f25062ad77e681024a34d4f9 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 02:58:38 +0100 Subject: [PATCH 26/28] Improved how to check debts --- jarvis/abilities/finance/ability.py | 7 +++++-- jarvis/abilities/finance/intents.py | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jarvis/abilities/finance/ability.py b/jarvis/abilities/finance/ability.py index 5eaa698..56685a0 100644 --- a/jarvis/abilities/finance/ability.py +++ b/jarvis/abilities/finance/ability.py @@ -207,8 +207,11 @@ def get_debts(cls, message: Message) -> ReplyStream[str]: """ reply_stream = ReplyStream() debts_by_lender: dict[User, int] = {} - borrower_name = extract_username(message, "borrower_name") - borrower: User = User.objects.from_username_or_alias(borrower_name) + if message.entities["author_is_borrower"]: + borrower = User.objects.from_message(message) + else: + borrower_name = extract_username(message, "borrower_name") + borrower: User = User.objects.from_username_or_alias(borrower_name) debt_sum = Debt.objects.filter(borrower=borrower).sum("amount") if borrower is None: diff --git a/jarvis/abilities/finance/intents.py b/jarvis/abilities/finance/intents.py index 2d45b5f..044dfb7 100644 --- a/jarvis/abilities/finance/intents.py +++ b/jarvis/abilities/finance/intents.py @@ -149,9 +149,10 @@ class GetDebts(Intent): Returns the sum of the debts registered for a borrower to a particular lender. """ - lead = ("visa", "lista", "show", "get", "hämta") - trail = ("skuld", "skulder", "debts", "lån", "lånat", "lånade") + lead = ("visa", "lista", "show", "get", "hämta", "hur") + trail = ("skuld", "skulder", "debts", "lån", "lånat", "lånade", "skyldig") + author_is_borrower = BoolEntityField(message_contains=("jag", "i")) borrower_name = TextEntityField( valid_strings=SharedFinancesCalculator.enrolled_usernames) From 402169b6ee11326af86a1fc513223b4896a9adc6 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 03:05:33 +0100 Subject: [PATCH 27/28] added 'individual' to debts, allowing users to enter details about the debt when they borrow --- jarvis/abilities/finance/ability.py | 10 +++++++--- jarvis/abilities/finance/intents.py | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/jarvis/abilities/finance/ability.py b/jarvis/abilities/finance/ability.py index 56685a0..fa9d9f1 100644 --- a/jarvis/abilities/finance/ability.py +++ b/jarvis/abilities/finance/ability.py @@ -233,9 +233,13 @@ def get_debts(cls, message: Message) -> ReplyStream[str]: except KeyError: debts_by_lender[debt.lender] = debt.amount - for lender, _sum in debts_by_lender.items(): - debt = Debt(lender=lender, borrower=borrower, amount=_sum) - reply_stream.put(debt) + if message.entities["individual"]: + for debt in Debt.objects.filter(borrower=borrower): + reply_stream.put(debt) + else: + for lender, _sum in debts_by_lender.items(): + debt = Debt(lender=lender, borrower=borrower, amount=_sum) + reply_stream.put(debt) return reply_stream diff --git a/jarvis/abilities/finance/intents.py b/jarvis/abilities/finance/intents.py index 044dfb7..ea63ba9 100644 --- a/jarvis/abilities/finance/intents.py +++ b/jarvis/abilities/finance/intents.py @@ -155,6 +155,9 @@ class GetDebts(Intent): author_is_borrower = BoolEntityField(message_contains=("jag", "i")) borrower_name = TextEntityField( valid_strings=SharedFinancesCalculator.enrolled_usernames) + individual = BoolEntityField(message_contains=("individuell", + "individuella", + "individuellt")) def respond(self, message: Message) -> Reply | ReplyStream: return self.ability.get_debts(message) From 4f542ff48dd79ad5e8f80be2afa4daedbcec03cc Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 4 Jan 2024 03:20:07 +0100 Subject: [PATCH 28/28] dont track log file --- jarvis/logs/jarvis.log | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 jarvis/logs/jarvis.log diff --git a/jarvis/logs/jarvis.log b/jarvis/logs/jarvis.log deleted file mode 100644 index e69de29..0000000