95 lines
4.0 KiB
JavaScript
95 lines
4.0 KiB
JavaScript
const GitHubIntegrationService = require('./src/services/github-integration.service');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
async function testRepository() {
|
|
try {
|
|
console.log('🔍 Testing GitHub Repository Integration...');
|
|
|
|
const githubService = new GitHubIntegrationService();
|
|
const repositoryUrl = 'https://github.com/prakash6383206529/code-generator.git';
|
|
|
|
console.log(`📂 Testing repository: ${repositoryUrl}`);
|
|
|
|
// Parse the GitHub URL
|
|
const { owner, repo, branch } = githubService.parseGitHubUrl(repositoryUrl);
|
|
console.log(`📋 Parsed URL - Owner: ${owner}, Repo: ${repo}, Branch: ${branch || 'main'}`);
|
|
|
|
// Check if repository is public
|
|
try {
|
|
const unauthenticatedOctokit = new (require('@octokit/rest')).Octokit({
|
|
userAgent: 'CodeNuk-GitIntegration/1.0.0',
|
|
});
|
|
|
|
const { data: repoInfo } = await unauthenticatedOctokit.repos.get({ owner, repo });
|
|
const isPublic = !repoInfo.private;
|
|
|
|
console.log(`🔓 Repository is ${isPublic ? 'public' : 'private'}`);
|
|
console.log(`📊 Repository info:`);
|
|
console.log(` - Full Name: ${repoInfo.full_name}`);
|
|
console.log(` - Description: ${repoInfo.description || 'No description'}`);
|
|
console.log(` - Language: ${repoInfo.language || 'Unknown'}`);
|
|
console.log(` - Stars: ${repoInfo.stargazers_count}`);
|
|
console.log(` - Forks: ${repoInfo.forks_count}`);
|
|
console.log(` - Default Branch: ${repoInfo.default_branch}`);
|
|
console.log(` - Size: ${repoInfo.size} KB`);
|
|
console.log(` - Updated: ${repoInfo.updated_at}`);
|
|
|
|
if (isPublic) {
|
|
console.log(`✅ Repository is accessible and public`);
|
|
|
|
// Try to analyze the codebase
|
|
console.log(`🔍 Analyzing codebase...`);
|
|
const analysis = await githubService.analyzeCodebase(owner, repo, repoInfo.default_branch, true);
|
|
console.log(`📈 Codebase analysis completed:`);
|
|
console.log(` - Total Files: ${analysis.total_files}`);
|
|
console.log(` - Languages: ${Object.keys(analysis.languages).join(', ')}`);
|
|
console.log(` - Main Language: ${analysis.main_language}`);
|
|
console.log(` - Structure: ${analysis.structure ? 'Available' : 'Not available'}`);
|
|
|
|
// Try to download the repository
|
|
console.log(`📥 Attempting to download repository...`);
|
|
const downloadResult = await githubService.downloadRepository(owner, repo, repoInfo.default_branch);
|
|
|
|
if (downloadResult.success) {
|
|
console.log(`✅ Repository downloaded successfully!`);
|
|
console.log(`📁 Local path: ${downloadResult.local_path}`);
|
|
console.log(`📊 Download stats:`);
|
|
console.log(` - Files: ${downloadResult.files_count}`);
|
|
console.log(` - Directories: ${downloadResult.directories_count}`);
|
|
console.log(` - Size: ${downloadResult.total_size_bytes} bytes`);
|
|
|
|
// List some files
|
|
if (fs.existsSync(downloadResult.local_path)) {
|
|
const files = fs.readdirSync(downloadResult.local_path);
|
|
console.log(`📄 Sample files in root:`);
|
|
files.slice(0, 10).forEach(file => {
|
|
const filePath = path.join(downloadResult.local_path, file);
|
|
const stat = fs.statSync(filePath);
|
|
console.log(` - ${file} (${stat.isDirectory() ? 'directory' : 'file'})`);
|
|
});
|
|
}
|
|
} else {
|
|
console.log(`❌ Repository download failed: ${downloadResult.error}`);
|
|
}
|
|
|
|
} else {
|
|
console.log(`🔒 Repository is private - authentication required`);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log(`❌ Error accessing repository: ${error.message}`);
|
|
if (error.status === 404) {
|
|
console.log(`🔍 Repository might be private or not found`);
|
|
}
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error(`💥 Test failed: ${error.message}`);
|
|
console.error(error.stack);
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
testRepository();
|