Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sourabratabose
Copy link

@sourabratabose sourabratabose commented Apr 24, 2025

…back to org level configuration as fetched

Description

I have updated the fetchValue() function body to fetch both the organization level and repo level configurations which are then merged and returned on call. Repo level configurations as found will be considered as final over organization level configurations.

Related Issue

#422

Motivation and Context

As of right now, the org fallback only works if you have no site config. We should inherit on a row basis so that if a site has a single property (aem.assets.link.type) the rest still falls back to org so you don't have to duplicate your repoId, etc.

To solve this as mention in issue #422.

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [ x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x ] I have signed the Adobe Open Source CLA.
  • [x ] My code follows the code style of this project.
  • [x ] My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Comment on lines 40 to 60
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data was an array previously, and is now an object which means that the data.find will fail on line 60. Now that it's an object, you can just do a lookup

Suggested change
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];

Copy link
Author

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.


// Determine if images should be links
const injectLink = (await getConfKey(owner, repo, 'aem.assets.image.type')) === 'link';
const injectLink =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change and below don't need to be refactored

@sourabratabose
Copy link
Author

sourabratabose commented Apr 26, 2025

Hi @chrischrischris , I didn't really understand as to why the path variable is required to be passed anyways.

Since configuration merge is fetched from an exhaustive list of paths. I decided to check whether paths are matching with the expected org and repo level paths, fetch the configurations and merge as required.

All other fetchValue() calls which dont match that path patterns will still fall through and return the value fetched as expected in the original function body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants