Skip to content

Commit e02d498

Browse files
feat: allow custom repos (#3483)
1 parent 9ee3906 commit e02d498

File tree

4 files changed

+156
-13
lines changed

4 files changed

+156
-13
lines changed

__tests__/schema/profile.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,4 +2375,146 @@ describe('mutation upsertUserGeneralExperience with repository', () => {
23752375
'ZOD_VALIDATION_ERROR',
23762376
);
23772377
});
2378+
2379+
it('should create an opensource experience with custom repository (null id)', async () => {
2380+
loggedUser = '1';
2381+
2382+
const res = await client.mutate(UPSERT_OPENSOURCE_MUTATION, {
2383+
variables: {
2384+
input: {
2385+
type: 'opensource',
2386+
title: 'GitLab Contributor',
2387+
description: 'Contributing to a GitLab project',
2388+
startedAt: new Date('2023-01-01'),
2389+
repository: {
2390+
id: null,
2391+
owner: 'myorg',
2392+
name: 'myproject',
2393+
url: 'https://gitlab.com/myorg/myproject',
2394+
image: null,
2395+
},
2396+
},
2397+
},
2398+
});
2399+
2400+
expect(res.errors).toBeFalsy();
2401+
expect(res.data.upsertUserGeneralExperience).toMatchObject({
2402+
id: expect.any(String),
2403+
type: 'opensource',
2404+
title: 'GitLab Contributor',
2405+
company: null,
2406+
customCompanyName: null,
2407+
repository: {
2408+
id: null,
2409+
owner: 'myorg',
2410+
name: 'myproject',
2411+
url: 'https://gitlab.com/myorg/myproject',
2412+
image: null,
2413+
},
2414+
});
2415+
2416+
// Verify the repository is stored in flags
2417+
const saved = await con.getRepository(UserExperience).findOne({
2418+
where: { id: res.data.upsertUserGeneralExperience.id },
2419+
});
2420+
expect(saved?.flags).toMatchObject({
2421+
repository: {
2422+
id: null,
2423+
owner: 'myorg',
2424+
name: 'myproject',
2425+
url: 'https://gitlab.com/myorg/myproject',
2426+
image: null,
2427+
},
2428+
});
2429+
});
2430+
2431+
it('should create an opensource experience with custom repository without owner', async () => {
2432+
loggedUser = '1';
2433+
2434+
const res = await client.mutate(UPSERT_OPENSOURCE_MUTATION, {
2435+
variables: {
2436+
input: {
2437+
type: 'opensource',
2438+
title: 'Custom Repo Contributor',
2439+
startedAt: new Date('2023-01-01'),
2440+
repository: {
2441+
id: null,
2442+
owner: null,
2443+
name: 'standalone-project',
2444+
url: 'https://example.com/standalone-project',
2445+
image: null,
2446+
},
2447+
},
2448+
},
2449+
});
2450+
2451+
expect(res.errors).toBeFalsy();
2452+
expect(res.data.upsertUserGeneralExperience).toMatchObject({
2453+
type: 'opensource',
2454+
repository: {
2455+
id: null,
2456+
owner: null,
2457+
name: 'standalone-project',
2458+
url: 'https://example.com/standalone-project',
2459+
image: null,
2460+
},
2461+
});
2462+
});
2463+
2464+
it('should update from GitHub repository to custom repository', async () => {
2465+
loggedUser = '1';
2466+
2467+
// First create with GitHub repository
2468+
const created = await client.mutate(UPSERT_OPENSOURCE_MUTATION, {
2469+
variables: {
2470+
input: {
2471+
type: 'opensource',
2472+
title: 'Initial Contribution',
2473+
startedAt: new Date('2023-01-01'),
2474+
repository: {
2475+
id: '10270250',
2476+
owner: 'facebook',
2477+
name: 'react',
2478+
url: 'https://github.com/facebook/react',
2479+
image: 'https://avatars.githubusercontent.com/u/69631?v=4',
2480+
},
2481+
},
2482+
},
2483+
});
2484+
2485+
expect(created.errors).toBeFalsy();
2486+
const experienceId = created.data.upsertUserGeneralExperience.id;
2487+
2488+
// Update to custom repository
2489+
const updated = await client.mutate(UPSERT_OPENSOURCE_MUTATION, {
2490+
variables: {
2491+
id: experienceId,
2492+
input: {
2493+
type: 'opensource',
2494+
title: 'Moved to GitLab',
2495+
startedAt: new Date('2023-01-01'),
2496+
repository: {
2497+
id: null,
2498+
owner: 'myorg',
2499+
name: 'forked-project',
2500+
url: 'https://gitlab.com/myorg/forked-project',
2501+
image: null,
2502+
},
2503+
},
2504+
},
2505+
});
2506+
2507+
expect(updated.errors).toBeFalsy();
2508+
expect(updated.data.upsertUserGeneralExperience).toMatchObject({
2509+
id: experienceId,
2510+
title: 'Moved to GitLab',
2511+
repository: {
2512+
id: null,
2513+
owner: 'myorg',
2514+
name: 'forked-project',
2515+
url: 'https://gitlab.com/myorg/forked-project',
2516+
image: null,
2517+
},
2518+
});
2519+
});
23782520
});

src/common/schema/profile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export const userExperienceProjectSchema = z
5151
.extend(userExperienceInputBaseSchema.shape);
5252

5353
export const repositoryInputSchema = z.object({
54-
id: z.string().min(1),
55-
owner: z.string().min(1).max(100),
54+
id: z.string().min(1).nullish(),
55+
owner: z.string().max(100).nullish(),
5656
name: z.string().min(1).max(200),
5757
url: z.url(),
58-
image: z.url(),
58+
image: z.url().nullish(),
5959
});
6060

6161
export const userExperienceOpenSourceSchema = z

src/entity/user/experiences/UserExperience.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ export type UserExperienceFlags = Partial<{
2323
customImage: string;
2424
removedEnrichment: boolean;
2525
repository: {
26-
id: string;
26+
id: string | null;
27+
owner: string | null;
2728
name: string;
2829
url: string;
29-
image: string;
30+
image: string | null;
3031
};
3132
}>;
3233

src/schema/profile.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ export const typeDefs = /* GraphQL */ `
6868
}
6969
7070
type UserExperienceRepository {
71-
id: ID!
71+
id: ID
7272
owner: String
7373
name: String!
7474
url: String!
75-
image: String!
75+
image: String
7676
}
7777
7878
type UserExperience {
@@ -134,11 +134,11 @@ export const typeDefs = /* GraphQL */ `
134134
}
135135
136136
input RepositoryInput {
137-
id: ID!
138-
owner: String!
137+
id: ID
138+
owner: String
139139
name: String!
140140
url: String!
141-
image: String!
141+
image: String
142142
}
143143
144144
input UserGeneralExperienceInput {
@@ -236,11 +236,11 @@ const generateExperienceToSave = async <
236236
parsed as R & {
237237
customDomain?: string | null;
238238
repository?: {
239-
id: string;
240-
owner: string;
239+
id: string | null;
240+
owner: string | null;
241241
name: string;
242242
url: string;
243-
image: string;
243+
image: string | null;
244244
} | null;
245245
};
246246

0 commit comments

Comments
 (0)