Skip to content

Commit

Permalink
fix: change 'default' and 'wide' to 'Vertical' and 'Horizontal' respe…
Browse files Browse the repository at this point in the history
…ctively

feat: use enum for DevCardType to improve type safety and readability
feat: update devcardURL function to use DevCardType enum and default to Vertical
feat: update action.yml description for type input to reflect available options Vertical and Horizontal
  • Loading branch information
ncdai committed Feb 20, 2024
1 parent 82326fd commit afb4946
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:

### Optional

- `type`: Configure orientation for devcard
- `Vertical` (Default)
- `Horizontal`
- `token`: GitHub Token used to commit the devcard
- `commit_branch`: The branch to commit the devcard to. Defaults to the branch of the action.
- `commit_message`: The commit message to use when committing the devcard. Defaults to `Update ${filename}`.
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ inputs:
required: true

type:
description: 'Configure orientation for devcard. Must be either "default" or "wide"'
default: default
description: 'Configure orientation for devcard. Must be either "Vertical" or "Horizontal"'
default: Vertical
required: false

token:
Expand Down
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ process.on('unhandledRejection', (error) => {
throw error
})

type DevCardType = 'default' | 'wide'
enum DevCardType {
Vertical = 'default',
Horizontal = 'wide',
}

const devcardURL = (user_id: string, type: DevCardType = 'default'): string =>
const devcardURL = (user_id: string, type: DevCardType = DevCardType.Vertical): string =>
`https://api.daily.dev/devcards/v2/${user_id}.png?type=${type}&r=${new Date().valueOf()}&ref=action`

;(async function () {
Expand All @@ -36,8 +39,8 @@ const devcardURL = (user_id: string, type: DevCardType = 'default'): string =>
}

// throw an error if type is invalid, must be either "default" or "wide"
if (type && !['default', 'wide'].includes(type)) {
throw new Error('Invalid type. Must be either "default" or "wide"')
if (type && !Object.values(DevCardType).includes(type)) {
throw new Error('Invalid type')
}

console.log(`Dryrun`, dryrun)
Expand Down

0 comments on commit afb4946

Please sign in to comment.