From 50156120cd09f3bbbce2ca7133fd14f9cc0252c2 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 5 Jun 2024 11:48:21 +0100 Subject: [PATCH 01/22] Update roles/home/helix.nix --- roles/home/helix.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/roles/home/helix.nix b/roles/home/helix.nix index 027f9da..9bc7869 100644 --- a/roles/home/helix.nix +++ b/roles/home/helix.nix @@ -76,8 +76,7 @@ in command = "golangci-lint-langserver" [language-server.golangci-lint-langserver.config] - command = ["golangci-lint", "run","--enable-all", "-D", "godox", "-D", "godot", "--out-format", "json", "--issues-exit-code=1"] - + command = ["golangci-lint", "run", "--out-format", "json", "--issues-exit-code=1"] ''; }; }; From ac7315ff598a34354c459a64d12214108a45dd3f Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 5 Jun 2024 13:37:51 +0100 Subject: [PATCH 02/22] Update roles/home/helix.nix --- roles/home/helix.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/home/helix.nix b/roles/home/helix.nix index 9bc7869..6dde9c5 100644 --- a/roles/home/helix.nix +++ b/roles/home/helix.nix @@ -31,6 +31,8 @@ in gopls golangci-lint golangci-lint-langserver + gh + gofumpt ] ++ nodePkgs; sessionVariables = { From 9977b89d902927616a12e1eb40d2369dd6e1075d Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 5 Jun 2024 15:14:35 +0100 Subject: [PATCH 03/22] Update roles/home/helix.nix --- roles/home/helix.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/home/helix.nix b/roles/home/helix.nix index 6dde9c5..9f16bd8 100644 --- a/roles/home/helix.nix +++ b/roles/home/helix.nix @@ -48,7 +48,8 @@ in cursorline = true true-color = true gutters = ["diff", "diagnostics", "line-numbers", "spacer"] - + indent = { tab-width = 2, unit = "\t" } + [editor.cursor-shape] insert = "bar" normal = "block" From e5b806cdde99f9c0b2e6ff03e271a9bf4683d129 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 5 Jun 2024 15:18:35 +0100 Subject: [PATCH 04/22] Update roles/home/helix.nix --- roles/home/helix.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/home/helix.nix b/roles/home/helix.nix index 9f16bd8..0714640 100644 --- a/roles/home/helix.nix +++ b/roles/home/helix.nix @@ -48,7 +48,6 @@ in cursorline = true true-color = true gutters = ["diff", "diagnostics", "line-numbers", "spacer"] - indent = { tab-width = 2, unit = "\t" } [editor.cursor-shape] insert = "bar" From c002fadb445759ad994e5081e6c9c7a42031692b Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 5 Jun 2024 15:21:14 +0100 Subject: [PATCH 05/22] Update roles/home/helix.nix --- roles/home/helix.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/home/helix.nix b/roles/home/helix.nix index 0714640..4f1638a 100644 --- a/roles/home/helix.nix +++ b/roles/home/helix.nix @@ -70,6 +70,10 @@ in name = "nix" formatter = { command = "nixpkgs-fmt" } + [[language]] + name = "bash" + formatter = { command = ["shfmt", "-s", "-ci", "-sr"] } + [[language]] name = "go" language-servers = ["gopls", "golangci-lint-langserver"] From f8ce135e8e6a5ceab3abb0caa9df2d0b53005ce0 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 5 Jun 2024 15:22:01 +0100 Subject: [PATCH 06/22] Update roles/home/helix.nix --- roles/home/helix.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/home/helix.nix b/roles/home/helix.nix index 4f1638a..b628798 100644 --- a/roles/home/helix.nix +++ b/roles/home/helix.nix @@ -72,7 +72,7 @@ in [[language]] name = "bash" - formatter = { command = ["shfmt", "-s", "-ci", "-sr"] } + formatter = { command = "shfmt -s -ci -sr" } [[language]] name = "go" From 6a4c95010cddc6befcaabaea63dd9e477e11b1e3 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 5 Jun 2024 15:23:58 +0100 Subject: [PATCH 07/22] Update roles/home/helix.nix --- roles/home/helix.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/home/helix.nix b/roles/home/helix.nix index b628798..b636711 100644 --- a/roles/home/helix.nix +++ b/roles/home/helix.nix @@ -72,7 +72,7 @@ in [[language]] name = "bash" - formatter = { command = "shfmt -s -ci -sr" } + formatter = { command = "shfmt", args = ["-s", "-ci", "-sr"] } [[language]] name = "go" From 771c2c0e6553428e6b2f424388099eb56b55c0b7 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Fri, 7 Jun 2024 10:04:16 +0100 Subject: [PATCH 08/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index d0c0a49..44771c2 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -19,8 +19,8 @@ let max_input_tokens: 128000 max_output_tokens: 8192 - - name: codestral:22b-v0.1-q6_K - max_input_tokens: 32000 + - name: pino-coder + max_input_tokens: 28000 max_output_tokens: 8192 - type: openai From 89cc2be685d17d7745378cab21933758ced7bb03 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Fri, 7 Jun 2024 11:58:18 +0100 Subject: [PATCH 09/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 51 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 44771c2..47d6cf4 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -96,13 +96,56 @@ let 3. **Details of Changes:** Describe the key changes made, referencing specific files or functions if necessary. 4. **Impact:** Discuss any potential impact on the system, including backward compatibility, performance implications, and any new dependencies. - ### Input: Git diff + ### INPUT: - __ARG1__ + ``` + diff --git a/src/app.js b/src/app.js + index 83d2e7a..b6a1c3f 100644 + --- a/src/app.js + +++ b/src/app.js + @@ -10,6 +10,10 @@ function initialize() { + setupEventListeners(); + } - ### Input: Commit messages + +// TODO: add other listeners + +// https://github.com/user/project/issue/123 + +function setupEventListeners() { + + document.getElementById('submit').addEventListener('click', handleSubmit); + + document.getElementById('reset').addEventListener('click', handleReset); + +} + + + function handleSubmit(event) { + event.preventDefault(); + const data = new FormData(event.target); + @@ -20,6 +24,10 @@ function handleSubmit(event) { - __ARG2__ + console.log('Form submitted:', data); + } + + +function handleReset(event) { + + event.preventDefault(); + + event.target.form.reset(); + + console.log('Form reset'); + } + ``` + + ### OUTPUT: + + **Title:** feat(app): add event listeners for submit and reset buttons + + **Summary:** + This PR adds event listeners for the submit and reset buttons in the application. It introduces a new function to set up these event listeners and implements a handler for the reset button. + + **Details of Changes:** + 1. **src/app.js:** + - Added a new function `setupEventListeners` to attach click event listeners to the submit and reset buttons. + - Implemented the `handleReset` function to reset the form and log the reset action. + - Included a TODO comment to add other listeners, referencing issue [#123](https://github.com/user/project/issue/123). + + **Impact:** + - **Backward Compatibility:** The changes are backward compatible. + - **Performance Implications:** Minimal performance impact due to the addition of event listeners. + - **New Dependencies:** No new dependencies introduced. ''; in { From e109349112115b5ee224c37aac394ea48c3603d4 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Fri, 7 Jun 2024 11:58:32 +0100 Subject: [PATCH 10/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 47d6cf4..c6bb33f 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -85,7 +85,7 @@ let - Added TODO comment for issue #123 ``` - - name: createpr:diff:messages + - name: createpr prompt: |- You are an AI language model tasked with generating a comprehensive Pull Request (PR) description. Your goal is to create a clear and informative PR description that summarizes the changes and highlights any important details or considerations. You are given a git diff and a list of commits - use this context to generate the PR message. From c756fc15b2283d4c2266405c973ab3a97a6711bd Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Fri, 7 Jun 2024 13:22:22 +0100 Subject: [PATCH 11/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index c6bb33f..d87a971 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -82,7 +82,7 @@ let - Added `setupEventListeners` function to handle submit and reset button click events - Implemented `handleReset` function to reset the form and log the action - - Added TODO comment for issue #123 + - Added TODO comment for issue https://github.com/user/project/issue/123 ``` - name: createpr From e3013a77b720bb981c19c151e0c2316152c114ec Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 1 Jul 2024 18:18:39 +0100 Subject: [PATCH 12/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 170 ++++++++++++++++++++++++++++++------------ 1 file changed, 124 insertions(+), 46 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index d87a971..08a5903 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -28,62 +28,140 @@ let api_base: https://api.openai.com/v1 ''; - roles = '' - - name: commitmessage - prompt: |- - The task is to generate a commit message for a given git diff. The commit message should follow the Commit Convention, which typically includes a type, scope, and a brief description. The types can be `feat` (for new features), `fix` (for bug fixes), `docs` (for documentation changes), `style` (for code formatting changes), `refactor` (for code restructuring), `test` (for adding or updating tests), `chore` (for maintenance tasks), and `perf` (for performance improvements). +roles = '' + - name: commitmessage + prompt: |- + Your task is to generate a commit message for a given git diff. The commit message should follow the Conventional Commits specification, which includes a type, optional scope, and a brief description. The message should be concise, unambiguous, and capture the technical details of the changes made. - **Commit Convention Format:** - ``` - (): + Commit Convention Format: + (): - - - ``` + [optional body] - The description should be concise, unambiguos yet capture the technical details of the changes made. The output should exclusively be the commit message. + [optional footer(s)] - ### INPUT: + Common types include: + - feat: A new feature + - fix: A bug fix + - docs: Documentation changes + - style: Code style/formatting changes (not affecting code logic) + - refactor: Code changes that neither fix a bug nor add a feature + - test: Adding or modifying tests + - chore: Changes to build process or auxiliary tools + - perf: Performance improvements - ``` - diff --git a/src/app.js b/src/app.js - index 83d2e7a..b6a1c3f 100644 - --- a/src/app.js - +++ b/src/app.js - @@ -10,6 +10,10 @@ function initialize() { - setupEventListeners(); - } + Here are some examples of well-formatted commit messages: - +// TODO: add other listeners - +// https://github.com/user/project/issue/123 - +function setupEventListeners() { - + document.getElementById('submit').addEventListener('click', handleSubmit); - + document.getElementById('reset').addEventListener('click', handleReset); - +} - + - function handleSubmit(event) { - event.preventDefault(); - const data = new FormData(event.target); - @@ -20,6 +24,10 @@ function handleSubmit(event) { + ### INPUT : - console.log('Form submitted:', data); - } + ```diff + diff --git a/src/utils/date-formatter.js b/src/utils/date-formatter.js + index 2345678..3456789 100644 + --- a/src/utils/date-formatter.js + +++ b/src/utils/date-formatter.js + @@ -5,7 +5,7 @@ export function formatDate(date) { + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + - return `${year}-${month}-${day}`; + + return `${year}/${month}/${day}`; + } + ``` - +function handleReset(event) { - + event.preventDefault(); - + event.target.form.reset(); - + console.log('Form reset'); - } - ``` - - ### OUTPUT: + ### OUTPUT: - ``` - feat(app): add event listeners for submit and reset buttons + ``` + fix(date-formatter): change date format separator from hyphen to slash - - Added `setupEventListeners` function to handle submit and reset button click events - - Implemented `handleReset` function to reset the form and log the action - - Added TODO comment for issue https://github.com/user/project/issue/123 - ``` + - Modified `formatDate()` to use '/' instead of '-' as the separator + ``` + + ### INPUT: + + ```diff + diff --git a/src/components/Button.js b/src/components/Button.js + index 7890123..8901234 100644 + --- a/src/components/Button.js + +++ b/src/components/Button.js + @@ -1,5 +1,5 @@ + import React from 'react'; + -import './Button.css'; + +import styles from './Button.module.css'; + + const Button = ({ label, onClick }) => { + - return ; + + return ; + }; + ``` + + ### OUTPUT: + + ``` + refactor(Button): migrate to CSS modules + + - Replaced import of Button.css with Button.module.css + - Updated className to use styles object for better encapsulation + ``` + + ### INPUT: + + ``` + diff --git a/src/app.js b/src/app.js + index 83d2e7a..b6a1c3f 100644 + --- a/src/app.js + +++ b/src/app.js + @@ -10,6 +10,10 @@ function initialize() { + setupEventListeners(); + } + + +// TODO: add other listeners + +// https://github.com/user/project/issue/123 + +function setupEventListeners() { + + document.getElementById('submit').addEventListener('click', handleSubmit); + + document.getElementById('reset').addEventListener('click', handleReset); + +} + + + function handleSubmit(event) { + event.preventDefault(); + const data = new FormData(event.target); + @@ -20,6 +24,10 @@ function handleSubmit(event) { + + console.log('Form submitted:', data); + } + + +function handleReset(event) { + + event.preventDefault(); + + event.target.form.reset(); + + console.log('Form reset'); + } + + ### OUTPUT: + + ``` + feat(app): implement form event listeners + + - Added `setupEventListeners()` to handle form interactions + - Implemented `handleReset()` function for form reset functionality + - Added event listeners for submit and reset buttons + - Track TODO comment for future listener additions (issue #123) + + ### INPUT: + + diff --git a/ci/entrypoint.sh b/ci/entrypoint.sh + index 03a7870..50bc7f0 100755 + --- a/ci/entrypoint.sh + +++ b/ci/entrypoint.sh + @@ -181,7 +181,7 @@ ts_build_directory() { + } + + prep_go() { + - go download && go mod tidy + + go mod download && go mod tidy + } + + ### OUTPUT: + + fix (cicd): Modified `prep_go` function to use `go mod download` instead of `go download` + ``` - name: createpr prompt: |- From fe6d156580c8bba2cd638f79ff4661eebf07290a Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 1 Jul 2024 18:19:40 +0100 Subject: [PATCH 13/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 08a5903..10618fe 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -54,7 +54,6 @@ roles = '' ### INPUT : - ```diff diff --git a/src/utils/date-formatter.js b/src/utils/date-formatter.js index 2345678..3456789 100644 --- a/src/utils/date-formatter.js @@ -65,19 +64,15 @@ roles = '' - return `${year}-${month}-${day}`; + return `${year}/${month}/${day}`; } - ``` ### OUTPUT: - ``` fix(date-formatter): change date format separator from hyphen to slash - Modified `formatDate()` to use '/' instead of '-' as the separator - ``` ### INPUT: - ```diff diff --git a/src/components/Button.js b/src/components/Button.js index 7890123..8901234 100644 --- a/src/components/Button.js @@ -91,20 +86,16 @@ roles = '' - return ; + return ; }; - ``` ### OUTPUT: - ``` refactor(Button): migrate to CSS modules - Replaced import of Button.css with Button.module.css - Updated className to use styles object for better encapsulation - ``` ### INPUT: - ``` diff --git a/src/app.js b/src/app.js index 83d2e7a..b6a1c3f 100644 --- a/src/app.js @@ -136,7 +127,6 @@ roles = '' ### OUTPUT: - ``` feat(app): implement form event listeners - Added `setupEventListeners()` to handle form interactions @@ -161,7 +151,6 @@ roles = '' ### OUTPUT: fix (cicd): Modified `prep_go` function to use `go mod download` instead of `go download` - ``` - name: createpr prompt: |- From 047c36f1cabb22bb8c423b47bf39896c664caffe Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 1 Jul 2024 18:20:31 +0100 Subject: [PATCH 14/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 10618fe..b2f891c 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -61,8 +61,8 @@ roles = '' @@ -5,7 +5,7 @@ export function formatDate(date) { const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); - - return `${year}-${month}-${day}`; - + return `${year}/${month}/${day}`; + - return `$${year}-$${month}-$${day}`; + + return `$${year}/$${month}/$${day}`; } ### OUTPUT: From 866a5de2b8964079eba9ad536a9fe7bed8a0a3e7 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 1 Jul 2024 18:26:31 +0100 Subject: [PATCH 15/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 100 +++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index b2f891c..5905eda 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -152,67 +152,67 @@ roles = '' fix (cicd): Modified `prep_go` function to use `go mod download` instead of `go download` - - name: createpr - prompt: |- - You are an AI language model tasked with generating a comprehensive Pull Request (PR) description. Your goal is to create a clear and informative PR description that summarizes the changes and highlights any important details or considerations. - You are given a git diff and a list of commits - use this context to generate the PR message. + - name: createpr + prompt: |- + You are an AI language model tasked with generating a comprehensive Pull Request (PR) description. Your goal is to create a clear and informative PR description that summarizes the changes and highlights any important details or considerations. + You are given a git diff and a list of commits - use this context to generate the PR message. - # Requirements for the PR Description: - 1. **Title:** Provide a concise and descriptive title for the PR. - 2. **Summary:** Summarize the overall purpose and scope of the changes. - 3. **Details of Changes:** Describe the key changes made, referencing specific files or functions if necessary. - 4. **Impact:** Discuss any potential impact on the system, including backward compatibility, performance implications, and any new dependencies. + # Requirements for the PR Description: + 1. **Title:** Provide a concise and descriptive title for the PR. + 2. **Summary:** Summarize the overall purpose and scope of the changes. + 3. **Details of Changes:** Describe the key changes made, referencing specific files or functions if necessary. + 4. **Impact:** Discuss any potential impact on the system, including backward compatibility, performance implications, and any new dependencies. - ### INPUT: + ### INPUT: - ``` - diff --git a/src/app.js b/src/app.js - index 83d2e7a..b6a1c3f 100644 - --- a/src/app.js - +++ b/src/app.js - @@ -10,6 +10,10 @@ function initialize() { - setupEventListeners(); - } + ``` + diff --git a/src/app.js b/src/app.js + index 83d2e7a..b6a1c3f 100644 + --- a/src/app.js + +++ b/src/app.js + @@ -10,6 +10,10 @@ function initialize() { + setupEventListeners(); + } - +// TODO: add other listeners - +// https://github.com/user/project/issue/123 - +function setupEventListeners() { - + document.getElementById('submit').addEventListener('click', handleSubmit); - + document.getElementById('reset').addEventListener('click', handleReset); - +} - + - function handleSubmit(event) { - event.preventDefault(); - const data = new FormData(event.target); - @@ -20,6 +24,10 @@ function handleSubmit(event) { + +// TODO: add other listeners + +// https://github.com/user/project/issue/123 + +function setupEventListeners() { + + document.getElementById('submit').addEventListener('click', handleSubmit); + + document.getElementById('reset').addEventListener('click', handleReset); + +} + + + function handleSubmit(event) { + event.preventDefault(); + const data = new FormData(event.target); + @@ -20,6 +24,10 @@ function handleSubmit(event) { - console.log('Form submitted:', data); - } + console.log('Form submitted:', data); + } - +function handleReset(event) { - + event.preventDefault(); - + event.target.form.reset(); - + console.log('Form reset'); - } - ``` + +function handleReset(event) { + + event.preventDefault(); + + event.target.form.reset(); + + console.log('Form reset'); + } + ``` - ### OUTPUT: + ### OUTPUT: - **Title:** feat(app): add event listeners for submit and reset buttons + **Title:** feat(app): add event listeners for submit and reset buttons - **Summary:** - This PR adds event listeners for the submit and reset buttons in the application. It introduces a new function to set up these event listeners and implements a handler for the reset button. + **Summary:** + This PR adds event listeners for the submit and reset buttons in the application. It introduces a new function to set up these event listeners and implements a handler for the reset button. - **Details of Changes:** - 1. **src/app.js:** - - Added a new function `setupEventListeners` to attach click event listeners to the submit and reset buttons. - - Implemented the `handleReset` function to reset the form and log the reset action. - - Included a TODO comment to add other listeners, referencing issue [#123](https://github.com/user/project/issue/123). + **Details of Changes:** + 1. **src/app.js:** + - Added a new function `setupEventListeners` to attach click event listeners to the submit and reset buttons. + - Implemented the `handleReset` function to reset the form and log the reset action. + - Included a TODO comment to add other listeners, referencing issue [#123](https://github.com/user/project/issue/123). - **Impact:** - - **Backward Compatibility:** The changes are backward compatible. - - **Performance Implications:** Minimal performance impact due to the addition of event listeners. - - **New Dependencies:** No new dependencies introduced. + **Impact:** + - **Backward Compatibility:** The changes are backward compatible. + - **Performance Implications:** Minimal performance impact due to the addition of event listeners. + - **New Dependencies:** No new dependencies introduced. ''; in { From 180556cf4514900d90dab025925306c8e8faa585 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 1 Jul 2024 18:30:11 +0100 Subject: [PATCH 16/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 5905eda..66f30dc 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -130,7 +130,7 @@ roles = '' feat(app): implement form event listeners - Added `setupEventListeners()` to handle form interactions - - Implemented `handleReset()` function for form reset functionality + - Implemented `handleReset()` for form reset functionality - Added event listeners for submit and reset buttons - Track TODO comment for future listener additions (issue #123) @@ -150,7 +150,7 @@ roles = '' ### OUTPUT: - fix (cicd): Modified `prep_go` function to use `go mod download` instead of `go download` + fix (cicd): Modified `prep_go()` to use `go mod download` instead of `go download` - name: createpr prompt: |- From 1459444d6cf1f43170692ba22d7390d4edafae4d Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 1 Jul 2024 18:34:08 +0100 Subject: [PATCH 17/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 66f30dc..495e662 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -67,32 +67,7 @@ roles = '' ### OUTPUT: - fix(date-formatter): change date format separator from hyphen to slash - - - Modified `formatDate()` to use '/' instead of '-' as the separator - - ### INPUT: - - diff --git a/src/components/Button.js b/src/components/Button.js - index 7890123..8901234 100644 - --- a/src/components/Button.js - +++ b/src/components/Button.js - @@ -1,5 +1,5 @@ - import React from 'react'; - -import './Button.css'; - +import styles from './Button.module.css'; - - const Button = ({ label, onClick }) => { - - return ; - + return ; - }; - - ### OUTPUT: - - refactor(Button): migrate to CSS modules - - - Replaced import of Button.css with Button.module.css - - Updated className to use styles object for better encapsulation + fix(date-formatter): modified `formatDate()` to use '/' instead of '-' as the separator ### INPUT: @@ -132,7 +107,7 @@ roles = '' - Added `setupEventListeners()` to handle form interactions - Implemented `handleReset()` for form reset functionality - Added event listeners for submit and reset buttons - - Track TODO comment for future listener additions (issue #123) + - Track TODO comment for future listener additions (https://github.com/user/project/issue/123) ### INPUT: From 22bc7e809c66fea00549ce95dc3cea3d1a9fd868 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 1 Jul 2024 18:40:29 +0100 Subject: [PATCH 18/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 117 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 10 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 495e662..39d6939 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -111,21 +111,118 @@ roles = '' ### INPUT: - diff --git a/ci/entrypoint.sh b/ci/entrypoint.sh - index 03a7870..50bc7f0 100755 - --- a/ci/entrypoint.sh - +++ b/ci/entrypoint.sh - @@ -181,7 +181,7 @@ ts_build_directory() { + diff --git a/structs/routing_test.go b/structs/routing_test.go + index 2e19254..04191cc 100644 + --- a/structs/routing_test.go + +++ b/structs/routing_test.go + @@ -3,7 +3,7 @@ package structs_test + import ( + "testing" + + - "github.com/stretchr/testify/assert" + + "github.com/stretchr/testify/require" + "github.pie.apple.com/kerosene/Core/structs" + "gorm.io/datatypes" + ) + @@ -15,18 +15,18 @@ func TestNewRoutingBuilder(t *testing.T) { + scheme := "http" + + builder, err := structs.NewRoutingBuilder(name, proxy, port, scheme) + - assert.NoError(t, err) + + require.NoError(t, err) + + routing, err := builder.Build() + - assert.NoError(t, err) + - + - assert.Equal(t, name, routing.Name) + - assert.Equal(t, proxy, routing.Proxy) + - assert.Equal(t, port, routing.Port) + - assert.Equal(t, scheme, routing.Scheme) + - assert.Equal(t, datatypes.JSON(`[]`), routing.NameServers) + - assert.Nil(t, routing.Providers) + - assert.Nil(t, routing.Assets) + + require.NoError(t, err) + + + + require.Equal(t, name, routing.Name) + + require.Equal(t, proxy, routing.Proxy) + + require.Equal(t, port, routing.Port) + + require.Equal(t, scheme, routing.Scheme) + + require.Equal(t, datatypes.JSON(`[]`), routing.NameServers) + + require.Nil(t, routing.Providers) + + require.Nil(t, routing.Assets) } - - prep_go() { - - go download && go mod tidy - + go mod download && go mod tidy + + func TestRoutingBuilderMethods(t *testing.T) { + @@ -39,7 +39,7 @@ func TestRoutingBuilderMethods(t *testing.T) { + assets := []structs.Asset{} + + builder, err := structs.NewRoutingBuilder(name, proxy, port, scheme) + - assert.NoError(t, err) + + require.NoError(t, err) + + routing, err := builder. + WithProviders(providers). + @@ -47,38 +47,24 @@ func TestRoutingBuilderMethods(t *testing.T) { + WithAssets(assets). + Build() + + - assert.NoError(t, err) + - assert.Equal(t, providers, routing.Providers) + - assert.Equal(t, nameServers, routing.NameServers) + - assert.Equal(t, assets, routing.Assets) + + require.NoError(t, err) + + require.Equal(t, providers, routing.Providers) + + require.Equal(t, nameServers, routing.NameServers) + + require.Equal(t, assets, routing.Assets) + } + + -// func TestRoutingBuilderValidation(t *testing.T) { + -// builder, err := structs.NewRoutingBuilder("exampleName", "exampleProxy", 8080, "http") + -// assert.NoError(t, err) + - + -// // Test successful build + -// routing, err := builder.Build() + -// assert.NoError(t, err) + -// assert.NotNil(t, routing) + - + -// // Test invalid build with missing required fields + -// builder.routing.Name = "" + -// routing, err = builder.Build() + -// assert.Error(t, err) + -// assert.Nil(t, routing) + -// } + - + func TestRoutingBuilderSanityChecks(t *testing.T) { + + t.Parallel() + + + _, err := structs.NewRoutingBuilder("", "exampleProxy", 8080, "http") + - assert.Error(t, err) + - assert.Equal(t, structs.ErrInvalidName, err) + + require.Error(t, err) + + require.Equal(t, structs.ErrInvalidName, err) + + _, err = structs.NewRoutingBuilder("exampleName", "", 8080, "http") + - assert.Error(t, err) + - assert.Equal(t, structs.ErrInvalidProxy, err) + + require.Error(t, err) + + require.Equal(t, structs.ErrInvalidProxy, err) + + _, err = structs.NewRoutingBuilder("exampleName", "exampleProxy", 8080, "") + - assert.Error(t, err) + - assert.Equal(t, structs.ErrInvalidScheme, err) + + require.Error(t, err) + + require.Equal(t, structs.ErrInvalidScheme, err) } ### OUTPUT: - fix (cicd): Modified `prep_go()` to use `go mod download` instead of `go download` + refactor(structs_tests): update test assertion library to 'require' and refactor tests for better readability + + - Replaced the 'assert' library with 'require' in routing_test.go + - Refined code formatting and added comments + - Removed commented out test functions + - Added `t.Parallel()` + - name: createpr prompt: |- From 897b7eb6448f7afa601695e82c03e382b4409662 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Tue, 2 Jul 2024 15:07:16 +0100 Subject: [PATCH 19/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 39d6939..d95cfd1 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -111,6 +111,43 @@ roles = '' ### INPUT: + diff --git a/pkg/database/client.go b/pkg/database/client.go + index 003740f..6fc4861 100644 + --- a/pkg/database/client.go + +++ b/pkg/database/client.go + @@ -24,9 +24,12 @@ var ErrNilDatabaseClient = errors.New("database client is nil after setup") + + // InitDB initializes the database with the given application name and optional dbpath for SQLite. + func InitDB(appName string, dbpath ...string) error { + - cfg := config.New() + + var ( + + psqlReadReplica string + + err error + + ) + + - var err error + + cfg := config.New() + + // Set up a new logger with your required configuration. + newLogger := logger.New( + @@ -38,9 +41,8 @@ func InitDB(appName string, dbpath ...string) error { + }, + ) + + - // Load PostgreSQL configurations + - var psqlReadReplica string + psqlSource, err := cfg.Load(config.PSQL.String()) + + + if err != nil { + log.Println("PSQL not set, using SQLite instead.") + } else { + + ### OUTPUT: + + style(database/client): group together `psqlReadReplica` and `err` in function's prologue + + ### INPUT: + diff --git a/structs/routing_test.go b/structs/routing_test.go index 2e19254..04191cc 100644 --- a/structs/routing_test.go From abb0002c4cc8bd1f36b7050a978c95dffe9b06a0 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Tue, 2 Jul 2024 15:20:14 +0100 Subject: [PATCH 20/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 138 ++++++++++++------------------------------ 1 file changed, 39 insertions(+), 99 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index d95cfd1..8af249c 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -148,117 +148,57 @@ roles = '' ### INPUT: - diff --git a/structs/routing_test.go b/structs/routing_test.go - index 2e19254..04191cc 100644 - --- a/structs/routing_test.go - +++ b/structs/routing_test.go - @@ -3,7 +3,7 @@ package structs_test - import ( - "testing" - - - "github.com/stretchr/testify/assert" - + "github.com/stretchr/testify/require" + diff --git a/pkg/khttp/client.go b/pkg/khttp/client.go + index a53064c..3aff938 100644 + --- a/pkg/khttp/client.go + +++ b/pkg/khttp/client.go + @@ -11,14 +11,17 @@ import ( "github.pie.apple.com/kerosene/Core/structs" - "gorm.io/datatypes" ) - @@ -15,18 +15,18 @@ func TestNewRoutingBuilder(t *testing.T) { - scheme := "http" - builder, err := structs.NewRoutingBuilder(name, proxy, port, scheme) - - assert.NoError(t, err) - + require.NoError(t, err) + +// TODO: https://github.pie.apple.com/Kerosene/Core/issues/43 + +// feat: Centralise and remove over use of os.Environment + const ( + - // Environment variables and file names. + authFilesDirEnvVar = "WHISPER_AUTH_FILES_DIR" + keyName = "decrypted_key.pem" + certName = "cert.pem" + ) - routing, err := builder.Build() - - assert.NoError(t, err) - - - - assert.Equal(t, name, routing.Name) - - assert.Equal(t, proxy, routing.Proxy) - - assert.Equal(t, port, routing.Port) - - assert.Equal(t, scheme, routing.Scheme) - - assert.Equal(t, datatypes.JSON(`[]`), routing.NameServers) - - assert.Nil(t, routing.Providers) - - assert.Nil(t, routing.Assets) - + require.NoError(t, err) + // Error for missing environment variable. + +// TODO: refactor: move errors into centralized errors.go files + +// https://github.pie.apple.com/Kerosene/Core/issues/57 + var errMissingEnvironmentVariable = fmt.Errorf("%s environment variable is not set", authFilesDirEnvVar) + + // AuthConfig holds authentication file paths. + @@ -31,9 +34,11 @@ type AuthConfig struct { + // NewAuthConfig creates an AuthConfig from environment variables. + func NewAuthConfig() (*AuthConfig, error) { + dir := os.Getenv(authFilesDirEnvVar) + - + require.Equal(t, name, routing.Name) - + require.Equal(t, proxy, routing.Proxy) - + require.Equal(t, port, routing.Port) - + require.Equal(t, scheme, routing.Scheme) - + require.Equal(t, datatypes.JSON(`[]`), routing.NameServers) - + require.Nil(t, routing.Providers) - + require.Nil(t, routing.Assets) - } - - func TestRoutingBuilderMethods(t *testing.T) { - @@ -39,7 +39,7 @@ func TestRoutingBuilderMethods(t *testing.T) { - assets := []structs.Asset{} - - builder, err := structs.NewRoutingBuilder(name, proxy, port, scheme) - - assert.NoError(t, err) - + require.NoError(t, err) - - routing, err := builder. - WithProviders(providers). - @@ -47,38 +47,24 @@ func TestRoutingBuilderMethods(t *testing.T) { - WithAssets(assets). - Build() - - - assert.NoError(t, err) - - assert.Equal(t, providers, routing.Providers) - - assert.Equal(t, nameServers, routing.NameServers) - - assert.Equal(t, assets, routing.Assets) - + require.NoError(t, err) - + require.Equal(t, providers, routing.Providers) - + require.Equal(t, nameServers, routing.NameServers) - + require.Equal(t, assets, routing.Assets) - } - - -// func TestRoutingBuilderValidation(t *testing.T) { - -// builder, err := structs.NewRoutingBuilder("exampleName", "exampleProxy", 8080, "http") - -// assert.NoError(t, err) - - - -// // Test successful build - -// routing, err := builder.Build() - -// assert.NoError(t, err) - -// assert.NotNil(t, routing) - - - -// // Test invalid build with missing required fields - -// builder.routing.Name = "" - -// routing, err = builder.Build() - -// assert.Error(t, err) - -// assert.Nil(t, routing) - -// } - - - func TestRoutingBuilderSanityChecks(t *testing.T) { - + t.Parallel() + if dir == "" { + return nil, errMissingEnvironmentVariable + } + - _, err := structs.NewRoutingBuilder("", "exampleProxy", 8080, "http") - - assert.Error(t, err) - - assert.Equal(t, structs.ErrInvalidName, err) - + require.Error(t, err) - + require.Equal(t, structs.ErrInvalidName, err) + return &AuthConfig{ + Dir: dir, + CertFile: filepath.Join(dir, certName), + @@ -211,7 +216,7 @@ func setupMTLSOnlyTransport(certData string, keyData string) (*http.Transport, e - _, err = structs.NewRoutingBuilder("exampleName", "", 8080, "http") - - assert.Error(t, err) - - assert.Equal(t, structs.ErrInvalidProxy, err) - + require.Error(t, err) - + require.Equal(t, structs.ErrInvalidProxy, err) - - _, err = structs.NewRoutingBuilder("exampleName", "exampleProxy", 8080, "") - - assert.Error(t, err) - - assert.Equal(t, structs.ErrInvalidScheme, err) - + require.Error(t, err) - + require.Equal(t, structs.ErrInvalidScheme, err) + // Make scheme and Auth Type separate and load from DB. + func parseProxyURL(scheme string, routing structs.Routing) (*url.URL, error) { + - return url.Parse(fmt.Sprintf("%s://%s:%s", scheme, routing.Proxy, routing.Port)) + + return url.Parse(fmt.Sprintf("%s://%s:%d", scheme, routing.Proxy, routing.Port)) } + + // loadX509KeyPair loads an X509 key pair from the specified cert and key files. ### OUTPUT: - refactor(structs_tests): update test assertion library to 'require' and refactor tests for better readability + fix/refactor(khttp/client): use correct format specifier for and add TODOs - - Replaced the 'assert' library with 'require' in routing_test.go - - Refined code formatting and added comments - - Removed commented out test functions - - Added `t.Parallel()` + - Parsed proxy URL using `fmt.Sprintf()` with correct format specifier for port + - Added TODOs to centralize errors and remove overuse of `os.Environment` (#43, #57) - name: createpr From 29692c5f29ec904ef2add5eaab6fb648a1b84ba7 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 3 Jul 2024 10:13:02 +0100 Subject: [PATCH 21/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 518 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 481 insertions(+), 37 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 8af249c..87e5591 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -214,54 +214,498 @@ roles = '' ### INPUT: - ``` - diff --git a/src/app.js b/src/app.js - index 83d2e7a..b6a1c3f 100644 - --- a/src/app.js - +++ b/src/app.js - @@ -10,6 +10,10 @@ function initialize() { - setupEventListeners(); + diff --git a/cmd/api/main.go b/cmd/api/main.go + index 8b974c8..9dfd24b 100644 + --- a/cmd/api/main.go + +++ b/cmd/api/main.go + @@ -33,6 +33,8 @@ func loadAppConfig() *AppConfig { } - - +// TODO: add other listeners - +// https://github.com/user/project/issue/123 - +function setupEventListeners() { - + document.getElementById('submit').addEventListener('click', handleSubmit); - + document.getElementById('reset').addEventListener('click', handleReset); - +} + + func main() { + + applyMigrations := false + + cfg := config.New() + err := config.SetSecret([]string{ + "TEMPORAL_ADDRESS", + "PSQL", + @@ -42,13 +44,23 @@ func main() { + "REDASH_API_KEY", + "INFOBLOX_SECRET", + }) + - function handleSubmit(event) { - event.preventDefault(); - const data = new FormData(event.target); - @@ -20,6 +24,10 @@ function handleSubmit(event) { - - console.log('Form submitted:', data); + if err != nil { + log.Printf("Could not set secrets: %v", err) + + os.Exit(1) + } + + - database.InitDB("Core") + + runMigrations, _ := cfg.Load(config.RunMigration.String()) + + if runMigrations != "" { + + applyMigrations = true + + } + + + + err = database.InitDB("Core", applyMigrations) + + + + if err != nil { + + log.Fatalf("Cannot initialize DB: %v", err) + + } + + appConfig := loadAppConfig() + + diff --git a/cmd/fixtures/fixtures.go b/cmd/fixtures/fixtures.go + index 3d23a6d..ff3290e 100644 + --- a/cmd/fixtures/fixtures.go + +++ b/cmd/fixtures/fixtures.go + @@ -10,13 +10,27 @@ import ( + + "github.com/go-faker/faker/v4" + "github.com/lib/pq" + + "github.pie.apple.com/kerosene/Core/pkg/config" + "github.pie.apple.com/kerosene/Core/pkg/database" + "github.pie.apple.com/kerosene/Core/structs" + ) + + // Initializing worker, database, producer and redis when the program starts. + func init() { + - database.InitDB("DatabaseManager", "W") + + applyMigrations := false + + cfg := config.New() + + + + runMigrations, _ := cfg.Load(config.RunMigration.String()) + + if runMigrations != "" { + + applyMigrations = true + + } + + + + err := database.InitDB("DatabaseManager", applyMigrations, "W") + + + + if err != nil { + + log.Fatalf("Cannot initialize DB: %s", err) + + } + + + rand.Seed(time.Now().UnixNano()) + } + + diff --git a/cmd/migrator/migrator.go b/cmd/migrator/migrator.go + index 3b9961a..278cc2b 100755 + --- a/cmd/migrator/migrator.go + +++ b/cmd/migrator/migrator.go + @@ -17,13 +17,12 @@ func main() { + automigrate := flag.Bool("auto", false, "Run auto-migration") + apply := flag.String("apply", "", "Apply a specific migration file") + deleteFlag := flag.Bool("delete", false, "Delete existing tables before migration") + - configDir := flag.String("configDir", "", "Optional directory for configuration files") + + flag.Parse() + + utils.LogStep("Connecting to the database...") + + - err := database.InitDB("Migrator") + + err := database.InitDB("Migrator", *automigrate) + if err != nil { + utils.LogFatal("Could not initialise DB: ", err) + } + @@ -40,16 +39,13 @@ func main() { + } + + switch { + - case *automigrate: + - if err := database.DBAutoMigration(database.Client, *configDir); err != nil { + - utils.LogFatal("Failed to run auto-migration", err) + - } + - + case *apply != "": + if err := database.ApplyMigration(database.Client, *apply); err != nil { + utils.LogFatal("Failed to apply migration", err) + } + - + + case *automigrate: + + // Just log a message as the migrations are handled by InitDB + + utils.LogInfo("Initialized DB with auto-migrations") + default: + flag.Usage() + os.Exit(1) + diff --git a/pkg/advans/connect.go b/pkg/advans/connect.go + index cbcfdb3..f65c59c 100644 + --- a/pkg/advans/connect.go + +++ b/pkg/advans/connect.go + @@ -4,6 +4,7 @@ import ( + "bytes" + "encoding/json" + "fmt" + + "log" + "net/http" + + "github.pie.apple.com/kerosene/Core/pkg/config" + @@ -28,7 +29,21 @@ type Payload struct { + var cfg = config.New() + + func init() { + - database.InitDB("IngestionPipeline", "W") + + applyMigrations := false + + + + runMigrations, _ := cfg.Load(config.RunMigration.String()) + + if runMigrations != "" { + + applyMigrations = true + + } + + + + err := database.InitDB("IngestionPipeline", applyMigrations, "W") + + + + if err != nil { + + log.Fatalf("Cannot initialize DB: %s", err) + + } + + + + // TODO check errors! + + // https://github.pie.apple.com/Kerosene/Core/issues/51 + config.SetSecret([]string{"ADVANS_MTLS_PRIVATE_KEY", "ADVANS_MTLS_CERT", "ADVANS_API_END_POINT"}) + } + + @@ -42,6 +57,7 @@ func initMTLSClient(certFilePath, keyFilePath string) (*http.Client, error) { + + func sendPayload(client *http.Client, advansEndpoint string, path string, payload Payload) error { + payloadBytes, err := json.Marshal(payload) + + + if err != nil { + return fmt.Errorf("error marshalling payload: %s", err) + } + @@ -63,88 +79,3 @@ func sendPayload(client *http.Client, advansEndpoint string, path string, payloa + + return nil } - +function handleReset(event) { - + event.preventDefault(); - + event.target.form.reset(); - + console.log('Form reset'); + diff --git a/pkg/config/main.go b/pkg/config/main.go + index ec14c10..e80c2c2 100644 + --- a/pkg/config/main.go + +++ b/pkg/config/main.go + @@ -16,6 +16,7 @@ import ( + var ( + errSecretNotFound = errors.New("secret not found") + errSecretDuplicateSource = errors.New("tried to retrieve secret from multiple sources") + + errDataConfigDirNotExists = errors.New("data config directory does not exist") + errSecretNotSet = errors.New("secret not set in any provider or as an environment variable") + errUnknownProvider = errors.New("unknown provider when retrieving secret") + errWhisperAuthDirNotSet = errors.New("whisper authentication file directory not specified") + @@ -28,8 +29,12 @@ var ( + errWhisperRetrieveContent = errors.New("could not retrieve whisper secret's content") + ) + + -type configProvider string + -type configKey string + +const defaultDataConfigDir = "Config/" + + + +type ( + + configProvider string + + configKey string + +) + + func (cg configKey) String() string { + return string(cg) + @@ -40,17 +45,18 @@ func (cp configProvider) String() string { } - ``` + + const ( + - whisperProvider configProvider = "WHISPER" + - PSQL configKey = "PSQL" + - PSQLRead configKey = "PSQL_READ" + - TemporalAddress configKey = "TEMPORAL_ADDRESS" + - KafkaBrokers configKey = "KAFKA_BROKERS" + - RedisURI configKey = "REDIS" + - KeroseneEnvironment configKey = "ENVIRONMENT" + - ElasticSearchURI configKey = "ELASTICSEARCH_URL" + - Proxy configKey = "PROXY" + - Queue configKey = "QUEUE" + - RunMigration configKey = "RUN_AUTOMIGRATION" + + whisperProvider configProvider = "WHISPER" + + PSQL configKey = "PSQL" + + PSQLRead configKey = "PSQL_READ" + + TemporalAddress configKey = "TEMPORAL_ADDRESS" + + KafkaBrokers configKey = "KAFKA_BROKERS" + + RedisURI configKey = "REDIS" + + KeroseneEnvironment configKey = "ENVIRONMENT" + + ElasticSearchURI configKey = "ELASTICSEARCH_URL" + + Proxy configKey = "PROXY" + + Queue configKey = "QUEUE" + + RunMigration configKey = "RUN_AUTOMIGRATION" + + DefaultDataConfigDir configKey = "DEFAULT_DATA_CONFIG_DIR" + ) + + var providers = []configProvider{ + @@ -353,3 +359,23 @@ func (c *Config) Load(name string) (string, error) { + + return val, nil + } + + + +func (c *Config) GetDataConfigDir() (string, error) { + + retDir := defaultDataConfigDir + + + + overriddenConfigDir, _ := c.Load(DefaultDataConfigDir.String()) + + if overriddenConfigDir != "" { + + retDir = overriddenConfigDir + + } + + + + // check appended / + + if len(retDir) > 0 && retDir[len(retDir)-1] != '/' { + + retDir += "/" + + } + + + + if _, err := os.Stat(retDir); os.IsNotExist(err) { + + return "", errDataConfigDirNotExists + + } + + + + return retDir, nil + +} + diff --git a/pkg/database/client.go b/pkg/database/client.go + index 6fc4861..444bb5a 100644 + --- a/pkg/database/client.go + +++ b/pkg/database/client.go + @@ -19,17 +19,27 @@ import ( + "gorm.io/plugin/dbresolver" + ) + + -var Client *gorm.DB + -var ErrNilDatabaseClient = errors.New("database client is nil after setup") + +var ( + + Client *gorm.DB + + errNilDatabaseClient = errors.New("database client is nil after setup") + +) + + + +func determineApplyMigration(cfg *config.Config, automigrate bool) bool { + + overrideAutomigrate, _ := cfg.Load(config.RunMigration.String()) + + + + // the env var takes precedence! + + return overrideAutomigrate != "" || automigrate + +} + + // InitDB initializes the database with the given application name and optional dbpath for SQLite. + -func InitDB(appName string, dbpath ...string) error { + +func InitDB(appName string, automigrate bool, dbpath ...string) error { + var ( + psqlReadReplica string + err error + ) + + cfg := config.New() + + applyMigration := determineApplyMigration(&cfg, automigrate) + + // Set up a new logger with your required configuration. + newLogger := logger.New( + @@ -87,12 +97,12 @@ func InitDB(appName string, dbpath ...string) error { + if Client == nil { + log.Println("database client is nil after setup, aborting") + + - return ErrNilDatabaseClient + + return errNilDatabaseClient + } + + // Run auto-migration if using SQLite + - if isSQLiteDB(Client) { + - if err := DBAutoMigration(Client, ""); err != nil { + + if applyMigration && isSQLiteDB(Client) { + + if err := DBAutoMigration(Client); err != nil { + log.Printf("failed to run SQLite auto-migration: %v", err) + + return err + @@ -105,6 +115,7 @@ func InitDB(appName string, dbpath ...string) error { + // setupPostgres sets up a PostgreSQL database connection. + func setupPostgres(newLogger logger.Interface, appName, dbURI string) (*gorm.DB, error) { + dbURI = appendApplicationName(dbURI, appName) + + + return gorm.Open(postgres.Open(dbURI), &gorm.Config{ + Logger: newLogger, + }) + @@ -132,19 +143,19 @@ func setupPostgresWithReplicas(newLogger logger.Interface, appName, sourceURI, r + + // setupSQLite sets up a SQLite database connection. + func setupSQLite(newLogger logger.Interface, dbpath ...string) (*gorm.DB, error) { + - var sqliteFile string + + sqliteFile := "file::memory:?cache=shared" + + + if len(dbpath) > 0 { + sqliteFile = dbpath[0] + + + // Ensure the SQLite file ends with .db + if filepath.Ext(sqliteFile) != ".db" { + return nil, errors.New("SQLite file must have a .db extension") + } + - } else { + - // Default is to use an in-memory db + - sqliteFile = "file::memory:?cache=shared" + } + + log.Printf("Using SQLite: %s", sqliteFile) + + + return gorm.Open(sqlite.Open(sqliteFile), &gorm.Config{ + Logger: newLogger, + }) + diff --git a/pkg/database/migrations.go b/pkg/database/migrations.go + index 6582b99..3210216 100644 + --- a/pkg/database/migrations.go + +++ b/pkg/database/migrations.go + @@ -27,6 +27,7 @@ func ApplyMigration(dbClient *gorm.DB, filename string) error { + } + + utils.LogSuccess("Migration applied successfully.") + + + return nil + } + + @@ -47,22 +48,26 @@ func GeneratePassword() (string, error) { + return cfg.Load("REDASH_PASSWORD") + } + + -func DBAutoMigration(dbClient *gorm.DB, configDir string) error { + +func DBAutoMigration(dbClient *gorm.DB) error { + utils.LogStep("Running auto-migration...") + + dbDialect := dbClient.Dialector.Name() + + + if dbDialect == "postgres" { + if err := PSQLStart(); err != nil { + return fmt.Errorf("failed to initialize database: %v", err) + } + + + utils.LogSuccess("Database initialization completed successfully.") + utils.LogStep("Generating Redash password...") + + + password, err := GeneratePassword() + if err != nil { + return fmt.Errorf("failed to generate password: %v", err) + } + + utils.LogStep("Creating Redash user...") + + + if err := CreateUserRedash(password); err != nil { + utils.LogWarning("Failed to create Redash user", err) + } else { + @@ -72,11 +77,7 @@ func DBAutoMigration(dbClient *gorm.DB, configDir string) error { + ReflectionMigration() + } + + - if configDir != "" { + - initialise.GenerateInitData(dbClient, configDir) + - } else { + - initialise.GenerateInitData(dbClient) + - } + + initialise.GenerateInitData(dbClient) + + return nil + } + @@ -91,12 +92,15 @@ func RunAutoMigration() error { + dbTablesValue := reflect.ValueOf(structs.DatabaseTables) + for i := 0; i < dbTablesValue.NumField(); i++ { + field := dbTablesValue.Field(i) + + + if field.Kind() == reflect.Ptr && !field.IsNil() { + structValue := field.Elem() + + + if err := Client.AutoMigrate(structValue.Addr().Interface()); err != nil { + return fmt.Errorf("failed to auto-migrate model %v: %v", structValue.Type().Name(), err) + } + } + } + + + return nil + } + diff --git a/pkg/initialise/configInit.go b/pkg/initialise/configInit.go + index d087531..323a3d7 100644 + --- a/pkg/initialise/configInit.go + +++ b/pkg/initialise/configInit.go + @@ -9,6 +9,7 @@ import ( + "reflect" + "strings" + + + "github.pie.apple.com/kerosene/Core/pkg/config" + "github.pie.apple.com/kerosene/Core/pkg/utils" + "github.pie.apple.com/kerosene/Core/structs" + "gopkg.in/yaml.v2" + @@ -16,30 +17,28 @@ import ( + "gorm.io/gorm" + ) + + -//go:embed config + -var configFiles embed.FS + +var ( + + //go:embed config + + configFiles embed.FS + + cfg config.Config = config.New() + +) + + func GenerateInitData(database *gorm.DB, additionalConfigDir ...string) { + utils.LogHeader("INITIALISING DEFAULT DATA") + + - configDir := "config" + - if len(additionalConfigDir) > 0 { + - configDir = additionalConfigDir[0] + - + - utils.LogInfo(fmt.Sprintf("Using additional config directory: %s", configDir)) + + configDir, err := cfg.GetDataConfigDir() + + - if _, err := os.Stat(configDir); os.IsNotExist(err) { + - utils.LogWarning(fmt.Sprintf("Config directory does not exist: %s", configDir), err) + - } + - } else { + - utils.LogInfo("Using Default Config") + + if err != nil { + + utils.LogFatal("Cannot open config directory: %w", err) + } + + + utils.LogInfo("Using data config directory: " + configDir) + + + // Get the list of directories in the embedded config directory + - embeddedConfigDirs := getConfigDirs("config") + + embeddedConfigDirs := getConfigDirs(configDir) + + // Process the embedded configs + - processConfigs(database, embeddedConfigDirs, "config/") + + processConfigs(database, embeddedConfigDirs, configDir) + + // If an additional config directory is provided, process it after the embedded configs + if len(additionalConfigDir) > 0 { + @@ -47,7 +46,7 @@ func GenerateInitData(database *gorm.DB, additionalConfigDir ...string) { + + utils.LogHeader("ADDITIONAL DATA") + + - processConfigs(database, additionalConfigDirs, configDir+"/") + + processConfigs(database, additionalConfigDirs, configDir) + } + + utils.LogInfo(fmt.Sprintf("Initialised Default Data for environment '%s'.", os.Getenv("ENVIRONMENT"))) + @@ -113,9 +112,11 @@ func insertPrioritizedStruct(db *gorm.DB, configDirs []string, configPath, struc + } + + func getConfigDirs(path string) []string { + - var configDirs []string + - var entries []os.DirEntry + - var err error + + var ( + + configDirs []string + + entries []os.DirEntry + + err error + + ) + + // Check if the path is the default embedded directory or an external path + if path == "config" { ### OUTPUT: - **Title:** feat(app): add event listeners for submit and reset buttons + feat(config): add new env vars and refactor database initialization - **Summary:** - This PR adds event listeners for the submit and reset buttons in the application. It introduces a new function to set up these event listeners and implements a handler for the reset button. + This PR introduces new environment variables and improves our database initialization and migration process: - **Details of Changes:** - 1. **src/app.js:** - - Added a new function `setupEventListeners` to attach click event listeners to the submit and reset buttons. - - Implemented the `handleReset` function to reset the form and log the reset action. - - Included a TODO comment to add other listeners, referencing issue [#123](https://github.com/user/project/issue/123). + - Add new environment variables: + 1. `RUN_AUTOMIGRATION`: to control auto-migration + 2. `DEFAULT_DATA_CONFIG_DIR`: to specify the data configuration directory + - Implement conditional auto-migration support based on `RUN_AUTOMIGRATION` or function parameters + - Refactor database client initialization for better error handling and flexibility + - Streamline the migration process in the main application and various commands - **Impact:** - - **Backward Compatibility:** The changes are backward compatible. - - **Performance Implications:** Minimal performance impact due to the addition of event listeners. - - **New Dependencies:** No new dependencies introduced. + Key changes: + 1. Introduce `RUN_AUTOMIGRATION` and `DEFAULT_DATA_CONFIG_DIR` environment variables + 2. Add `applyMigrations` flag in database initialization + 3. Implement `GetDataConfigDir()` method to handle default and overridden config directories + 4. Refactor `InitDB()` to accept `automigrate` parameter + 5. Update `cmd/api/main.go`, `cmd/fixtures/fixtures.go`, and `pkg/advans/connect.go` to use new initialization process + 6. Simplify `cmd/migrator/migrator.go` to leverage the new auto-migration feature + 7. Improve error handling and logging throughout the affected files ''; in { From 55f370c9d1be04e6cb14cb8689d1346524f52ccf Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 3 Jul 2024 10:18:00 +0100 Subject: [PATCH 22/22] Update roles/home/aichat.nix --- roles/home/aichat.nix | 484 +----------------------------------------- 1 file changed, 3 insertions(+), 481 deletions(-) diff --git a/roles/home/aichat.nix b/roles/home/aichat.nix index 87e5591..be75802 100644 --- a/roles/home/aichat.nix +++ b/roles/home/aichat.nix @@ -203,487 +203,9 @@ roles = '' - name: createpr prompt: |- - You are an AI language model tasked with generating a comprehensive Pull Request (PR) description. Your goal is to create a clear and informative PR description that summarizes the changes and highlights any important details or considerations. - You are given a git diff and a list of commits - use this context to generate the PR message. - - # Requirements for the PR Description: - 1. **Title:** Provide a concise and descriptive title for the PR. - 2. **Summary:** Summarize the overall purpose and scope of the changes. - 3. **Details of Changes:** Describe the key changes made, referencing specific files or functions if necessary. - 4. **Impact:** Discuss any potential impact on the system, including backward compatibility, performance implications, and any new dependencies. - - ### INPUT: - - diff --git a/cmd/api/main.go b/cmd/api/main.go - index 8b974c8..9dfd24b 100644 - --- a/cmd/api/main.go - +++ b/cmd/api/main.go - @@ -33,6 +33,8 @@ func loadAppConfig() *AppConfig { - } - - func main() { - + applyMigrations := false - + cfg := config.New() - err := config.SetSecret([]string{ - "TEMPORAL_ADDRESS", - "PSQL", - @@ -42,13 +44,23 @@ func main() { - "REDASH_API_KEY", - "INFOBLOX_SECRET", - }) - + - if err != nil { - log.Printf("Could not set secrets: %v", err) - - os.Exit(1) - } - - - database.InitDB("Core") - + runMigrations, _ := cfg.Load(config.RunMigration.String()) - + if runMigrations != "" { - + applyMigrations = true - + } - + - + err = database.InitDB("Core", applyMigrations) - + - + if err != nil { - + log.Fatalf("Cannot initialize DB: %v", err) - + } - - appConfig := loadAppConfig() - - diff --git a/cmd/fixtures/fixtures.go b/cmd/fixtures/fixtures.go - index 3d23a6d..ff3290e 100644 - --- a/cmd/fixtures/fixtures.go - +++ b/cmd/fixtures/fixtures.go - @@ -10,13 +10,27 @@ import ( - - "github.com/go-faker/faker/v4" - "github.com/lib/pq" - + "github.pie.apple.com/kerosene/Core/pkg/config" - "github.pie.apple.com/kerosene/Core/pkg/database" - "github.pie.apple.com/kerosene/Core/structs" - ) - - // Initializing worker, database, producer and redis when the program starts. - func init() { - - database.InitDB("DatabaseManager", "W") - + applyMigrations := false - + cfg := config.New() - + - + runMigrations, _ := cfg.Load(config.RunMigration.String()) - + if runMigrations != "" { - + applyMigrations = true - + } - + - + err := database.InitDB("DatabaseManager", applyMigrations, "W") - + - + if err != nil { - + log.Fatalf("Cannot initialize DB: %s", err) - + } - + - rand.Seed(time.Now().UnixNano()) - } - - diff --git a/cmd/migrator/migrator.go b/cmd/migrator/migrator.go - index 3b9961a..278cc2b 100755 - --- a/cmd/migrator/migrator.go - +++ b/cmd/migrator/migrator.go - @@ -17,13 +17,12 @@ func main() { - automigrate := flag.Bool("auto", false, "Run auto-migration") - apply := flag.String("apply", "", "Apply a specific migration file") - deleteFlag := flag.Bool("delete", false, "Delete existing tables before migration") - - configDir := flag.String("configDir", "", "Optional directory for configuration files") - - flag.Parse() - - utils.LogStep("Connecting to the database...") - - - err := database.InitDB("Migrator") - + err := database.InitDB("Migrator", *automigrate) - if err != nil { - utils.LogFatal("Could not initialise DB: ", err) - } - @@ -40,16 +39,13 @@ func main() { - } - - switch { - - case *automigrate: - - if err := database.DBAutoMigration(database.Client, *configDir); err != nil { - - utils.LogFatal("Failed to run auto-migration", err) - - } - - - case *apply != "": - if err := database.ApplyMigration(database.Client, *apply); err != nil { - utils.LogFatal("Failed to apply migration", err) - } - - - + case *automigrate: - + // Just log a message as the migrations are handled by InitDB - + utils.LogInfo("Initialized DB with auto-migrations") - default: - flag.Usage() - os.Exit(1) - diff --git a/pkg/advans/connect.go b/pkg/advans/connect.go - index cbcfdb3..f65c59c 100644 - --- a/pkg/advans/connect.go - +++ b/pkg/advans/connect.go - @@ -4,6 +4,7 @@ import ( - "bytes" - "encoding/json" - "fmt" - + "log" - "net/http" - - "github.pie.apple.com/kerosene/Core/pkg/config" - @@ -28,7 +29,21 @@ type Payload struct { - var cfg = config.New() - - func init() { - - database.InitDB("IngestionPipeline", "W") - + applyMigrations := false - + - + runMigrations, _ := cfg.Load(config.RunMigration.String()) - + if runMigrations != "" { - + applyMigrations = true - + } - + - + err := database.InitDB("IngestionPipeline", applyMigrations, "W") - + - + if err != nil { - + log.Fatalf("Cannot initialize DB: %s", err) - + } - + - + // TODO check errors! - + // https://github.pie.apple.com/Kerosene/Core/issues/51 - config.SetSecret([]string{"ADVANS_MTLS_PRIVATE_KEY", "ADVANS_MTLS_CERT", "ADVANS_API_END_POINT"}) - } - - @@ -42,6 +57,7 @@ func initMTLSClient(certFilePath, keyFilePath string) (*http.Client, error) { - - func sendPayload(client *http.Client, advansEndpoint string, path string, payload Payload) error { - payloadBytes, err := json.Marshal(payload) - + - if err != nil { - return fmt.Errorf("error marshalling payload: %s", err) - } - @@ -63,88 +79,3 @@ func sendPayload(client *http.Client, advansEndpoint string, path string, payloa - - return nil - } - - diff --git a/pkg/config/main.go b/pkg/config/main.go - index ec14c10..e80c2c2 100644 - --- a/pkg/config/main.go - +++ b/pkg/config/main.go - @@ -16,6 +16,7 @@ import ( - var ( - errSecretNotFound = errors.New("secret not found") - errSecretDuplicateSource = errors.New("tried to retrieve secret from multiple sources") - + errDataConfigDirNotExists = errors.New("data config directory does not exist") - errSecretNotSet = errors.New("secret not set in any provider or as an environment variable") - errUnknownProvider = errors.New("unknown provider when retrieving secret") - errWhisperAuthDirNotSet = errors.New("whisper authentication file directory not specified") - @@ -28,8 +29,12 @@ var ( - errWhisperRetrieveContent = errors.New("could not retrieve whisper secret's content") - ) - - -type configProvider string - -type configKey string - +const defaultDataConfigDir = "Config/" - + - +type ( - + configProvider string - + configKey string - +) - - func (cg configKey) String() string { - return string(cg) - @@ -40,17 +45,18 @@ func (cp configProvider) String() string { - } - - const ( - - whisperProvider configProvider = "WHISPER" - - PSQL configKey = "PSQL" - - PSQLRead configKey = "PSQL_READ" - - TemporalAddress configKey = "TEMPORAL_ADDRESS" - - KafkaBrokers configKey = "KAFKA_BROKERS" - - RedisURI configKey = "REDIS" - - KeroseneEnvironment configKey = "ENVIRONMENT" - - ElasticSearchURI configKey = "ELASTICSEARCH_URL" - - Proxy configKey = "PROXY" - - Queue configKey = "QUEUE" - - RunMigration configKey = "RUN_AUTOMIGRATION" - + whisperProvider configProvider = "WHISPER" - + PSQL configKey = "PSQL" - + PSQLRead configKey = "PSQL_READ" - + TemporalAddress configKey = "TEMPORAL_ADDRESS" - + KafkaBrokers configKey = "KAFKA_BROKERS" - + RedisURI configKey = "REDIS" - + KeroseneEnvironment configKey = "ENVIRONMENT" - + ElasticSearchURI configKey = "ELASTICSEARCH_URL" - + Proxy configKey = "PROXY" - + Queue configKey = "QUEUE" - + RunMigration configKey = "RUN_AUTOMIGRATION" - + DefaultDataConfigDir configKey = "DEFAULT_DATA_CONFIG_DIR" - ) - - var providers = []configProvider{ - @@ -353,3 +359,23 @@ func (c *Config) Load(name string) (string, error) { - - return val, nil - } - + - +func (c *Config) GetDataConfigDir() (string, error) { - + retDir := defaultDataConfigDir - + - + overriddenConfigDir, _ := c.Load(DefaultDataConfigDir.String()) - + if overriddenConfigDir != "" { - + retDir = overriddenConfigDir - + } - + - + // check appended / - + if len(retDir) > 0 && retDir[len(retDir)-1] != '/' { - + retDir += "/" - + } - + - + if _, err := os.Stat(retDir); os.IsNotExist(err) { - + return "", errDataConfigDirNotExists - + } - + - + return retDir, nil - +} - diff --git a/pkg/database/client.go b/pkg/database/client.go - index 6fc4861..444bb5a 100644 - --- a/pkg/database/client.go - +++ b/pkg/database/client.go - @@ -19,17 +19,27 @@ import ( - "gorm.io/plugin/dbresolver" - ) - - -var Client *gorm.DB - -var ErrNilDatabaseClient = errors.New("database client is nil after setup") - +var ( - + Client *gorm.DB - + errNilDatabaseClient = errors.New("database client is nil after setup") - +) - + - +func determineApplyMigration(cfg *config.Config, automigrate bool) bool { - + overrideAutomigrate, _ := cfg.Load(config.RunMigration.String()) - + - + // the env var takes precedence! - + return overrideAutomigrate != "" || automigrate - +} - - // InitDB initializes the database with the given application name and optional dbpath for SQLite. - -func InitDB(appName string, dbpath ...string) error { - +func InitDB(appName string, automigrate bool, dbpath ...string) error { - var ( - psqlReadReplica string - err error - ) - - cfg := config.New() - + applyMigration := determineApplyMigration(&cfg, automigrate) - - // Set up a new logger with your required configuration. - newLogger := logger.New( - @@ -87,12 +97,12 @@ func InitDB(appName string, dbpath ...string) error { - if Client == nil { - log.Println("database client is nil after setup, aborting") - - - return ErrNilDatabaseClient - + return errNilDatabaseClient - } - - // Run auto-migration if using SQLite - - if isSQLiteDB(Client) { - - if err := DBAutoMigration(Client, ""); err != nil { - + if applyMigration && isSQLiteDB(Client) { - + if err := DBAutoMigration(Client); err != nil { - log.Printf("failed to run SQLite auto-migration: %v", err) - - return err - @@ -105,6 +115,7 @@ func InitDB(appName string, dbpath ...string) error { - // setupPostgres sets up a PostgreSQL database connection. - func setupPostgres(newLogger logger.Interface, appName, dbURI string) (*gorm.DB, error) { - dbURI = appendApplicationName(dbURI, appName) - + - return gorm.Open(postgres.Open(dbURI), &gorm.Config{ - Logger: newLogger, - }) - @@ -132,19 +143,19 @@ func setupPostgresWithReplicas(newLogger logger.Interface, appName, sourceURI, r - - // setupSQLite sets up a SQLite database connection. - func setupSQLite(newLogger logger.Interface, dbpath ...string) (*gorm.DB, error) { - - var sqliteFile string - + sqliteFile := "file::memory:?cache=shared" - + - if len(dbpath) > 0 { - sqliteFile = dbpath[0] - + - // Ensure the SQLite file ends with .db - if filepath.Ext(sqliteFile) != ".db" { - return nil, errors.New("SQLite file must have a .db extension") - } - - } else { - - // Default is to use an in-memory db - - sqliteFile = "file::memory:?cache=shared" - } - - log.Printf("Using SQLite: %s", sqliteFile) - + - return gorm.Open(sqlite.Open(sqliteFile), &gorm.Config{ - Logger: newLogger, - }) - diff --git a/pkg/database/migrations.go b/pkg/database/migrations.go - index 6582b99..3210216 100644 - --- a/pkg/database/migrations.go - +++ b/pkg/database/migrations.go - @@ -27,6 +27,7 @@ func ApplyMigration(dbClient *gorm.DB, filename string) error { - } - - utils.LogSuccess("Migration applied successfully.") - + - return nil - } - - @@ -47,22 +48,26 @@ func GeneratePassword() (string, error) { - return cfg.Load("REDASH_PASSWORD") - } - - -func DBAutoMigration(dbClient *gorm.DB, configDir string) error { - +func DBAutoMigration(dbClient *gorm.DB) error { - utils.LogStep("Running auto-migration...") - - dbDialect := dbClient.Dialector.Name() - + - if dbDialect == "postgres" { - if err := PSQLStart(); err != nil { - return fmt.Errorf("failed to initialize database: %v", err) - } - + - utils.LogSuccess("Database initialization completed successfully.") - utils.LogStep("Generating Redash password...") - + - password, err := GeneratePassword() - if err != nil { - return fmt.Errorf("failed to generate password: %v", err) - } - - utils.LogStep("Creating Redash user...") - + - if err := CreateUserRedash(password); err != nil { - utils.LogWarning("Failed to create Redash user", err) - } else { - @@ -72,11 +77,7 @@ func DBAutoMigration(dbClient *gorm.DB, configDir string) error { - ReflectionMigration() - } - - - if configDir != "" { - - initialise.GenerateInitData(dbClient, configDir) - - } else { - - initialise.GenerateInitData(dbClient) - - } - + initialise.GenerateInitData(dbClient) - - return nil - } - @@ -91,12 +92,15 @@ func RunAutoMigration() error { - dbTablesValue := reflect.ValueOf(structs.DatabaseTables) - for i := 0; i < dbTablesValue.NumField(); i++ { - field := dbTablesValue.Field(i) - + - if field.Kind() == reflect.Ptr && !field.IsNil() { - structValue := field.Elem() - + - if err := Client.AutoMigrate(structValue.Addr().Interface()); err != nil { - return fmt.Errorf("failed to auto-migrate model %v: %v", structValue.Type().Name(), err) - } - } - } - + - return nil - } - diff --git a/pkg/initialise/configInit.go b/pkg/initialise/configInit.go - index d087531..323a3d7 100644 - --- a/pkg/initialise/configInit.go - +++ b/pkg/initialise/configInit.go - @@ -9,6 +9,7 @@ import ( - "reflect" - "strings" - - + "github.pie.apple.com/kerosene/Core/pkg/config" - "github.pie.apple.com/kerosene/Core/pkg/utils" - "github.pie.apple.com/kerosene/Core/structs" - "gopkg.in/yaml.v2" - @@ -16,30 +17,28 @@ import ( - "gorm.io/gorm" - ) - - -//go:embed config - -var configFiles embed.FS - +var ( - + //go:embed config - + configFiles embed.FS - + cfg config.Config = config.New() - +) - - func GenerateInitData(database *gorm.DB, additionalConfigDir ...string) { - utils.LogHeader("INITIALISING DEFAULT DATA") - - - configDir := "config" - - if len(additionalConfigDir) > 0 { - - configDir = additionalConfigDir[0] - - - - utils.LogInfo(fmt.Sprintf("Using additional config directory: %s", configDir)) - + configDir, err := cfg.GetDataConfigDir() - - - if _, err := os.Stat(configDir); os.IsNotExist(err) { - - utils.LogWarning(fmt.Sprintf("Config directory does not exist: %s", configDir), err) - - } - - } else { - - utils.LogInfo("Using Default Config") - + if err != nil { - + utils.LogFatal("Cannot open config directory: %w", err) - } - - + utils.LogInfo("Using data config directory: " + configDir) - + - // Get the list of directories in the embedded config directory - - embeddedConfigDirs := getConfigDirs("config") - + embeddedConfigDirs := getConfigDirs(configDir) - - // Process the embedded configs - - processConfigs(database, embeddedConfigDirs, "config/") - + processConfigs(database, embeddedConfigDirs, configDir) - - // If an additional config directory is provided, process it after the embedded configs - if len(additionalConfigDir) > 0 { - @@ -47,7 +46,7 @@ func GenerateInitData(database *gorm.DB, additionalConfigDir ...string) { - - utils.LogHeader("ADDITIONAL DATA") - - - processConfigs(database, additionalConfigDirs, configDir+"/") - + processConfigs(database, additionalConfigDirs, configDir) - } - - utils.LogInfo(fmt.Sprintf("Initialised Default Data for environment '%s'.", os.Getenv("ENVIRONMENT"))) - @@ -113,9 +112,11 @@ func insertPrioritizedStruct(db *gorm.DB, configDirs []string, configPath, struc - } - - func getConfigDirs(path string) []string { - - var configDirs []string - - var entries []os.DirEntry - - var err error - + var ( - + configDirs []string - + entries []os.DirEntry - + err error - + ) - - // Check if the path is the default embedded directory or an external path - if path == "config" { + Create a concise and informative PR message for a given code diff using the Conventional Commits format. + Include all significant changes, such as new environment variables, refactored functions, and added or removed TODOs. + Mention specific issue numbers for better trackability. ### OUTPUT: