Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configure orientation for devcard #406

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
- `default`: Vertical (Default)
- `wide`: 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
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ inputs:
description: 'Your daily.dev user id'
required: true

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

token:
description: GitHub Token used to commit the devcard
default: ${{ github.token }}
Expand Down
19 changes: 15 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ process.on('unhandledRejection', (error) => {
throw error
})

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

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 () {
try {
const user_id = core.getInput('user_id')
const type = core.getInput('type') as DevCardType
const token = core.getInput('token')
const branch = core.getInput('commit_branch')
const message = core.getInput('commit_message')
Expand All @@ -32,13 +38,18 @@ const devcardURL = (user_id: string): string =>
throw new Error('Filename is required')
}

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

console.log(`Dryrun`, dryrun)

// Fetch the latest devcard
try {
const { body } = await fetch(devcardURL(user_id))
const { body } = await fetch(devcardURL(user_id, type))
if (body === null) {
const message = `Empty response from devcard URL: ${devcardURL(user_id)}`
const message = `Empty response from devcard URL: ${devcardURL(user_id, type)}`
core.setFailed(message)
console.debug(message)
process.exit(1)
Expand Down