Skip to content

Commit 08f4a48

Browse files
fix: v2 event-types versioning (#15549)
* Added a log for pull_request * Added labels logging * Using labels straight from event PR object * Converting to JSON * Switching to use payload * Fixed issue with undefined pr * Fixed non-mapping issue * Removed the types * Added another cache key segment using the head commit sha * Added separate workflow for labeled action * Fixed syntax error * Fixing payload issue * Added log * logging full object * Put e2e back in the names to help find them * Limited logging * fix: v2 even-types versioning * test: old v2 even-types request with VERSION_2024_06_11 * test: old v2 even-types request with VERSION_2024_04_15 --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
1 parent 928dd49 commit 08f4a48

File tree

6 files changed

+99
-10
lines changed

6 files changed

+99
-10
lines changed

.github/actions/cache-build/action.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ runs:
2020
key-2: ${{ hashFiles('apps/**/**.[jt]s', 'apps/**/**.[jt]sx', 'packages/**/**.[jt]s', 'packages/**/**.[jt]sx', '!**/node_modules') }}
2121
key-3: ${{ github.event.pull_request.number || github.ref }}
2222
key-4: ${{ github.sha }}
23+
key-5: ${{ github.event.pull_request.head.sha }}
2324
with:
2425
path: |
2526
${{ github.workspace }}/apps/web/.next
2627
${{ github.workspace }}/apps/web/public/embed
2728
**/.turbo/**
2829
**/dist/**
29-
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}-${{ env.key-2 }}-${{ env.key-3 }}-${{ env.key-4 }}
30+
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}-${{ env.key-2 }}-${{ env.key-3 }}-${{ env.key-4 }}-${{ env.key-5 }}
3031
- run: |
3132
export NODE_OPTIONS="--max_old_space_size=8192"
3233
yarn build

.github/workflows/pr-labeled.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: PR Labeled with ready-for-e2e
2+
3+
on:
4+
pull_request_target:
5+
types: [labeled]
6+
branches:
7+
- main
8+
- gh-actions-test-branch
9+
workflow_dispatch:
10+
jobs:
11+
run-e2e-jobs:
12+
name: Run E2E Jobs
13+
runs-on: buildjet-2vcpu-ubuntu-2204
14+
permissions:
15+
pull-requests: read
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: ./.github/actions/dangerous-git-checkout
19+
20+
- name: Check Label and Retrigger Checks
21+
uses: actions/github-script@v7
22+
with:
23+
github-token: ${{ secrets.GITHUB_TOKEN }}
24+
script: |
25+
const labelName = context.payload.label.name;
26+
const prNumber = context.payload.pull_request.number;
27+
const owner = context.repo.owner;
28+
const repo = context.repo.repo;
29+
30+
if (labelName === 'ready-for-e2e') {
31+
console.log(`Running E2E jobs for PR #${prNumber}...`);
32+
33+
const checkRuns = await github.rest.checks.listForRef({
34+
owner,
35+
repo,
36+
ref: context.payload.pull_request.head.sha,
37+
});
38+
39+
for (const check of checkRuns.data.check_runs) {
40+
console.log('check.name', check.name);
41+
if (check.name.includes('e2e')) {
42+
await github.rest.actions.reRunJob({
43+
owner,
44+
repo,
45+
job_id: check.id,
46+
});
47+
console.log(`Triggering job #${check.id}`);
48+
}
49+
}
50+
51+
console.log(`Triggered E2E checks for PR #${prNumber}`);
52+
} else {
53+
console.log(`Label ${labelName} does not trigger re-running checks.`);
54+
}

.github/workflows/pr.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: PR Update
22

33
on:
44
pull_request_target:
5-
types: [opened, synchronize, reopened, labeled]
65
branches:
76
- main
87
- gh-actions-test-branch
@@ -135,28 +134,28 @@ jobs:
135134
secrets: inherit
136135

137136
e2e:
138-
name: Tests
137+
name: e2e
139138
needs: [changes, check-label, build]
140139
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
141140
uses: ./.github/workflows/e2e.yml
142141
secrets: inherit
143142

144143
e2e-app-store:
145-
name: Tests
144+
name: e2e-app-store
146145
needs: [changes, check-label, build]
147146
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
148147
uses: ./.github/workflows/e2e-app-store.yml
149148
secrets: inherit
150149

151150
e2e-embed:
152-
name: Tests
151+
name: e2e-embed
153152
needs: [changes, check-label, build]
154153
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
155154
uses: ./.github/workflows/e2e-embed.yml
156155
secrets: inherit
157156

158157
e2e-embed-react:
159-
name: Tests
158+
name: e2e-embed-react
160159
needs: [changes, check-label, build]
161160
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
162161
uses: ./.github/workflows/e2e-embed-react.yml

apps/api/v2/src/ee/event-types/event-types_2024_04_15/controllers/event-types.controller.e2e-spec.ts

+36-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import { TeamRepositoryFixture } from "test/fixtures/repository/team.repository.
2424
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
2525
import { withApiAuth } from "test/utils/withApiAuth";
2626

27-
import { SUCCESS_STATUS } from "@calcom/platform-constants";
27+
import {
28+
SUCCESS_STATUS,
29+
VERSION_2024_06_11,
30+
VERSION_2024_04_15,
31+
CAL_API_VERSION_HEADER,
32+
} from "@calcom/platform-constants";
2833
import {
2934
EventTypesByViewer,
3035
EventTypesPublic,
@@ -154,6 +159,7 @@ describe("Event types Endpoints", () => {
154159

155160
return request(app.getHttpServer())
156161
.post("/api/v2/event-types")
162+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
157163
.send(body)
158164
.expect(201)
159165
.then(async (response) => {
@@ -184,6 +190,7 @@ describe("Event types Endpoints", () => {
184190

185191
return request(app.getHttpServer())
186192
.patch(`/api/v2/event-types/${eventType.id}`)
193+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
187194
.send(body)
188195
.expect(200)
189196
.then(async (response) => {
@@ -288,6 +295,25 @@ describe("Event types Endpoints", () => {
288295
it(`/GET/:id`, async () => {
289296
const response = await request(app.getHttpServer())
290297
.get(`/api/v2/event-types/${eventType.id}`)
298+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
299+
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
300+
.set("Authorization", `Bearer whatever`)
301+
.expect(200);
302+
303+
const responseBody: GetEventTypeOutput = response.body;
304+
305+
expect(responseBody.status).toEqual(SUCCESS_STATUS);
306+
expect(responseBody.data).toBeDefined();
307+
expect(responseBody.data.eventType.id).toEqual(eventType.id);
308+
expect(responseBody.data.eventType.title).toEqual(eventType.title);
309+
expect(responseBody.data.eventType.slug).toEqual(eventType.slug);
310+
expect(responseBody.data.eventType.userId).toEqual(user.id);
311+
});
312+
313+
it(`/GET/:id with version VERSION_2024_06_11`, async () => {
314+
const response = await request(app.getHttpServer())
315+
.get(`/api/v2/event-types/${eventType.id}`)
316+
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_11)
291317
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
292318
.set("Authorization", `Bearer whatever`)
293319
.expect(200);
@@ -305,6 +331,7 @@ describe("Event types Endpoints", () => {
305331
it(`/GET/:username/public`, async () => {
306332
const response = await request(app.getHttpServer())
307333
.get(`/api/v2/event-types/${username}/public`)
334+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
308335
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
309336
.set("Authorization", `Bearer whatever`)
310337
.expect(200);
@@ -323,6 +350,7 @@ describe("Event types Endpoints", () => {
323350
it(`/GET/:username/:eventSlug/public`, async () => {
324351
const response = await request(app.getHttpServer())
325352
.get(`/api/v2/event-types/${username}/${eventType.slug}/public`)
353+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
326354
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
327355
.set("Authorization", `Bearer whatever`)
328356
.expect(200);
@@ -340,6 +368,7 @@ describe("Event types Endpoints", () => {
340368
it(`/GET/`, async () => {
341369
const response = await request(app.getHttpServer())
342370
.get(`/api/v2/event-types`)
371+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
343372
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
344373
.set("Authorization", `Bearer whatever`)
345374
.expect(200);
@@ -359,6 +388,7 @@ describe("Event types Endpoints", () => {
359388
it(`/GET/public/:username/`, async () => {
360389
const response = await request(app.getHttpServer())
361390
.get(`/api/v2/event-types/${username}/public`)
391+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
362392
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
363393
.set("Authorization", `Bearer whatever`)
364394
.expect(200);
@@ -375,13 +405,17 @@ describe("Event types Endpoints", () => {
375405
it(`/GET/:id not existing`, async () => {
376406
await request(app.getHttpServer())
377407
.get(`/api/v2/event-types/1000`)
408+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
378409
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
379410
.set("Authorization", `Bearer whatever`)
380411
.expect(404);
381412
});
382413

383414
it("should delete schedule", async () => {
384-
return request(app.getHttpServer()).delete(`/api/v2/event-types/${eventType.id}`).expect(200);
415+
return request(app.getHttpServer())
416+
.delete(`/api/v2/event-types/${eventType.id}`)
417+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
418+
.expect(200);
385419
});
386420

387421
afterAll(async () => {

apps/api/v2/src/ee/event-types/event-types_2024_04_15/controllers/event-types.controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "@/ee/event-types/event-types_2024_04_15/outputs/get-event-types.output";
1414
import { UpdateEventTypeOutput } from "@/ee/event-types/event-types_2024_04_15/outputs/update-event-type.output";
1515
import { EventTypesService_2024_04_15 } from "@/ee/event-types/event-types_2024_04_15/services/event-types.service";
16-
import { VERSION_2024_04_15_VALUE } from "@/lib/api-versions";
16+
import { VERSION_2024_04_15, VERSION_2024_06_11 } from "@/lib/api-versions";
1717
import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator";
1818
import { Permissions } from "@/modules/auth/decorators/permissions/permissions.decorator";
1919
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard";
@@ -45,7 +45,7 @@ import { PrismaClient } from "@calcom/prisma";
4545

4646
@Controller({
4747
path: "/v2/event-types",
48-
version: VERSION_2024_04_15_VALUE,
48+
version: [VERSION_2024_04_15, VERSION_2024_06_11],
4949
})
5050
@UseGuards(PermissionsGuard)
5151
@DocsTags("Event types")

apps/api/v2/src/lib/api-versions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export const VERSION_2024_06_14_VALUE: VersionValue = VERSION_2024_06_14 as unkn
1212
export const VERSION_2024_06_11_VALUE: VersionValue = VERSION_2024_06_11 as unknown as VersionValue;
1313
export const VERSION_2024_04_15_VALUE: VersionValue = VERSION_2024_04_15 as unknown as VersionValue;
1414

15+
export { VERSION_2024_04_15 };
1516
export { VERSION_2024_06_11 };
1617
export { VERSION_2024_06_14 };

0 commit comments

Comments
 (0)