From e5bc28ccf6d4b0c91944ecbb39ce00757faf014f Mon Sep 17 00:00:00 2001 From: danibonilha Date: Thu, 28 Dec 2023 10:17:48 -0300 Subject: [PATCH] WIP --- .github/workflows/ci.yml | 20 +++++++++++++++++++- README.md | 6 +++--- action.yml | 2 +- badges/coverage.svg | 2 +- dist/index.js | 18 ++++++++++++------ src/main.ts | 21 +++++++++++++++------ 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c002e65..5edaeaf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - main + - dani/setup-th-action permissions: contents: read @@ -41,3 +41,21 @@ jobs: - name: Test id: npm-ci-test run: npm run ci-test + test-action: + name: GitHub Actions Test + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Test Local Action + id: test-action + uses: ./ + with: + threadName: 'v1.0-test-action' + channelName: 'bifrost' + title: 'ci-test-action' + webhookUrl: ${{ secrets.HUBOT_WEBHOOK_URl }} + webhookAuth: ${{ secrets.HUBOT_WEBHOOK_AUTH }} diff --git a/README.md b/README.md index b09d23b..292b2fd 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ steps: uses: thesis/valyrie-thread-action@v1 with: threadName: 'v1.0' - channellName: 'release' + channelName: 'release' message: 'release notes' - webhookUrl: { { secrets.WEBHOOK_URL } } - webhookAuth: { { secrets.WEBHOOK_AUTH } } + webhookUrl: ${{ secrets.WEBHOOK_URL }} + webhookAuth: ${{ secrets.WEBHOOK_AUTH }} ``` ## Initial Local Setup diff --git a/action.yml b/action.yml index 62b12dc..f55c5f2 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ inputs: description: 'The name of the thread.' required: true default: 'release' - channellName: + channelName: description: 'The name of the channel to create the thread in.' required: true message: diff --git a/badges/coverage.svg b/badges/coverage.svg index 1063f3d..8c73e34 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -Coverage: 36.36%Coverage36.36% \ No newline at end of file +Coverage: 33.33%Coverage33.33% \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 30b8624..e769aa2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2753,26 +2753,32 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.createThread = void 0; const core = __importStar(__nccwpck_require__(186)); +const getRequiredInput = (name) => core.getInput(name, { required: true }); /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. */ async function createThread() { try { - const webhookUrl = core.getInput('webhookUrl'); - const webhookAuth = core.getInput('webhookAuth'); - await fetch(webhookUrl, { + const webhookUrl = getRequiredInput('webhookUrl'); + const webhookAuth = getRequiredInput('webhookAuth'); + const response = await fetch(webhookUrl, { method: 'POST', headers: { + 'Content-type': 'application/json', Accept: 'application/json', Authorization: webhookAuth }, body: JSON.stringify({ - channelName: core.getInput('channelName'), - title: core.getInput('threadName'), - message: core.getInput('message') + channelName: getRequiredInput('channelName'), + title: core.getInput('title'), + message: core.getInput('message'), + tagUser: '0' }) }); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } core.info('Thread created'); } catch (error) { diff --git a/src/main.ts b/src/main.ts index 836287c..d916ebe 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,27 +1,36 @@ import * as core from '@actions/core' +const getRequiredInput = (name: string): string => + core.getInput(name, { required: true }) + /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. */ export async function createThread(): Promise { try { - const webhookUrl: string = core.getInput('webhookUrl') - const webhookAuth: string = core.getInput('webhookAuth') + const webhookUrl = getRequiredInput('webhookUrl') + const webhookAuth = getRequiredInput('webhookAuth') - await fetch(webhookUrl, { + const response = await fetch(webhookUrl, { method: 'POST', headers: { + 'Content-type': 'application/json', Accept: 'application/json', Authorization: webhookAuth }, body: JSON.stringify({ - channelName: core.getInput('channelName'), - title: core.getInput('threadName'), - message: core.getInput('message') + channelName: getRequiredInput('channelName'), + title: core.getInput('title'), + message: core.getInput('message'), + tagUser: '0' }) }) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + core.info('Thread created') } catch (error) { // Fail the workflow run if an error occurs