generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: [email protected] <[email protected]>
- Loading branch information
Showing
6 changed files
with
140 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const convertRef = ((str, { refType }) => { | ||
if (str === null || str === undefined) return null | ||
if (str.startsWith('refs/')) return str | ||
switch (refType) { | ||
case 'branch': | ||
return `refs/heads/${str}` | ||
case 'tag': | ||
return `refs/tags/${str}` | ||
case 'pull': | ||
return `refs/pull/${str}/merge` | ||
default: | ||
return null | ||
} | ||
}) satisfies ( | ||
str: string | undefined | null, | ||
{}: { refType: 'branch' | 'tag' | 'pull' } | ||
Check failure on line 16 in src/internal/utils.ts GitHub Actions / Lint Codebase
|
||
) => string | null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as v from 'valibot' | ||
import { WebhookPayload } from '@actions/github/lib/interfaces' | ||
import { | ||
OptionalStringSchema, | ||
NullableStringSchema, | ||
StringSchema | ||
} from './schema' | ||
import { convertRef } from './internal/utils' | ||
|
||
export const getRef = (({ eventName, payload }) => { | ||
switch (eventName) { | ||
case 'check_run': | ||
return convertRef( | ||
v.parse( | ||
NullableStringSchema, | ||
payload.check_run.check_suite.head_branch | ||
), | ||
{ refType: 'branch' } | ||
) | ||
case 'check_suite': | ||
return convertRef( | ||
v.parse(NullableStringSchema, payload.check_suite.head_branch), | ||
{ 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 | ||
}) | ||
case 'deployment_status': | ||
return convertRef( | ||
v.parse(OptionalStringSchema, payload.workflow_run?.head_branch), | ||
{ | ||
refType: 'branch' | ||
} | ||
) | ||
case 'issue_comment': | ||
return convertRef( | ||
v.parse(StringSchema, payload.issue?.number.toString()), | ||
{ | ||
refType: 'pull' | ||
} | ||
) | ||
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' | ||
}) | ||
case 'push': | ||
return v.parse(StringSchema, payload.ref) | ||
case 'registry_package': | ||
return convertRef( | ||
v.parse( | ||
OptionalStringSchema, | ||
payload.registry_package?.package_version?.release?.tag_name | ||
), | ||
{ | ||
refType: 'tag' | ||
} | ||
) | ||
case 'release': | ||
return convertRef(v.parse(StringSchema, payload.release.tag_name), { | ||
refType: 'tag' | ||
}) | ||
case 'workflow_dispatch': | ||
return v.parse(StringSchema, payload.ref) | ||
case 'workflow_run': | ||
return convertRef( | ||
v.parse(NullableStringSchema, payload.workflow_run.head_branch), | ||
{ | ||
refType: 'branch' | ||
} | ||
) | ||
default: | ||
throw new Error(`${eventName} event is not supported.`) | ||
} | ||
}) satisfies ({}: { | ||
Check failure on line 91 in src/ref.ts GitHub Actions / Lint Codebase
|
||
eventName: string | ||
payload: WebhookPayload | ||
}) => string | null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { nullable, optional, string } from 'valibot' | ||
|
||
export const StringSchema = string() | ||
export const OptionalStringSchema = optional(string()) | ||
export const NullableStringSchema = nullable(string()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters