-
Notifications
You must be signed in to change notification settings - Fork 58
Updated fetchValue() function to handle repo level configuration fall… #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,10 +8,15 @@ const { loadStyle } = await import(`${getNx()}/scripts/nexter.js`); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { loadIms, handleSignIn } = await import(`${getNx()}/utils/ims.js`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const loadScript = (await import(`${getNx()}/utils/script.js`)).default; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ASSET_SELECTOR_URL = 'https://experience.adobe.com/solutions/CQ-assets-selectors/assets/resources/assets-selectors.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ASSET_SELECTOR_URL = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'https://experience.adobe.com/solutions/CQ-assets-selectors/assets/resources/assets-selectors.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const CONFS = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function getMergedConf(owner, repo) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return mergedConf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function fetchConf(path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (CONFS[path]) return CONFS[path]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const resp = await daFetch(`${DA_ORIGIN}/config${path}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -27,7 +32,29 @@ async function fetchConf(path) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function fetchValue(path, key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (CONFS[path]?.[key]) return CONFS[path][key]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sourabratabose marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await fetchConf(path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [repoConf, orgConf] = await Promise.all([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetchConf(`/${owner}/${repo}/`), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetchConf(`/${owner}/`), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Start with organization-level config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (orgConf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| orgConf.forEach((item) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data[item.key] = item.value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Override with repository-level config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (repoConf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data === null) data = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repoConf.forEach((item) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data[item.key] = item.value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!data) return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const confKey = data.find((conf) => conf.key === key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = null; | |
| // Start with organization-level config | |
| if (orgConf) { | |
| data = {}; | |
| orgConf.forEach((item) => { | |
| data[item.key] = item.value; | |
| }); | |
| } | |
| // Override with repository-level config | |
| if (repoConf) { | |
| if (data === null) data = {}; | |
| repoConf.forEach((item) => { | |
| data[item.key] = item.value; | |
| }); | |
| } | |
| if (!data) return null; | |
| const confKey = data.find((conf) => conf.key === key); | |
| const data = {}; | |
| // Start with organization-level config | |
| orgConf?.forEach((item) => { | |
| data[item.key] = item.value; | |
| }); | |
| // Override with repository-level config | |
| repoConf?.forEach((item) => { | |
| data[item.key] = item.value; | |
| }); | |
| return data[key]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will be updating the PR to treat data as an array to retain the expected data type of data variable. Pushing objects to an array and updating values inside them if the keys match afterwards, is my approach.
Uh oh!
There was an error while loading. Please reload this page.