-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-greptile.ts
More file actions
147 lines (125 loc) · 4.91 KB
/
Copy pathtest-greptile.ts
File metadata and controls
147 lines (125 loc) · 4.91 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
140
141
142
143
144
145
146
147
// test-greptile.ts
const popularRepos = [
// 'apache/spark',
'marimo-team/marimo'
];
async function testGreptileIndexing() {
// Replace these with your actual tokens
const greptileApiKey = process.env.GREPTILE_API_KEY;
const githubToken = process.env.GITHUB_PAT;
// Ensure tokens are set
if (!greptileApiKey || !githubToken) {
throw new Error('API keys not set');
}
for (const repo of popularRepos) {
console.log(`\nTesting repository: ${repo}`);
try {
// 1. Submit repository for indexing
// console.log('Submitting for indexing...');
// const submitResponse = await fetch('https://api.greptile.com/v2/repositories', {
// method: 'POST',
// headers: {
// 'Authorization': `Bearer ${greptileApiKey}`,
// 'X-Github-Token': githubToken,
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify({
// remote: 'github',
// repository: repo,
// branch: "main"
// })
// });
// console.log('Submit response status:', submitResponse.status);
// const submitData = await submitResponse.json();
// console.log('Submit response:', submitData);
// 2. Check indexing status
const repositoryId = encodeURIComponent(`github:main:${repo}`);
console.log('Checking initial status...');
const statusResponse = await fetch(
`https://api.greptile.com/v2/repositories/${repositoryId}`,
{
method: 'GET',
headers: {
'Authorization': `Bearer ${greptileApiKey}`,
'X-Github-Token': githubToken
}
}
);
console.log('Status response status:', statusResponse.status);
const statusData = await statusResponse.json();
console.log('Status response:', statusData);
} catch (error) {
console.error('Error processing repository:', repo);
console.error('Error details:', error);
}
}
}
// test-greptile-query.ts
async function testGreptileChangelog() {
const greptileApiKey = process.env.GREPTILE_API_KEY || 'your-greptile-api-key';
const githubToken = process.env.GITHUB_PAT || 'your-github-token';
// Test with one of our indexed repos
const repoUrl = 'facebook/react';
// Sample diff text (you would get this from your actual diffs)
const diffText = `
Commit: b4cbdc5 - 2024-10-22 23:49:10
Message: remove terser from react-compiler-runtime build (#31326)
📋 Summary
This fixes a minor nit I have about the react-compiler-runtime package
in that the published code is minified. I assume most consumers will
minify their own bundles so there's no rea
... (truncated)
Commit: 9daabc0 - 2024-10-22 20:07:10
Message: react-hooks/rules-of-hooks: Add support for do/while loops (#28714)
`;
try {
console.log('Testing Greptile changelog generation...');
console.log('Repository:', repoUrl);
console.log('Sample diff length:', diffText.length);
const response = await fetch("https://api.greptile.com/v2/query", {
method: "POST",
headers: {
Authorization: `Bearer ${greptileApiKey}`,
"X-Github-Token": githubToken,
"Content-Type": "application/json",
},
body: JSON.stringify({
messages: [{
content: `You are a changelog generator. Analyze these Git diffs and generate a clear, concise changelog entry. Focus on the impact and meaning of changes:
Diffs to analyze:
${diffText}
Format the changelog with appropriate sections (Features, Improvements, Bug Fixes) and use bullet points.`,
role: "user"
}],
repositories: [{
remote: "github",
repository: repoUrl,
branch: "main"
}],
genius: true
})
});
console.log('\nResponse status:', response.status);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`API request failed: ${response.status} ${errorText}`);
}
const data = await response.json();
console.log('\nGreptile Response:', JSON.stringify(data, null, 2));
} catch (error) {
console.error('Error:', error instanceof Error ? error.message : 'Unknown error');
if (error instanceof Error) {
console.error('Stack:', error.stack);
}
}
}
// Run the test
console.log('Starting Greptile changelog test...');
testGreptileChangelog()
.then(() => console.log('\nTest completed'))
.catch(error => console.error('Test failed:', error));
// // Run the test
// console.log('Starting Greptile API test...');
// testGreptileIndexing()
// .then(() => console.log('Test completed'))
// .catch(error => console.error('Test failed:', error));