remcode
Version:
Turn your AI assistant into a codebase expert. Intelligent code analysis, semantic search, and software engineering guidance through MCP integration.
266 lines (265 loc) • 11.2 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkflowGenerator = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const logger_1 = require("../utils/logger");
const templates_1 = require("./templates");
const logger = (0, logger_1.getLogger)('WorkflowGenerator');
/**
* Class for generating GitHub Actions workflows
*/
class WorkflowGenerator {
/**
* Constructor
* @param repoPath Path to the repository
*/
constructor(repoPath = process.cwd()) {
this.templates = new templates_1.WorkflowTemplates();
this.repoPath = repoPath;
}
/**
* Generate a standard Remcode workflow for code analysis and vectorization
* @param repoName Repository name
* @param options Additional workflow options
* @returns Workflow generation result
*/
async generateRemcodeWorkflow(repoName, options = {}) {
logger.info(`Generating Remcode workflow for repository: ${repoName}`);
try {
const templateOptions = {
repoName,
...options
};
const workflowContent = this.templates.getWorkflowTemplate(templates_1.WorkflowType.REMCODE_BASIC, templateOptions);
const workflowPath = path.join(this.repoPath, '.github', 'workflows', 'remcode.yml');
await this.ensureWorkflowDirectory();
fs.writeFileSync(workflowPath, workflowContent, 'utf8');
logger.info(`Workflow generated at: ${workflowPath}`);
return {
success: true,
filePath: workflowPath,
workflowContent
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error(`Failed to generate Remcode workflow: ${errorMessage}`);
return {
success: false,
error: errorMessage
};
}
}
/**
* Generate a scheduled Remcode workflow for periodic processing
* @param repoName Repository name
* @param schedule Schedule configuration (cron expression)
* @param options Additional workflow options
* @returns Workflow generation result
*/
async generateScheduledWorkflow(repoName, schedule = '0 0 * * 0', // Weekly on Sunday
options = {}) {
logger.info(`Generating scheduled Remcode workflow for ${repoName} with schedule: ${schedule}`);
try {
const templateOptions = {
repoName,
schedule: {
enabled: true,
cron: schedule,
branches: ['main']
},
...options
};
const workflowContent = this.templates.getWorkflowTemplate(templates_1.WorkflowType.REMCODE_SCHEDULED, templateOptions);
const workflowPath = path.join(this.repoPath, '.github', 'workflows', 'remcode-scheduled.yml');
await this.ensureWorkflowDirectory();
fs.writeFileSync(workflowPath, workflowContent, 'utf8');
logger.info(`Scheduled workflow generated at: ${workflowPath}`);
return {
success: true,
filePath: workflowPath,
workflowContent
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error(`Failed to generate scheduled workflow: ${errorMessage}`);
return {
success: false,
error: errorMessage
};
}
}
/**
* Generate an advanced Remcode workflow with detailed steps
* @param repoName Repository name
* @param options Additional workflow options
* @returns Workflow generation result
*/
async generateAdvancedWorkflow(repoName, options = {}) {
logger.info(`Generating advanced Remcode workflow for repository: ${repoName}`);
try {
const templateOptions = {
repoName,
...options
};
const workflowContent = this.templates.getWorkflowTemplate(templates_1.WorkflowType.REMCODE_ADVANCED, templateOptions);
const workflowPath = path.join(this.repoPath, '.github', 'workflows', 'remcode-advanced.yml');
await this.ensureWorkflowDirectory();
fs.writeFileSync(workflowPath, workflowContent, 'utf8');
logger.info(`Advanced workflow generated at: ${workflowPath}`);
return {
success: true,
filePath: workflowPath,
workflowContent
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error(`Failed to generate advanced workflow: ${errorMessage}`);
return {
success: false,
error: errorMessage
};
}
}
/**
* Generate a custom workflow with specified options
* @param name Workflow name (filename without extension)
* @param type Workflow template type
* @param options Template options
* @returns Workflow generation result
*/
async generateCustomWorkflow(name, type = templates_1.WorkflowType.CUSTOM, options) {
logger.info(`Generating custom workflow: ${name} using template type: ${type}`);
try {
const workflowContent = this.templates.getWorkflowTemplate(type, options);
const workflowPath = path.join(this.repoPath, '.github', 'workflows', `${name}.yml`);
await this.ensureWorkflowDirectory();
fs.writeFileSync(workflowPath, workflowContent, 'utf8');
logger.info(`Custom workflow generated at: ${workflowPath}`);
return {
success: true,
filePath: workflowPath,
workflowContent
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error(`Failed to generate custom workflow: ${errorMessage}`);
return {
success: false,
error: errorMessage
};
}
}
/**
* Generate all common Remcode workflows
* @param repoName Repository name
* @param options Additional template options
* @returns Map of workflow names to generation results
*/
async generateAllWorkflows(repoName, options = {}) {
logger.info(`Generating all Remcode workflows for repository: ${repoName}`);
const results = new Map();
// Generate basic workflow
results.set('basic', await this.generateRemcodeWorkflow(repoName, options));
// Generate scheduled workflow
results.set('scheduled', await this.generateScheduledWorkflow(repoName, undefined, options));
// Generate advanced workflow
results.set('advanced', await this.generateAdvancedWorkflow(repoName, options));
// Generate workflow with cache
results.set('cached', await this.generateCustomWorkflow('remcode-cached', templates_1.WorkflowType.REMCODE_WITH_CACHE, { repoName, ...options }));
// Generate workflow with notifications
results.set('notifications', await this.generateCustomWorkflow('remcode-notifications', templates_1.WorkflowType.REMCODE_WITH_NOTIFICATIONS, { repoName, ...options }));
// Count successes
const successCount = [...results.values()].filter(r => r.success).length;
logger.info(`Generated ${successCount}/${results.size} workflows successfully`);
return results;
}
/**
* Update an existing workflow
* @param workflowPath Path to the workflow file
* @param type Workflow template type
* @param options Template options
* @returns Workflow generation result
*/
async updateWorkflow(workflowPath, type, options) {
logger.info(`Updating workflow at: ${workflowPath}`);
try {
if (!fs.existsSync(workflowPath)) {
throw new Error(`Workflow file not found: ${workflowPath}`);
}
const workflowContent = this.templates.getWorkflowTemplate(type, options);
fs.writeFileSync(workflowPath, workflowContent, 'utf8');
logger.info(`Workflow updated at: ${workflowPath}`);
return {
success: true,
filePath: workflowPath,
workflowContent
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error(`Failed to update workflow: ${errorMessage}`);
return {
success: false,
error: errorMessage
};
}
}
/**
* Ensure .github/workflows directory exists
* @returns Path to workflows directory
*/
async ensureWorkflowDirectory() {
const workflowDir = path.join(this.repoPath, '.github', 'workflows');
try {
if (!fs.existsSync(workflowDir)) {
fs.mkdirSync(workflowDir, { recursive: true });
logger.debug(`Created workflows directory: ${workflowDir}`);
}
return workflowDir;
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error(`Failed to create workflows directory: ${errorMessage}`);
throw new Error(`Failed to create workflows directory: ${errorMessage}`);
}
}
}
exports.WorkflowGenerator = WorkflowGenerator;
;