Skip to content

Commit

Permalink
[bug]: Add validation for inputs and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
danibonilha committed Dec 28, 2023
1 parent 9006d87 commit 8372672
Showing 6 changed files with 49 additions and 18 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -41,3 +41,20 @@ 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'
webhookUrl: ${{ secrets.HUBOT_WEBHOOK_URl }}
webhookAuth: ${{ secrets.HUBOT_WEBHOOK_AUTH }}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -5,8 +5,7 @@ inputs:
threadName:
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:
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 12 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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<void>} Resolves when the action is complete.
*/
export async function createThread(): Promise<void> {
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: getRequiredInput('threadName'),
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

0 comments on commit 8372672

Please sign in to comment.