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 cd7e138
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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: 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
Expand Down

0 comments on commit cd7e138

Please sign in to comment.