Skip to content

Update and rename Indhu.py to Indhu_Subash.py #287

Update and rename Indhu.py to Indhu_Subash.py

Update and rename Indhu.py to Indhu_Subash.py #287

Workflow file for this run

name: Auto Close Issue on File Upload
on:
push:
branches:
- main
pull_request:
types: [closed]
issues:
types: [reopened]
jobs:
check-and-close:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check folder contents and close issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
function countFiles(dirPath) {
try {
const files = fs.readdirSync(dirPath);
return files.filter(file => fs.statSync(path.join(dirPath, file)).isFile()).length;
} catch (error) {
return 0;
}
}
const dirs = fs.readdirSync('.').filter(dir => /^Day[ -]?\d+$/.test(dir));
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 {
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));
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'
});
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));
}
}
}