Skip to content

Commit

Permalink
Merge branch 'main' into remove-get-push-links-call
Browse files Browse the repository at this point in the history
  • Loading branch information
Prithpal-Sooriya authored Feb 18, 2025
2 parents 8fda7f5 + 48b1b68 commit b1e904c
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ module.exports = defineConfig({
if (isChildWorkspace) {
// All non-root packages must have a valid README.md file.
await expectReadme(workspace, workspaceBasename);

await expectCodeowner(workspace, workspaceBasename);
}
}

Expand Down Expand Up @@ -835,3 +837,62 @@ async function expectReadme(workspace, workspaceBasename) {
);
}
}

// A promise resolving to the codeowners file contents
let cachedCodeownersFile;

/**
* Expect that the workspace has a codeowner set, and that the CHANGELOG.md and
* package.json files are co-owned with the wallet framework team.
*
* @param {Workspace} workspace - The workspace to check.
* @param {string} workspaceBasename - The name of the workspace.
* @returns {Promise<void>}
*/
async function expectCodeowner(workspace, workspaceBasename) {
if (!cachedCodeownersFile) {
cachedCodeownersFile = readFile(
resolve(__dirname, '.github', 'CODEOWNERS'),
'utf8',
);
}
const codeownersFile = await cachedCodeownersFile;
const codeownerRules = codeownersFile.split('\n');

const packageCodeownerRule = codeownerRules.find((rule) =>
// Matcher includes intentional trailing space to ensure there is a package-wide rule, not
// just a rule for specific files/directories in the package.
rule.startsWith(`/packages/${workspaceBasename} `),
);

if (!packageCodeownerRule) {
workspace.error('Missing CODEOWNER rule for package');
return;
}

if (!packageCodeownerRule.includes('@MetaMask/wallet-framework-engineers')) {
if (
!codeownerRules.some(
(rule) =>
rule.startsWith(`/packages/${workspaceBasename}/CHANGELOG.md`) &&
rule.includes('@MetaMask/wallet-framework-engineers'),
)
) {
workspace.error(
'Missing CODEOWNER rule for CHANGELOG.md co-ownership with wallet framework team',
);
}

if (
!codeownerRules.some(
(rule) =>
rule.startsWith(`/packages/${workspaceBasename}/package.json`) &&
rule.includes('@MetaMask/wallet-framework-engineers'),
)
) {
workspace.error(
'Missing CODEOWNER rule for package.json co-ownership with wallet framework team',
);
}
}
}

0 comments on commit b1e904c

Please sign in to comment.