-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
97 lines (79 loc) · 3.44 KB
/
index.js
File metadata and controls
97 lines (79 loc) · 3.44 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
const core = require('@actions/core');
const { getDbAdapter } = require('./src/db');
const { scanRepository } = require('./src/scanners');
async function run() {
try {
// Отримуємо налаштування з GitHub Actions
const mode = core.getInput('mode') || 'full';
const dbType = core.getInput('db_type') || 'chromadb';
let version = "unknown";
try {
const fs = require('fs');
const path = require('path');
const packageJsonPath = path.resolve(__dirname, './package.json');
if (fs.existsSync(packageJsonPath)) {
const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
version = packageData.version || "unknown";
}
} catch (versionError) {
console.error('Error getting version:', versionError.message);
}
console.log(`Vector code map generator v${version}`);
// Отримання шляху до репозиторію
const repoPath = process.env.GITHUB_WORKSPACE || '.';
// OpenAI налаштування
const openaiApiKey = core.getInput('openai_api_key', { required: true });
const openaiModel = core.getInput('openai_model') || 'text-embedding-3-small';
// Налаштування для фільтрації файлів
const fileExtensions = (core.getInput('file_extensions') || '.js,.ts,.jsx,.tsx,.html,.css,.md,.txt').split(',');
const excludePatterns = (core.getInput('exclude_patterns') || 'node_modules/**,dist/**,.git/**').split(',');
const MAX_TOKENS_PER_BATCH = core.getInput('max_tokens_per_batch') || 250000;
// Підключаємося до векторної бази даних
let dbAdapter;
const { execSync } = require('child_process');
try {
execSync('git config --global --add safe.directory '+repoPath);
console.log('Added '+repoPath+' as safe directory');
} catch (error) {
console.error('Failed to configure safe directory:', error.message);
}
if (dbType === 'chromadb') {
const chromaHost = core.getInput('chroma_host', { required: true });
const chromaPort = core.getInput('chroma_port') || '8000';
const chromaCollection = core.getInput('chroma_collection', { required: true });
// Налаштування авторизації для ChromaDB
const authEnabled = core.getInput('chroma_auth_enabled') === 'true';
const authConfig = {};
if (authEnabled) {
authConfig.enabled = true;
authConfig.type = core.getInput('chroma_auth_type') || 'basic';
authConfig.credentials = core.getInput('chroma_auth_credentials');
authConfig.ssl = core.getInput('chroma_ssl_enabled') === 'true';
}
dbAdapter = await getDbAdapter('chromadb', {
host: chromaHost,
port: chromaPort,
collection: chromaCollection,
auth: authConfig
});
} else {
throw new Error(`Unsupported database type: ${dbType}`);
}
// Встановлюємо OpenAI API ключ 1
process.env.OPENAI_API_KEY = openaiApiKey;
process.env.MAX_TOKENS_PER_BATCH = MAX_TOKENS_PER_BATCH;
// Запускаємо сканування репозиторію
await scanRepository({
repoPath,
dbAdapter,
mode,
fileExtensions,
excludePatterns,
openaiModel
});
core.info(`Vector code map generation completed in ${mode} mode`);
} catch (error) {
core.setFailed(error.message);
}
}
run();