Files
Do Siki f918e300a6 feat(plane): add Plane-TODO sync script
Add plane-sync.js one-way (Plane -> TODO.md) synchronization for the
MITHOME project. Config reads from .mcp.json with .env override. CLI:
--list, --dry-run, --yes, --project, --verbose, --help. Interactive
discrepancy resolution (status mismatches, orphans, new issues), backup
before write, rate limiting. Pure functions covered by node:test unit
tests. Includes PLANE-SYNC-GUIDE.md and TODO.md changelog entry.
2026-08-17 12:18:55 +02:00

54 lines
1.9 KiB
JavaScript

const fs = require('fs');
const path = require('path');
// WHY: .mcp.json is gitignored but already holds the Plane credentials for the MCP
// server, so reusing it keeps the API key in a single place instead of duplicating it.
const MCP_PATH = path.join(__dirname, '..', '..', '.mcp.json');
const DEFAULT_PROJECT_ID = '643f7055-1237-4912-912f-99ec49fd0f0e';
const DEFAULT_PROJECT_IDENTIFIER = 'MITHOME';
function loadDotEnv() {
try {
const envPath = path.join(__dirname, '..', '..', '.env');
if (fs.existsSync(envPath)) {
const lines = fs.readFileSync(envPath, 'utf8').split('\n');
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const idx = trimmed.indexOf('=');
if (idx > 0) process.env[trimmed.slice(0, idx).trim()] = trimmed.slice(idx + 1).trim();
}
}
} catch (error) {
console.warn('⚠️ .env load error:', error.message);
}
}
function loadMcpConfig() {
try {
if (fs.existsSync(MCP_PATH)) {
const mcp = JSON.parse(fs.readFileSync(MCP_PATH, 'utf8'));
const plane = mcp.mcpServers && mcp.mcpServers.plane;
return plane && plane.env ? plane.env : {};
}
} catch (error) {
console.warn('⚠️ .mcp.json parse error:', error.message);
}
return {};
}
// DECISION: env vars override .mcp.json so CI/CD can supply its own credentials.
function getConfig() {
const mcp = loadMcpConfig();
return {
apiKey: process.env.PLANE_API_KEY || mcp.PLANE_API_KEY,
host: (process.env.PLANE_API_HOST_URL || mcp.PLANE_API_HOST_URL || 'https://pm.llmdev.mozdit.hu/').replace(/\/+$/, ''),
workspace: process.env.PLANE_WORKSPACE_SLUG || mcp.PLANE_WORKSPACE_SLUG,
projectId: process.env.PLANE_PROJECT_ID || DEFAULT_PROJECT_ID,
projectIdentifier: process.env.PLANE_PROJECT_IDENTIFIER || DEFAULT_PROJECT_IDENTIFIER
};
}
module.exports = { getConfig, loadDotEnv };