diff --git a/dist/index.js b/dist/index.js index 9d82c97..fc4f8ff 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29627,7 +29627,7 @@ function wrappy (fn, cb) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.convertRef = void 0; -exports.convertRef = ((str, { refType }) => { +const convertRef = (str, { refType }) => { if (str === null || str === undefined) return null; if (str.startsWith('refs/')) @@ -29639,10 +29639,9 @@ exports.convertRef = ((str, { refType }) => { return `refs/tags/${str}`; case 'pull': return `refs/pull/${str}/merge`; - default: - return null; } -}); +}; +exports.convertRef = convertRef; /***/ }), @@ -29765,16 +29764,13 @@ exports.getRef = void 0; const v = __importStar(__nccwpck_require__(6661)); const schema_1 = __nccwpck_require__(3731); const utils_1 = __nccwpck_require__(1356); -exports.getRef = (({ eventName, payload }) => { +const getRef = ({ eventName, payload }) => { switch (eventName) { case 'check_run': return (0, utils_1.convertRef)(v.parse(schema_1.NullableStringSchema, payload.check_run.check_suite.head_branch), { refType: 'branch' }); case 'check_suite': return (0, utils_1.convertRef)(v.parse(schema_1.NullableStringSchema, payload.check_suite.head_branch), { refType: 'branch' }); case 'create': - return (0, utils_1.convertRef)(v.parse(schema_1.NullableStringSchema, payload.ref), { - refType: payload.ref_type - }); case 'delete': return (0, utils_1.convertRef)(v.parse(schema_1.NullableStringSchema, payload.ref), { refType: payload.ref_type @@ -29788,17 +29784,8 @@ exports.getRef = (({ eventName, payload }) => { refType: 'pull' }); case 'pull_request': - return (0, utils_1.convertRef)(payload.pull_request?.number.toString(), { - refType: 'pull' - }); case 'pull_request_review': - return (0, utils_1.convertRef)(payload.pull_request?.number.toString(), { - refType: 'pull' - }); case 'pull_request_review_comment': - return (0, utils_1.convertRef)(payload.pull_request?.number.toString(), { - refType: 'pull' - }); case 'pull_request_target': return (0, utils_1.convertRef)(payload.pull_request?.number.toString(), { refType: 'pull' @@ -29822,7 +29809,8 @@ exports.getRef = (({ eventName, payload }) => { default: throw new Error(`${eventName} event is not supported.`); } -}); +}; +exports.getRef = getRef; /***/ }), diff --git a/src/internal/utils.ts b/src/internal/utils.ts index ffbd844..460d014 100644 --- a/src/internal/utils.ts +++ b/src/internal/utils.ts @@ -1,4 +1,7 @@ -export const convertRef = ((str, { refType }) => { +export const convertRef = ( + str: string | undefined | null, + { refType }: { refType: 'branch' | 'tag' | 'pull' } +): string | null => { if (str === null || str === undefined) return null if (str.startsWith('refs/')) return str switch (refType) { @@ -8,10 +11,5 @@ export const convertRef = ((str, { refType }) => { return `refs/tags/${str}` case 'pull': return `refs/pull/${str}/merge` - default: - return null } -}) satisfies ( - str: string | undefined | null, - { refType }: { refType: 'branch' | 'tag' | 'pull' } -) => string | null +} diff --git a/src/ref.ts b/src/ref.ts index 5fbc163..86c6d31 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -7,7 +7,13 @@ import { } from './schema' import { convertRef } from './internal/utils' -export const getRef = (({ eventName, payload }) => { +export const getRef = ({ + eventName, + payload +}: { + eventName: string + payload: WebhookPayload +}): string | null => { switch (eventName) { case 'check_run': return convertRef( @@ -23,9 +29,6 @@ export const getRef = (({ eventName, payload }) => { { refType: 'branch' } ) case 'create': - return convertRef(v.parse(NullableStringSchema, payload.ref), { - refType: payload.ref_type - }) case 'delete': return convertRef(v.parse(NullableStringSchema, payload.ref), { refType: payload.ref_type @@ -45,17 +48,8 @@ export const getRef = (({ eventName, payload }) => { } ) case 'pull_request': - return convertRef(payload.pull_request?.number.toString(), { - refType: 'pull' - }) case 'pull_request_review': - return convertRef(payload.pull_request?.number.toString(), { - refType: 'pull' - }) case 'pull_request_review_comment': - return convertRef(payload.pull_request?.number.toString(), { - refType: 'pull' - }) case 'pull_request_target': return convertRef(payload.pull_request?.number.toString(), { refType: 'pull' @@ -88,10 +82,4 @@ export const getRef = (({ eventName, payload }) => { default: throw new Error(`${eventName} event is not supported.`) } -}) satisfies ({ - eventName, - payload -}: { - eventName: string - payload: WebhookPayload -}) => string | null +}