-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathinject-repo-data.ts
More file actions
93 lines (81 loc) · 3.06 KB
/
inject-repo-data.ts
File metadata and controls
93 lines (81 loc) · 3.06 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
import { Script } from "../scriptRunner";
import { PrismaClient } from "../../dist";
const NUM_REPOS = 1000;
const NUM_INDEXING_JOBS_PER_REPO = 10000;
const NUM_PERMISSION_JOBS_PER_REPO = 10000;
export const injectRepoData: Script = {
run: async (prisma: PrismaClient) => {
const orgId = 1;
// Check if org exists
const org = await prisma.org.findUnique({
where: { id: orgId }
});
if (!org) {
await prisma.org.create({
data: {
id: orgId,
name: 'Test Org',
domain: 'test-org.com'
}
});
}
const connection = await prisma.connection.create({
data: {
orgId,
name: 'test-connection',
connectionType: 'github',
config: {}
}
});
console.log(`Creating ${NUM_REPOS} repos...`);
const statuses = ['PENDING', 'IN_PROGRESS', 'COMPLETED', 'FAILED'] as const;
const indexingJobTypes = ['INDEX', 'CLEANUP'] as const;
for (let i = 0; i < NUM_REPOS; i++) {
const repo = await prisma.repo.create({
data: {
name: `test-repo-${i}`,
isFork: false,
isArchived: false,
metadata: {},
cloneUrl: `https://github.com/test-org/test-repo-${i}`,
webUrl: `https://github.com/test-org/test-repo-${i}`,
orgId,
external_id: `test-repo-${i}`,
external_codeHostType: 'github',
external_codeHostUrl: 'https://github.com',
connections: {
create: {
connectionId: connection.id,
}
}
}
});
for (let j = 0; j < NUM_PERMISSION_JOBS_PER_REPO; j++) {
const status = statuses[Math.floor(Math.random() * statuses.length)];
await prisma.repoPermissionSyncJob.create({
data: {
repoId: repo.id,
status,
completedAt: status === 'COMPLETED' || status === 'FAILED' ? new Date() : null,
errorMessage: status === 'FAILED' ? 'Mock error message' : null
}
});
}
for (let j = 0; j < NUM_INDEXING_JOBS_PER_REPO; j++) {
const status = statuses[Math.floor(Math.random() * statuses.length)];
const type = indexingJobTypes[Math.floor(Math.random() * indexingJobTypes.length)];
await prisma.repoIndexingJob.create({
data: {
repoId: repo.id,
type,
status,
completedAt: status === 'COMPLETED' || status === 'FAILED' ? new Date() : null,
errorMessage: status === 'FAILED' ? 'Mock indexing error' : null,
metadata: {}
}
});
}
}
console.log(`Created ${NUM_REPOS} repos with associated jobs.`);
}
};