Repository navigation
Expand file tree
/
Copy pathscan-completion.cjs
More file actions
executable file
·130 lines (107 loc) · 3.47 KB
/
Copy pathscan-completion.cjs
File metadata and controls
executable file
·130 lines (107 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env node
/**
* Scan active projects for completion markers
*
* Checks each project in .github/projects/active/ for completion indicators:
* - Project README has "status: completed"
* - All associated issues are closed
* - All associated PRs are merged or closed
*
* Outputs: projects_json (JSON array of completed projects), has_completed (true|false)
*/
const fs = require('fs');
const path = require('path');
const ACTIVE_DIR = process.env.ACTIVE_PROJECTS_DIR || '.github/projects/active';
const PROJECT_FILTER = process.env.PROJECT_FILTER || '';
const completedProjects = [];
try {
if (!fs.existsSync(ACTIVE_DIR)) {
console.log(`ℹ️ Active projects directory not found: ${ACTIVE_DIR}`);
outputResults([], false);
process.exit(0);
}
const projectDirs = fs
.readdirSync(ACTIVE_DIR, { withFileTypes: true })
.filter((d) => d.isDirectory())
.map((d) => d.name);
if (projectDirs.length === 0) {
console.log('ℹ️ No active projects found');
outputResults([], false);
process.exit(0);
}
console.log(`Scanning ${projectDirs.length} active projects...`);
for (const projectName of projectDirs) {
// Filter by name if specified
if (PROJECT_FILTER && !projectName.includes(PROJECT_FILTER)) {
continue;
}
const projectPath = path.join(ACTIVE_DIR, projectName);
const readmePath = path.join(projectPath, 'PARENT_ISSUE.md');
// Check if project has a status indicator
if (!fs.existsSync(readmePath)) {
console.log(`⚠️ No PARENT_ISSUE.md found for project: ${projectName}`);
continue;
}
const content = fs.readFileSync(readmePath, 'utf8');
const isCompleted = checkProjectCompletion(projectName, content);
if (isCompleted) {
completedProjects.push({
name: projectName,
path: projectPath,
archivedAt: new Date().toISOString().split('T')[0],
});
console.log(`✅ Project marked for archival: ${projectName}`);
} else {
console.log(`➖ Project active: ${projectName}`);
}
}
if (completedProjects.length > 0) {
console.log(
`\n✅ Found ${completedProjects.length} completed project(s) ready for archival`,
);
} else {
console.log('\nℹ️ No completed projects found');
}
outputResults(completedProjects, completedProjects.length > 0);
} catch (err) {
console.error(`❌ Error scanning projects: ${err.message}`);
process.exit(1);
}
/**
* Check if project should be archived
* Returns true if project shows completion markers
*/
function checkProjectCompletion(projectName, content) {
// Check for explicit completion markers in content
const completionMarkers = [
/status:\s*completed/i,
/status:\s*"completed"/i,
/\[x\]\s+completed/i,
/\[x\]\s+project\s+complete/i,
];
for (const marker of completionMarkers) {
if (marker.test(content)) {
return true;
}
}
// Check for manual archival comment
if (content.includes('<!-- archival-ready -->')) {
return true;
}
return false;
}
/**
* Output GitHub Actions workflow outputs
*/
function outputResults(projects, hasCompleted) {
const projectsJson = JSON.stringify(projects);
const outputFile = process.env.GITHUB_OUTPUT;
if (!outputFile) {
console.log(`projects_json=${projectsJson}`);
console.log(`has_completed=${hasCompleted}`);
return;
}
let output = `projects_json=${projectsJson}\n`;
output += `has_completed=${hasCompleted}\n`;
fs.appendFileSync(outputFile, output, 'utf8');
}