File tree Expand file tree Collapse file tree 6 files changed +60
-3
lines changed
src/server/webhooks/events Expand file tree Collapse file tree 6 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 11import { describe , test } from "vitest"
2- import { isPrEventKey } from "./event.js"
2+ import type { Event } from "../event.js"
3+ import { isPrEvent , isPrEventKey } from "./event.js"
34
45describe ( "isPrEventKey" , ( ) => {
56test ( "pr:comment:added" , ( { expect } ) => {
@@ -12,3 +13,15 @@ describe("isPrEventKey", () => {
1213expect ( result ) . toBe ( false )
1314} )
1415} )
16+
17+ describe ( "isPrEvent" , ( ) => {
18+ test ( "pr:comment:added" , ( { expect } ) => {
19+ const result = isPrEvent ( { eventKey : "pr:comment:added" } as Event )
20+ expect ( result ) . toBe ( true )
21+ } )
22+
23+ test ( "project:modified" , ( { expect } ) => {
24+ const result = isPrEvent ( { eventKey : "project:modified" } as Event )
25+ expect ( result ) . toBe ( false )
26+ } )
27+ } )
Original file line number Diff line number Diff line change 1+ import type { Event } from "../event.js"
12import type { PRCommentAdded } from "./comment_added.js"
23import type { PRCommentDeleted } from "./comment_deleted.js"
34import type { PRCommentEdited } from "./comment_edited.js"
@@ -29,6 +30,10 @@ export type PrEvent =
2930| PRReviewerUpdated
3031export type PrEventKey = PrEvent [ "eventKey" ]
3132
33+ export function isPrEvent ( event : Event ) : event is PrEvent {
34+ return isPrEventKey ( event . eventKey )
35+ }
36+
3237export function isPrEventKey ( key : unknown ) : key is PrEventKey {
3338return Object . values < unknown > ( prEventKeys ) . includes ( key )
3439}
Original file line number Diff line number Diff line change 11import { describe , test } from "vitest"
2- import { isProjectEventKey } from "./event.js"
2+ import type { Event } from "../event.js"
3+ import { isProjectEvent , isProjectEventKey } from "./event.js"
34
45describe ( "isProjectEventKey" , ( ) => {
56test ( "project:modified" , ( { expect } ) => {
@@ -12,3 +13,17 @@ describe("isProjectEventKey", () => {
1213expect ( result ) . toBe ( false )
1314} )
1415} )
16+
17+ describe ( "isProjectEvent" , ( ) => {
18+ test ( "project:modified" , ( { expect } ) => {
19+ const result = isProjectEvent ( { eventKey : "project:modified" } as Event )
20+ expect ( result ) . toBe ( true )
21+ } )
22+
23+ test ( "mirror:repo_synchronized" , ( { expect } ) => {
24+ const result = isProjectEvent ( {
25+ eventKey : "mirror:repo_synchronized" ,
26+ } as Event )
27+ expect ( result ) . toBe ( false )
28+ } )
29+ } )
Original file line number Diff line number Diff line change 1+ import type { Event } from "../event.js"
12import type { ProjectModified } from "./modified.js"
23
34/** You can create webhooks for events that occur in a project. */
45export type ProjectEvent = ProjectModified
56export type ProjectEventKey = ProjectEvent [ "eventKey" ]
67
8+ export function isProjectEvent ( event : Event ) : event is ProjectEvent {
9+ return isProjectEventKey ( event . eventKey )
10+ }
11+
712export function isProjectEventKey ( key : unknown ) : key is ProjectEventKey {
813return Object . values < unknown > ( projectEventKeys ) . includes ( key )
914}
Original file line number Diff line number Diff line change 11import { describe , test } from "vitest"
2- import { isRepoEventKey } from "./event.js"
2+ import type { Event } from "../event.js"
3+ import { isRepoEvent , isRepoEventKey } from "./event.js"
34
45describe ( "isRepoEventKey" , ( ) => {
56test ( "mirror:repo_synchronized" , ( { expect } ) => {
@@ -12,3 +13,16 @@ describe("isRepoEventKey", () => {
1213expect ( result ) . toBe ( false )
1314} )
1415} )
16+ describe ( "isRepoEvent" , ( ) => {
17+ test ( "mirror:repo_synchronized" , ( { expect } ) => {
18+ const result = isRepoEvent ( {
19+ eventKey : "mirror:repo_synchronized" ,
20+ } as Event )
21+ expect ( result ) . toBe ( true )
22+ } )
23+
24+ test ( "project:modified" , ( { expect } ) => {
25+ const result = isRepoEvent ( { eventKey : "project:modified" } as Event )
26+ expect ( result ) . toBe ( false )
27+ } )
28+ } )
Original file line number Diff line number Diff line change 1+ import type { Event } from "../event.js"
12import type { RepoCommentAdded } from "./comment_added.js"
23import type { RepoCommentDeleted } from "./comment_deleted.js"
34import type { RepoCommentEdited } from "./comment_edited.js"
@@ -19,6 +20,10 @@ export type RepoEvent =
1920| RepoSecretDetected
2021export type RepoEventKey = RepoEvent [ "eventKey" ]
2122
23+ export function isRepoEvent ( event : Event ) : event is RepoEvent {
24+ return isRepoEventKey ( event . eventKey )
25+ }
26+
2227export function isRepoEventKey ( key : unknown ) : key is RepoEventKey {
2328return Object . values < unknown > ( repoEventKeys ) . includes ( key )
2429}
You can’t perform that action at this time.
0 commit comments