From 82326fd53d2bbdeb3b3af436a21d43440fffadaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ch=C3=A1nh=20=C4=90=E1=BA=A1i?= Date: Tue, 20 Feb 2024 20:43:54 +0700 Subject: [PATCH 1/3] Add configure orientation for devcard --- action.yml | 5 +++++ src/index.ts | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index a65d106..38ed43a 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/src/index.ts b/src/index.ts index f6c79ba..6c96939 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,12 +13,15 @@ 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` +type DevCardType = 'default' | 'wide' + +const devcardURL = (user_id: string, type: DevCardType = 'default'): 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') @@ -32,13 +35,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 && !['default', 'wide'].includes(type)) { + throw new Error('Invalid type. Must be either "default" or "wide"') + } + 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) From afb4946a16e5d5c4d6c12bf87650e24b96daa9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ch=C3=A1nh=20=C4=90=E1=BA=A1i?= Date: Tue, 20 Feb 2024 20:57:53 +0700 Subject: [PATCH 2/3] fix: change 'default' and 'wide' to 'Vertical' and 'Horizontal' respectively 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 --- README.md | 3 +++ action.yml | 4 ++-- src/index.ts | 11 +++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c6cf3cf..89549dd 100644 --- a/README.md +++ b/README.md @@ -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}`. diff --git a/action.yml b/action.yml index 38ed43a..c27b911 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/src/index.ts b/src/index.ts index 6c96939..2f6782f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 () { @@ -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) From 90c9eff47e26e66800ce31debcf2fc45d8ba4a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ch=C3=A1nh=20=C4=90=E1=BA=A1i?= Date: Tue, 20 Feb 2024 21:04:05 +0700 Subject: [PATCH 3/3] docs(README.md): update optional configuration for devcard orientation to use "default" and "wide" values instead of "Vertical" and "Horizontal" fix(action.yml): update input description for type to reflect the new "default" and "wide" values for devcard orientation configuration. --- README.md | 4 ++-- action.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 89549dd..b20edfb 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ jobs: ### Optional - `type`: Configure orientation for devcard - - `Vertical` (Default) - - `Horizontal` + - `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}`. diff --git a/action.yml b/action.yml index c27b911..38ed43a 100644 --- a/action.yml +++ b/action.yml @@ -10,8 +10,8 @@ inputs: required: true type: - description: 'Configure orientation for devcard. Must be either "Vertical" or "Horizontal"' - default: Vertical + description: 'Configure orientation for devcard. Must be either "default" or "wide"' + default: default required: false token: