Skip to content

Commit 8b845ac

Browse files
committed
Refactor subdirectory validation logic to clarify repository structure checks and improve error handling for missing metadata and logo files
1 parent 9a365e3 commit 8b845ac

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

scripts/validate-pull-request.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ async function main() {
662662
await validateDirectoryFiles(dir, directMetadataFile, directLogoPath);
663663
} else {
664664
// This directory doesn't contain metadata.json directly
665-
// Check if it contains subdirectories with metadata.json
666-
console.log(` - 🔍 Checking for app subdirectories...`);
665+
// Check if it contains subdirectories with metadata.json (repositories/owner/repo/app structure)
666+
console.log(` - 🔍 Checking for repository subdirectories...`);
667667

668668
const subdirs = fs.readdirSync(dir, { withFileTypes: true })
669669
.filter(dirent => dirent.isDirectory())
@@ -676,17 +676,51 @@ async function main() {
676676
const subdirLogoPath = path.join(subdirPath, 'logo.png');
677677

678678
if (fs.existsSync(subdirMetadataFile)) {
679+
// Direct metadata.json in repo directory
679680
foundApps = true;
680-
console.log(` - 📁 App subdirectory: \`${subdir}\``);
681+
console.log(` - 📁 Repository: \`${subdir}\``);
681682
await validateDirectoryFiles(subdirPath, subdirMetadataFile, subdirLogoPath);
683+
} else {
684+
// Check for app subdirectories within this repo directory
685+
console.log(` - 📁 Repository: \`${subdir}\``);
686+
console.log(` - 🔍 Checking for app subdirectories...`);
687+
688+
try {
689+
const appSubdirs = fs.readdirSync(subdirPath, { withFileTypes: true })
690+
.filter(dirent => dirent.isDirectory())
691+
.map(dirent => dirent.name);
692+
693+
let foundAppsInRepo = false;
694+
for (const appSubdir of appSubdirs) {
695+
const appSubdirPath = path.join(subdirPath, appSubdir);
696+
const appMetadataFile = path.join(appSubdirPath, 'metadata.json');
697+
const appLogoPath = path.join(appSubdirPath, 'logo.png');
698+
699+
if (fs.existsSync(appMetadataFile)) {
700+
foundApps = true;
701+
foundAppsInRepo = true;
702+
console.log(` - 📁 App subdirectory: \`${appSubdir}\``);
703+
await validateDirectoryFiles(appSubdirPath, appMetadataFile, appLogoPath);
704+
}
705+
}
706+
707+
if (!foundAppsInRepo) {
708+
console.log(` - 📄 \`metadata.json\``);
709+
console.log(` - ❌ File not found in any app subdirectories`);
710+
console.log(` - 📄 \`logo.png\``);
711+
console.log(` - ❌ File not found in any app subdirectories`);
712+
}
713+
} catch (error) {
714+
console.log(` - ❌ Error reading repository directory: ${error.message}`);
715+
}
682716
}
683717
}
684718

685719
if (!foundApps) {
686720
console.log(` - 📄 \`metadata.json\``);
687-
console.log(` - ❌ File not found`);
721+
console.log(` - ❌ File not found in any subdirectories`);
688722
console.log(` - 📄 \`logo.png\``);
689-
console.log(` - ❌ File not found`);
723+
console.log(` - ❌ File not found in any subdirectories`);
690724
}
691725
}
692726

0 commit comments

Comments
 (0)