Trying a few fixes

This commit is contained in:
tsickert 2024-03-30 15:32:05 +00:00
parent f4badf5fa9
commit c5be16bcd9
3 changed files with 20 additions and 16 deletions

View file

@ -1,5 +1,4 @@
import {executeWebhook} from '../src/webhook'
import {expect, test} from '@jest/globals'
test('fails with missing URL', async () => {
await expect(executeWebhook()).rejects.toThrow('Invalid URL')

View file

@ -3,6 +3,7 @@ import {createReadStream, readFileSync} from 'fs'
import FormData from 'form-data'
import {HttpClient} from '@actions/http-client'
import {TypedResponse} from '@actions/http-client/lib/interfaces'
import http from 'http'
const WEBHOOK_URL = 'webhook-url'
const CONTENT = 'content'
@ -156,20 +157,23 @@ export async function executeWebhook(): Promise<void> {
if (flags !== '') {
formData.append('flags', Number(flags))
}
formData.submit(webhookUrl, function (error, response) {
if (error != null) {
if (filename !== '') {
core.error(`failed to upload file: ${error.message}`)
formData.submit(
webhookUrl,
function (error: Error | null, response: http.IncomingMessage) {
if (error != null) {
if (filename !== '') {
core.error(`failed to upload file: ${error.message}`)
}
if (threadName !== '') {
core.error(`failed to create thread: ${threadName}`)
}
} else if (filename !== '') {
core.info(
`successfully uploaded file with status code: ${response.statusCode}`
)
}
if (threadName !== '') {
core.error(`failed to create thread: ${threadName}`)
}
} else if (filename !== '') {
core.info(
`successfully uploaded file with status code: ${response.statusCode}`
)
}
})
)
} else {
try {
const response = await client.postJson(webhookUrl, payload)
@ -189,4 +193,4 @@ async function run(): Promise<void> {
}
}
run()
await run()

View file

@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "es2022", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"moduleResolution": "node",
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */