Update check_files.yml #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... (previous code remains same until script section) | ||
script: | | ||
// ... (previous functions remain same) | ||
for (const dir of dirs) { | ||
const fileCount = countFiles(dir); | ||
console.log(`Checking ${dir}: ${fileCount} files found`); | ||
if (fileCount >= 5) { | ||
const dayNumber = dir.match(/\d+/)[0]; | ||
try { | ||
// First, let's list all labels in the repository to debug | ||
console.log(`Getting all labels in the repository...`); | ||
const allLabels = await github.rest.issues.listLabelsForRepo({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
console.log('Available labels:', allLabels.data.map(l => l.name)); | ||
// Now search for issues | ||
console.log(`Searching for issues with Day-${dayNumber}`); | ||
const issues = await github.rest.issues.listForRepo({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
state: 'open' | ||
}); | ||
// Filter issues that have matching labels | ||
const matchingIssues = issues.data.filter(issue => { | ||
const issueLabels = issue.labels.map(label => label.name); | ||
console.log(`Issue #${issue.number} has labels:`, issueLabels); | ||
return issueLabels.some(label => | ||
label === `Day-${dayNumber}` || | ||
label === `Day ${dayNumber}` || | ||
label.toLowerCase() === `day-${dayNumber}`.toLowerCase() || | ||
label.toLowerCase() === `day ${dayNumber}`.toLowerCase() | ||
); | ||
}); | ||
console.log(`Found ${matchingIssues.length} matching issues`); | ||
for (const issue of matchingIssues) { | ||
console.log(`Closing issue #${issue.number}`); | ||
await github.rest.issues.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue.number, | ||
state: 'closed', | ||
state_reason: 'completed' | ||
}); | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue.number, | ||
body: `This issue has been automatically closed as ${fileCount} files have been uploaded to the ${dir} folder.` | ||
}); | ||
} | ||
} catch (error) { | ||
console.error(`Error processing ${dir}:`, error); | ||
console.error('Full error:', JSON.stringify(error, null, 2)); | ||
} | ||
} | ||
} |