MCPcopy Create free account
hub / github.com/block/buzz / buildMockProjectEvents

Function buildMockProjectEvents

desktop/src/testing/e2eBridge.ts:4204–4267  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4202let mockProjectEventStore: RelayEvent[] | null = null;
4203
4204function buildMockProjectEvents(): RelayEvent[] {
4205 const events: RelayEvent[] = [];
4206 const daySeconds = 86_400;
4207 const now = Math.floor(Date.now() / 1000);
4208 const historyDays = 26 * 7;
4209
4210 for (const [projectIndex, seed] of MOCK_PROJECT_SEEDS.entries()) {
4211 const repoAddress = `${KIND_REPO_ANNOUNCEMENT}:${seed.owner}:${seed.dtag}`;
4212 const authors = [seed.owner, ...seed.contributors];
4213 const random = mulberry32(projectIndex + 1);
4214
4215 events.push(
4216 createMockEvent(
4217 KIND_REPO_ANNOUNCEMENT,
4218 seed.description,
4219 [
4220 ["d", seed.dtag],
4221 ["name", seed.name],
4222 ["description", seed.description],
4223 ["clone", `https://relay.example.com/git/${seed.dtag}.git`],
4224 ...seed.contributors.map((pubkey) => ["p", pubkey]),
4225 ],
4226 seed.owner,
4227 now - (historyDays + 30 + projectIndex) * daySeconds,
4228 `mock-project-${seed.dtag}`.replace(/[^a-zA-Z0-9]/g, ""),
4229 ),
4230 );
4231
4232 for (let dayOffset = historyDays; dayOffset >= 0; dayOffset -= 1) {
4233 // Roughly half the days are quiet; busy days scale with activityLevel.
4234 if (random() < 0.5) continue;
4235 const dayEventCount = 1 + Math.floor(random() * seed.activityLevel);
4236
4237 for (let index = 0; index < dayEventCount; index += 1) {
4238 const createdAt =
4239 now - dayOffset * daySeconds - Math.floor(random() * 10) * 3_600;
4240 const author = authors[Math.floor(random() * authors.length)];
4241 const subject =
4242 MOCK_PROJECT_SUBJECTS[
4243 Math.floor(random() * MOCK_PROJECT_SUBJECTS.length)
4244 ];
4245 const commitHash = `${seed.dtag}${dayOffset}x${index}`
4246 .padEnd(40, "0")
4247 .slice(0, 40);
4248 const roll = random();
4249 const kind =
4250 roll < 0.7
4251 ? KIND_GIT_PATCH
4252 : roll < 0.85
4253 ? KIND_GIT_PULL_REQUEST
4254 : KIND_GIT_ISSUE;
4255 const tags = [
4256 ["a", repoAddress],
4257 ["subject", subject],
4258 ...(kind === KIND_GIT_ISSUE ? [] : [["c", commitHash]]),
4259 ];
4260
4261 events.push(createMockEvent(kind, subject, tags, author, createdAt));

Callers 1

getMockProjectEventStoreFunction · 0.85

Calls 3

mulberry32Function · 0.85
createMockEventFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected