-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-github-tools.ts
More file actions
139 lines (119 loc) · 5.26 KB
/
test-github-tools.ts
File metadata and controls
139 lines (119 loc) · 5.26 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
131
132
133
134
135
136
137
138
139
/**
* Script de test manuel pour les GitHub Tools
* Usage: node --experimental-strip-types test-github-tools.ts [owner] [repo]
* Exemple: node --experimental-strip-types test-github-tools.ts 1904labs dom-to-image-more
*/
import { githubTools } from './lib/github-tools';
// Récupérer les arguments de la ligne de commande
const args = process.argv.slice(2);
const owner = args[0] || '1904labs';
const repo = args[1] || 'dom-to-image-more';
console.log('🧪 Test des GitHub Tools');
console.log('========================\n');
console.log(`Repository de test: ${owner}/${repo}\n`);
// Récupérer les outils par leur nom
const getRepositoryInfoTool = githubTools.find(tool => tool.name === 'get_repository_info');
const getReadmeContentTool = githubTools.find(tool => tool.name === 'get_readme_content');
const getRecentActivityTool = githubTools.find(tool => tool.name === 'get_recent_activity');
const getTopContributorsTool = githubTools.find(tool => tool.name === 'get_top_contributors');
async function testTool1_RepositoryInfo() {
console.log('📝 Test 1: get_repository_info');
console.log('--------------------------------');
try {
if (!getRepositoryInfoTool) {
throw new Error('Outil get_repository_info non trouvé');
}
const result = await getRepositoryInfoTool.invoke({ owner, repo });
const data = JSON.parse(result);
console.log('✅ Résultat:');
console.log(` Repository: ${data.full_name}`);
console.log(` Description: ${data.description || 'Aucune description'}`);
console.log(` Stars: ${data.stars} ⭐`);
console.log(` Forks: ${data.forks} 🔱`);
console.log(` Langage principal: ${data.language || 'Non spécifié'}`);
console.log(` Créé le: ${new Date(data.created_at).toLocaleDateString('fr-FR')}`);
console.log(` Dernière mise à jour: ${new Date(data.updated_at).toLocaleDateString('fr-FR')}`);
console.log(` License: ${data.license || 'Non spécifiée'}`);
console.log(` Issues ouvertes: ${data.open_issues}`);
if (data.topics && data.topics.length > 0) {
console.log(` Topics: ${data.topics.join(', ')}`);
}
} catch (error) {
console.error('❌ Erreur:', error instanceof Error ? error.message : error);
}
console.log('\n');
}
async function testTool2_ReadmeContent() {
console.log('📖 Test 2: get_readme_content');
console.log('--------------------------------');
try {
if (!getReadmeContentTool) {
throw new Error('Outil get_readme_content non trouvé');
}
const content = await getReadmeContentTool.invoke({ owner, repo });
const preview = content.substring(0, 500);
console.log('✅ Résultat (premiers 500 caractères):');
console.log(preview + '...');
console.log(`\nLongueur totale du README: ${content.length} caractères`);
} catch (error) {
console.error('❌ Erreur:', error instanceof Error ? error.message : error);
}
console.log('\n');
}
async function testTool3_RecentActivity() {
console.log('🔄 Test 3: get_recent_activity');
console.log('--------------------------------');
try {
if (!getRecentActivityTool) {
throw new Error('Outil get_recent_activity non trouvé');
}
const result = await getRecentActivityTool.invoke({ owner, repo });
const data = JSON.parse(result);
console.log(`✅ Résultat:\n`);
console.log(` Dernier commit: ${data.last_commit_message}`);
console.log(` Auteur: ${data.last_commit_author}`);
console.log(` Date: ${new Date(data.last_commit_date).toLocaleDateString('fr-FR')}`);
if (data.recent_commits && data.recent_commits.length > 1) {
console.log(`\n Derniers commits:`);
data.recent_commits.forEach((commit: { message: string; author: string; date: string }, i: number) => {
const date = new Date(commit.date).toLocaleDateString('fr-FR');
console.log(` ${i + 1}. ${commit.message.split('\n')[0]}`);
console.log(` Par ${commit.author} le ${date}`);
});
}
} catch (error) {
console.error('❌ Erreur:', error instanceof Error ? error.message : error);
}
console.log('\n');
}
async function testTool4_TopContributors() {
console.log('👥 Test 4: get_top_contributors');
console.log('--------------------------------');
try {
if (!getTopContributorsTool) {
throw new Error('Outil get_top_contributors non trouvé');
}
const result = await getTopContributorsTool.invoke({ owner, repo });
const data = JSON.parse(result);
console.log(`✅ Résultat - Top ${data.top_contributors.length} contributeurs:\n`);
data.top_contributors.forEach((contributor: { username: string; contributions: any; }, i: number) => {
console.log(` ${i + 1}. ${contributor.username.padEnd(30)} ${contributor.contributions} contributions`);
});
} catch (error) {
console.error('❌ Erreur:', error instanceof Error ? error.message : error);
}
console.log('\n');
}
// Fonction principale pour exécuter tous les tests
async function runAllTests() {
await testTool1_RepositoryInfo();
await testTool2_ReadmeContent();
await testTool3_RecentActivity();
await testTool4_TopContributors();
console.log('🎉 Tous les tests sont terminés!');
}
// Exécuter les tests
runAllTests().catch((error) => {
console.error('💥 Erreur fatale:', error);
process.exit(1);
});