Skip to content

Commit ab4b5bf

Browse files
authored
Add configure orientation for devcard (#406)
1 parent 1da8fa4 commit ab4b5bf

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929

3030
### Optional
3131

32+
- `type`: Configure orientation for devcard
33+
- `default`: Vertical (Default)
34+
- `wide`: Horizontal
3235
- `token`: GitHub Token used to commit the devcard
3336
- `commit_branch`: The branch to commit the devcard to. Defaults to the branch of the action.
3437
- `commit_message`: The commit message to use when committing the devcard. Defaults to `Update ${filename}`.

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ inputs:
99
description: 'Your daily.dev user id'
1010
required: true
1111

12+
type:
13+
description: 'Configure orientation for devcard. Must be either "default" or "wide"'
14+
default: default
15+
required: false
16+
1217
token:
1318
description: GitHub Token used to commit the devcard
1419
default: ${{ github.token }}

src/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ process.on('unhandledRejection', (error) => {
1313
throw error
1414
})
1515

16-
const devcardURL = (user_id: string): string =>
17-
`https://api.daily.dev/devcards/v2/${user_id}.png?r=${new Date().valueOf()}&ref=action`
16+
enum DevCardType {
17+
Vertical = 'default',
18+
Horizontal = 'wide',
19+
}
20+
21+
const devcardURL = (user_id: string, type: DevCardType = DevCardType.Vertical): string =>
22+
`https://api.daily.dev/devcards/v2/${user_id}.png?type=${type}&r=${new Date().valueOf()}&ref=action`
1823

1924
;(async function () {
2025
try {
2126
const user_id = core.getInput('user_id')
27+
const type = core.getInput('type') as DevCardType
2228
const token = core.getInput('token')
2329
const branch = core.getInput('commit_branch')
2430
const message = core.getInput('commit_message')
@@ -32,13 +38,18 @@ const devcardURL = (user_id: string): string =>
3238
throw new Error('Filename is required')
3339
}
3440

41+
// throw an error if type is invalid, must be either "default" or "wide"
42+
if (type && !Object.values(DevCardType).includes(type)) {
43+
throw new Error('Invalid type')
44+
}
45+
3546
console.log(`Dryrun`, dryrun)
3647

3748
// Fetch the latest devcard
3849
try {
39-
const { body } = await fetch(devcardURL(user_id))
50+
const { body } = await fetch(devcardURL(user_id, type))
4051
if (body === null) {
41-
const message = `Empty response from devcard URL: ${devcardURL(user_id)}`
52+
const message = `Empty response from devcard URL: ${devcardURL(user_id, type)}`
4253
core.setFailed(message)
4354
console.debug(message)
4455
process.exit(1)

0 commit comments

Comments
 (0)