From 090f36f3b7147340ef5bfa7be8e57bb2f3d805c1 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Wed, 28 Feb 2024 14:00:20 +0100 Subject: [PATCH 01/12] =?UTF-8?q?=E2=9C=A8=20(ContentKit):=20Activity=20-?= =?UTF-8?q?=20Add=20createdAt,=20lastEditedAt=20properties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContentKitExample/Sources/ActivityDetailsView.swift | 2 ++ Modules/ContentKit/Sources/Activity/Activity+Mock.swift | 3 +++ Modules/ContentKit/Sources/Activity/Activity.swift | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityDetailsView.swift b/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityDetailsView.swift index 5d3cd64de3..5d90e9e936 100644 --- a/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityDetailsView.swift +++ b/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityDetailsView.swift @@ -49,6 +49,8 @@ struct ActivityDetailsView: View { Section("Information") { RowView(label: "UUID", value: self.activity.id) RowView(label: "Name", value: self.activity.name) + RowView(label: "Created at", value: self.activity.createdAt.description) + RowView(label: "Last edited at", value: self.activity.lastEditedAt.description) RowView(label: "Status", value: self.activity.status == .published ? "published" : "draft") diff --git a/Modules/ContentKit/Sources/Activity/Activity+Mock.swift b/Modules/ContentKit/Sources/Activity/Activity+Mock.swift index 5e38937d51..20f4160df0 100644 --- a/Modules/ContentKit/Sources/Activity/Activity+Mock.swift +++ b/Modules/ContentKit/Sources/Activity/Activity+Mock.swift @@ -18,6 +18,9 @@ public extension Activity { uuid: E7EE9CA4B13B49AF96CD77A9DF90833B name: mock_activity + created_at: 2024-02-28T12:53:48+00:00 + last_edited_at: 2024-02-28T12:53:48+00:00 + status: published authors: diff --git a/Modules/ContentKit/Sources/Activity/Activity.swift b/Modules/ContentKit/Sources/Activity/Activity.swift index a330bd15e2..0a399f3845 100644 --- a/Modules/ContentKit/Sources/Activity/Activity.swift +++ b/Modules/ContentKit/Sources/Activity/Activity.swift @@ -19,6 +19,8 @@ public struct Activity: Decodable, Identifiable { self.uuid = try container.decode(String.self, forKey: .uuid) self.name = try container.decode(String.self, forKey: .name) + self.createdAt = try container.decode(Date.self, forKey: .createdAt) + self.lastEditedAt = try container.decode(Date.self, forKey: .lastEditedAt) self.status = try container.decode(Status.self, forKey: .status) self.authors = try container.decode([String].self, forKey: .authors) @@ -38,6 +40,8 @@ public struct Activity: Decodable, Identifiable { public let uuid: String public let name: String + public let createdAt: Date + public let lastEditedAt: Date public let status: Status public let authors: [String] // TODO: (@ladislas) - implement authors @@ -72,12 +76,14 @@ public struct Activity: Decodable, Identifiable { private enum CodingKeys: String, CodingKey { case uuid case name + case createdAt = "created_at" + case lastEditedAt = "last_edited_at" + case status case authors case skills case hmi case types case tags - case status case locales case l10n case exercicesPayload = "exercises_payload" From cefe14f22f2d4483c7ef20a0b1a9eb0fa2d49ab1 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Wed, 28 Feb 2024 13:35:59 +0100 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=94=A7=20(jtd):=20Activity=20-=20ad?= =?UTF-8?q?d=20created=5Fat=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Specs/jtd/activity.jtd.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Specs/jtd/activity.jtd.json b/Specs/jtd/activity.jtd.json index 58261e4c7e..4a5abcf42c 100644 --- a/Specs/jtd/activity.jtd.json +++ b/Specs/jtd/activity.jtd.json @@ -9,6 +9,9 @@ "name": { "type": "string" }, + "created_at": { + "type": "string" + }, "status": { "ref": "$status" }, From 81f2378dd1a9a2947afeba52b45cafb5fee73bf0 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Wed, 28 Feb 2024 14:50:18 +0100 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20(hook?= =?UTF-8?q?s):=20Activities=20-=20add=20missing=20key=20created=5Fat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tools/Hooks/check_yaml_content_activities.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tools/Hooks/check_yaml_content_activities.py b/Tools/Hooks/check_yaml_content_activities.py index 0bd344f125..2f7f44f680 100755 --- a/Tools/Hooks/check_yaml_content_activities.py +++ b/Tools/Hooks/check_yaml_content_activities.py @@ -10,6 +10,7 @@ import uuid import sys from pathlib import Path +from datetime import datetime import ruamel.yaml @@ -17,6 +18,8 @@ SKILLS_FILE = "Modules/ContentKit/Resources/Content/definitions/skills.yml" CONTENTKIT_DIRECTORY = "Modules/ContentKit/Resources/Content" +CREATED_AT_INDEX = 3 + # # Mark: - Functions @@ -89,6 +92,17 @@ def check_content_activity(filename): print(f"uuid: {data['uuid']}") file_is_valid = False + # ? Check created_at is present + if "created_at" not in data: + print(f"\n❌ Missing key created_at in {filename}") + print(f"Add created_at: {datetime.now().isoformat()}") + if "name" in data and "status" in data: + data.insert(CREATED_AT_INDEX, "created_at", datetime.now().isoformat()) + with open(filename, "w", encoding="utf8") as file: + yaml.dump(data, file) + + file_is_valid = False + # ? Check schema validation with ajv os.environ["FORCE_COLOR"] = "true" cmd = ( From a96b4c65347c8e1fffa1cdad5bd0b5ece4291c85 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Wed, 28 Feb 2024 14:50:57 +0100 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=8D=B1=20(ContentKit):=20Activities?= =?UTF-8?q?=20-=20add=20missing=20key=20created=5Fat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml | 1 + .../sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml | 1 + .../sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml | 1 + .../sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml | 1 + .../sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml | 1 + .../sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml | 1 + ...tivity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml | 1 + 7 files changed, 7 insertions(+) diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml index 5579f7b615..695882f0f8 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml @@ -7,6 +7,7 @@ version: 1.0.0 uuid: 5A670B59EB214A6AA11AB39D64D63990 name: sample_1 +created_at: "2024-02-28T14:49:32.982712" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml index 84ea6b4496..4686cd2b9e 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml @@ -7,6 +7,7 @@ version: 1.0.0 uuid: 6102794F02D3423482E243BCBC7F8CA8 name: sample_2 +created_at: "2024-02-28T14:49:34.312602" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml index cd4337444d..590b285cb2 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml @@ -7,6 +7,7 @@ version: 1.0.0 uuid: E7EE9CA4B13B49AF96CD77A9DF90833B name: sample_3 +created_at: "2024-02-28T14:49:33.391679" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml index 0f980df8dd..4df7126628 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml @@ -7,6 +7,7 @@ version: 1.0.0 uuid: 81F6617499FE42ADB5B03B409462923E name: sample_4 +created_at: "2024-02-28T14:49:33.392801" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml index 78075a5b76..09dbb5dbb8 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml @@ -7,6 +7,7 @@ version: 1.0.0 uuid: 725853C4DC7B4D84A45AA20385F389F1 name: sample_5 +created_at: "2024-02-28T14:49:33.890955" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml index 338b8e9a57..7f60281360 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml @@ -7,6 +7,7 @@ version: 1.0.0 uuid: 2FE0B8BDD1B0497F87B32A390119DB98 name: sample_6 +created_at: "2024-02-28T14:49:33.894132" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml b/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml index 31d62ed816..af932833bc 100644 --- a/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml @@ -7,6 +7,7 @@ version: 1.0.0 uuid: 0123456789ABCDEF0123456789ABCDEF # {{💡TO_DEFINE}} name: activity_template # {{💡TO_DEFINE}} +created_at: "2024-02-28T14:49:32.973012" status: published authors: # {{💡TO_DEFINE}} From 54bb4745052e7d6b74302dbd639ceb445202e0f5 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 09:53:20 +0100 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=94=A7=20(jtd):=20Activity=20-=20ad?= =?UTF-8?q?d=20last=5Fedited=5Fat=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Specs/jtd/activity.jtd.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Specs/jtd/activity.jtd.json b/Specs/jtd/activity.jtd.json index 4a5abcf42c..f74f2884b3 100644 --- a/Specs/jtd/activity.jtd.json +++ b/Specs/jtd/activity.jtd.json @@ -12,6 +12,9 @@ "created_at": { "type": "string" }, + "last_edited_at": { + "type": "string" + }, "status": { "ref": "$status" }, From 47cbbc63015804e9ca0e8d311b46f82370d97196 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 10:00:14 +0100 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20(hook?= =?UTF-8?q?s):=20Activities=20-=20add=20missing=20key=20last=5Fedited=5Fat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tools/Hooks/check_yaml_content_activities.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Tools/Hooks/check_yaml_content_activities.py b/Tools/Hooks/check_yaml_content_activities.py index 2f7f44f680..50ab99553b 100755 --- a/Tools/Hooks/check_yaml_content_activities.py +++ b/Tools/Hooks/check_yaml_content_activities.py @@ -19,6 +19,8 @@ CONTENTKIT_DIRECTORY = "Modules/ContentKit/Resources/Content" CREATED_AT_INDEX = 3 +LAST_EDITED_AT_INDEX = 4 +DATE_NOW_TIMESTAMP = datetime.now().isoformat() # @@ -95,9 +97,20 @@ def check_content_activity(filename): # ? Check created_at is present if "created_at" not in data: print(f"\n❌ Missing key created_at in {filename}") - print(f"Add created_at: {datetime.now().isoformat()}") + print(f"Add created_at: {DATE_NOW_TIMESTAMP}") if "name" in data and "status" in data: - data.insert(CREATED_AT_INDEX, "created_at", datetime.now().isoformat()) + data.insert(CREATED_AT_INDEX, "created_at", DATE_NOW_TIMESTAMP) + with open(filename, "w", encoding="utf8") as file: + yaml.dump(data, file) + + file_is_valid = False + + # ? Check last_edited_at is present + if "last_edited_at" not in data: + print(f"\n❌ Missing key last_edited_at in {filename}") + print(f"Add last_edited_at: {DATE_NOW_TIMESTAMP}") + if "name" in data and "status" in data: + data.insert(LAST_EDITED_AT_INDEX, "last_edited_at", DATE_NOW_TIMESTAMP) with open(filename, "w", encoding="utf8") as file: yaml.dump(data, file) From 556fb5ee88c1fee70c14188b7292fd6e282890a7 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 10:00:41 +0100 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=8D=B1=20(ContentKit):=20Activities?= =?UTF-8?q?=20-=20add=20missing=20key=20last=5Fedited=5Fat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml | 1 + .../sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml | 1 + .../sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml | 1 + .../sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml | 1 + .../sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml | 1 + .../sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml | 1 + ...tivity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml | 1 + 7 files changed, 7 insertions(+) diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml index 695882f0f8..21ae4f7c2d 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_1-5A670B59EB214A6AA11AB39D64D63990.activity.yml @@ -8,6 +8,7 @@ uuid: 5A670B59EB214A6AA11AB39D64D63990 name: sample_1 created_at: "2024-02-28T14:49:32.982712" +last_edited_at: "2024-02-29T09:57:32.346571" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml index 4686cd2b9e..b97af5f6f2 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_2-6102794F02D3423482E243BCBC7F8CA8.activity.yml @@ -8,6 +8,7 @@ uuid: 6102794F02D3423482E243BCBC7F8CA8 name: sample_2 created_at: "2024-02-28T14:49:34.312602" +last_edited_at: "2024-02-29T09:57:32.346571" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml index 590b285cb2..6b49370ef0 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml @@ -8,6 +8,7 @@ uuid: E7EE9CA4B13B49AF96CD77A9DF90833B name: sample_3 created_at: "2024-02-28T14:49:33.391679" +last_edited_at: "2024-02-29T09:57:32.346571" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml index 4df7126628..d1544ee832 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_4-81F6617499FE42ADB5B03B409462923E.activity.yml @@ -8,6 +8,7 @@ uuid: 81F6617499FE42ADB5B03B409462923E name: sample_4 created_at: "2024-02-28T14:49:33.392801" +last_edited_at: "2024-02-29T09:57:32.346568" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml index 09dbb5dbb8..f516a44905 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_5-725853C4DC7B4D84A45AA20385F389F1.activity.yml @@ -8,6 +8,7 @@ uuid: 725853C4DC7B4D84A45AA20385F389F1 name: sample_5 created_at: "2024-02-28T14:49:33.890955" +last_edited_at: "2024-02-29T09:57:32.346568" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml index 7f60281360..8718bde4eb 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_6-2FE0B8BDD1B0497F87B32A390119DB98.activity.yml @@ -8,6 +8,7 @@ uuid: 2FE0B8BDD1B0497F87B32A390119DB98 name: sample_6 created_at: "2024-02-28T14:49:33.894132" +last_edited_at: "2024-02-29T09:57:32.346571" status: published authors: diff --git a/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml b/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml index af932833bc..cc11e3ddda 100644 --- a/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/templates/activity_template-0123456789ABCDEF0123456789ABCDEF.activity.yml @@ -8,6 +8,7 @@ uuid: 0123456789ABCDEF0123456789ABCDEF # {{💡TO_DEFINE}} name: activity_template # {{💡TO_DEFINE}} created_at: "2024-02-28T14:49:32.973012" +last_edited_at: "2024-02-29T09:57:32.346568" status: published authors: # {{💡TO_DEFINE}} From 0c93ca7d00fead3e24592b3951a215fb3228bfde Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 10:32:55 +0100 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20(hook?= =?UTF-8?q?):=20Activity=20content=20-=20use=20double=20quotes=20for=20str?= =?UTF-8?q?ings,=20keep=20null=20in=20dump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tools/Hooks/check_yaml_content_activities.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tools/Hooks/check_yaml_content_activities.py b/Tools/Hooks/check_yaml_content_activities.py index 50ab99553b..e18aa6ccdc 100755 --- a/Tools/Hooks/check_yaml_content_activities.py +++ b/Tools/Hooks/check_yaml_content_activities.py @@ -20,7 +20,9 @@ CREATED_AT_INDEX = 3 LAST_EDITED_AT_INDEX = 4 -DATE_NOW_TIMESTAMP = datetime.now().isoformat() +DATE_NOW_TIMESTAMP = ruamel.yaml.scalarstring.DoubleQuotedScalarString( + datetime.now().isoformat() +) # @@ -71,6 +73,11 @@ def check_content_activity(filename): # ? Create a YAML object yaml = ruamel.yaml.YAML(typ="rt") yaml.indent(mapping=2, sequence=4, offset=2) + yaml.preserve_quotes = True + yaml.representer.add_representer( + type(None), + lambda dumper, data: dumper.represent_scalar("tag:yaml.org,2002:null", "null"), + ) file_is_valid = True From 3fa476c3873eb95f963a0141033a619f77b54a75 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 10:42:36 +0100 Subject: [PATCH 09/12] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(hooks):=20Activity?= =?UTF-8?q?=20content=20-=20move=20yaml=20config=20to=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tools/Hooks/check_yaml_content_activities.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Tools/Hooks/check_yaml_content_activities.py b/Tools/Hooks/check_yaml_content_activities.py index e18aa6ccdc..d3180a308d 100755 --- a/Tools/Hooks/check_yaml_content_activities.py +++ b/Tools/Hooks/check_yaml_content_activities.py @@ -68,9 +68,8 @@ def find_skill_ids(data, ids): return ids -def check_content_activity(filename): - """Check the content of a YAML file for an activity""" - # ? Create a YAML object +def create_yaml_object(): + """Create a YAML object""" yaml = ruamel.yaml.YAML(typ="rt") yaml.indent(mapping=2, sequence=4, offset=2) yaml.preserve_quotes = True @@ -78,6 +77,12 @@ def check_content_activity(filename): type(None), lambda dumper, data: dumper.represent_scalar("tag:yaml.org,2002:null", "null"), ) + return yaml + + +def check_content_activity(filename): + """Check the content of a YAML file for an activity""" + yaml = create_yaml_object() file_is_valid = True From 9791e3e120ce787c6b75f6ede36ea6ef50790e45 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 11:01:40 +0100 Subject: [PATCH 10/12] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20(hook?= =?UTF-8?q?s):=20Activities=20-=20update=20last=5Fedited=5Fat=20on=20chang?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tools/Hooks/check_yaml_content_activities.py | 41 +++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Tools/Hooks/check_yaml_content_activities.py b/Tools/Hooks/check_yaml_content_activities.py index d3180a308d..7e372a2d32 100755 --- a/Tools/Hooks/check_yaml_content_activities.py +++ b/Tools/Hooks/check_yaml_content_activities.py @@ -10,7 +10,7 @@ import uuid import sys from pathlib import Path -from datetime import datetime +from datetime import datetime, timedelta import ruamel.yaml @@ -68,6 +68,29 @@ def find_skill_ids(data, ids): return ids +def is_file_modified(file_path): + """Check if a file is modified and/or staged for commit""" + result = subprocess.run( + ["git", "status", "--porcelain", file_path], + capture_output=True, + text=True, + check=False, + ) + + output = result.stdout.strip() + + if output: + # Check for modifications in both staged (index) and work tree + # Staged modifications: first letter is not ' ' (space) + # Work tree modifications: second letter is 'M' + # This covers added (A), modified (M), deleted (D), renamed (R), etc. + status_code = output[:2] + if status_code[0] != " " or status_code[1] == "M": + return True + + return False + + def create_yaml_object(): """Create a YAML object""" yaml = ruamel.yaml.YAML(typ="rt") @@ -128,6 +151,22 @@ def check_content_activity(filename): file_is_valid = False + # ? Update last_edited_at if DATE_NOW_TIMESTAMP is more recent with a threshold of 1 minute + if is_file_modified(filename) and "last_edited_at" in data: + last_edited_at = datetime.fromisoformat(data["last_edited_at"]) + one_minute_ago = datetime.fromisoformat(DATE_NOW_TIMESTAMP) - timedelta( + minutes=1 + ) + if last_edited_at < one_minute_ago: + print(f"\n❌ last_edited_at in {filename} is not up to date") + print(f"last_edited_at: {last_edited_at}") + print(f"Update last_edited_at: {DATE_NOW_TIMESTAMP}") + data["last_edited_at"] = DATE_NOW_TIMESTAMP + with open(filename, "w", encoding="utf8") as file: + yaml.dump(data, file) + + file_is_valid = False + # ? Check schema validation with ajv os.environ["FORCE_COLOR"] = "true" cmd = ( From dd448034e57ae8bfac557166bca9d6c71526a644 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 11:02:16 +0100 Subject: [PATCH 11/12] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20(hooks):=20Activity?= =?UTF-8?q?=20-=20update=20last=5Fedited=5Fat=20on=20file=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml index 6b49370ef0..3579b9a736 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml @@ -8,7 +8,7 @@ uuid: E7EE9CA4B13B49AF96CD77A9DF90833B name: sample_3 created_at: "2024-02-28T14:49:33.391679" -last_edited_at: "2024-02-29T09:57:32.346571" +last_edited_at: "2024-02-29T11:06:01.695641" status: published authors: @@ -44,7 +44,7 @@ l10n: details: icon: sample_3 - title: Activité d'exemple 3 + title: Activité d'exemple 3 - modified for testing subtitle: pour le développement short_description: > From d0fb56a8c9e9247c2e1244d4e31d88b86dffed02 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 29 Feb 2024 11:06:23 +0100 Subject: [PATCH 12/12] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20(hooks):=20Activity?= =?UTF-8?q?=20-=20modify=20file=20with=20not=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml index 3579b9a736..19159ccd85 100644 --- a/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml +++ b/Modules/ContentKit/Resources/Content/activities/examples/sample_3-E7EE9CA4B13B49AF96CD77A9DF90833B.activity.yml @@ -44,7 +44,7 @@ l10n: details: icon: sample_3 - title: Activité d'exemple 3 - modified for testing + title: Activité d'exemple 3 - modified for testing - again without update of last_edited_at subtitle: pour le développement short_description: >