@@ -247,6 +247,8 @@ module.exports = defineConfig({
247247 if ( isChildWorkspace ) {
248248 // All non-root packages must have a valid README.md file.
249249 await expectReadme ( workspace , workspaceBasename ) ;
250+
251+ await expectCodeowner ( workspace , workspaceBasename ) ;
250252 }
251253 }
252254
@@ -835,3 +837,62 @@ async function expectReadme(workspace, workspaceBasename) {
835837 ) ;
836838 }
837839}
840+
841+ // A promise resolving to the codeowners file contents
842+ let cachedCodeownersFile ;
843+
844+ /**
845+ * Expect that the workspace has a codeowner set, and that the CHANGELOG.md and
846+ * package.json files are co-owned with the wallet framework team.
847+ *
848+ * @param {Workspace } workspace - The workspace to check.
849+ * @param {string } workspaceBasename - The name of the workspace.
850+ * @returns {Promise<void> }
851+ */
852+ async function expectCodeowner ( workspace , workspaceBasename ) {
853+ if ( ! cachedCodeownersFile ) {
854+ cachedCodeownersFile = readFile (
855+ resolve ( __dirname , '.github' , 'CODEOWNERS' ) ,
856+ 'utf8' ,
857+ ) ;
858+ }
859+ const codeownersFile = await cachedCodeownersFile ;
860+ const codeownerRules = codeownersFile . split ( '\n' ) ;
861+
862+ const packageCodeownerRule = codeownerRules . find ( ( rule ) =>
863+ // Matcher includes intentional trailing space to ensure there is a package-wide rule, not
864+ // just a rule for specific files/directories in the package.
865+ rule . startsWith ( `/packages/${ workspaceBasename } ` ) ,
866+ ) ;
867+
868+ if ( ! packageCodeownerRule ) {
869+ workspace . error ( 'Missing CODEOWNER rule for package' ) ;
870+ return ;
871+ }
872+
873+ if ( ! packageCodeownerRule . includes ( '@MetaMask/wallet-framework-engineers' ) ) {
874+ if (
875+ ! codeownerRules . some (
876+ ( rule ) =>
877+ rule . startsWith ( `/packages/${ workspaceBasename } /CHANGELOG.md` ) &&
878+ rule . includes ( '@MetaMask/wallet-framework-engineers' ) ,
879+ )
880+ ) {
881+ workspace . error (
882+ 'Missing CODEOWNER rule for CHANGELOG.md co-ownership with wallet framework team' ,
883+ ) ;
884+ }
885+
886+ if (
887+ ! codeownerRules . some (
888+ ( rule ) =>
889+ rule . startsWith ( `/packages/${ workspaceBasename } /package.json` ) &&
890+ rule . includes ( '@MetaMask/wallet-framework-engineers' ) ,
891+ )
892+ ) {
893+ workspace . error (
894+ 'Missing CODEOWNER rule for package.json co-ownership with wallet framework team' ,
895+ ) ;
896+ }
897+ }
898+ }
0 commit comments