@typed-assistant/builder 0.0.40 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/setupWebhook.tsx +27 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed-assistant/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"exports": {
|
|
5
5
|
"./appProcess": "./src/appProcess.tsx",
|
|
6
6
|
"./bunInstall": "./src/bunInstall.tsx",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"home-assistant-js-websocket": "^8.2.0",
|
|
25
25
|
"ts-toolbelt": "^9.6.0",
|
|
26
26
|
"typescript": "^5.3.3",
|
|
27
|
-
"@typed-assistant/eslint-config": "0.0.8",
|
|
28
27
|
"@typed-assistant/logger": "0.0.13",
|
|
29
28
|
"@typed-assistant/typescript-config": "0.0.8",
|
|
30
|
-
"@typed-assistant/utils": "0.0.14"
|
|
29
|
+
"@typed-assistant/utils": "0.0.14",
|
|
30
|
+
"@typed-assistant/eslint-config": "0.0.8"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"home-assistant-js-websocket": "^8.2.0"
|
package/src/setupWebhook.tsx
CHANGED
|
@@ -3,8 +3,6 @@ import { handleFetchError } from "@typed-assistant/utils/getHassAPI"
|
|
|
3
3
|
import { withErrorHandling } from "@typed-assistant/utils/withErrorHandling"
|
|
4
4
|
import { z } from "zod"
|
|
5
5
|
|
|
6
|
-
const webhookUrl = `${process.env.HASS_EXTERNAL_URL}/webhook`
|
|
7
|
-
|
|
8
6
|
const commonOptions = {
|
|
9
7
|
headers: {
|
|
10
8
|
Accept: "application/vnd.github+json",
|
|
@@ -13,7 +11,7 @@ const commonOptions = {
|
|
|
13
11
|
},
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
const webhookIsSetup = async () => {
|
|
14
|
+
const webhookIsSetup = async (webhookUrl: string) => {
|
|
17
15
|
const { error } = await fetch(webhookUrl, {
|
|
18
16
|
...commonOptions,
|
|
19
17
|
body: JSON.stringify({ check: "true" }),
|
|
@@ -22,7 +20,8 @@ const webhookIsSetup = async () => {
|
|
|
22
20
|
.then((d) => d.json())
|
|
23
21
|
|
|
24
22
|
if (error) {
|
|
25
|
-
logger.error(
|
|
23
|
+
logger.error(`🚨 Failed to reach webhook "${webhookUrl}"`)
|
|
24
|
+
logger.error(` ${error.message}`)
|
|
26
25
|
return false
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -49,23 +48,24 @@ const deleteRepoWebhook = async (id: number) =>
|
|
|
49
48
|
),
|
|
50
49
|
)()
|
|
51
50
|
|
|
52
|
-
const deleteAllRepoWebhooks = async () => {
|
|
53
|
-
|
|
51
|
+
// const deleteAllRepoWebhooks = async () => {
|
|
52
|
+
// const { data: webhooks, error } = await listRepoWebhooks()
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
// if (error) {
|
|
55
|
+
// logger.error("🚨 Failed fetching webhooks")
|
|
56
|
+
// logger.error(` ${error.message}`)
|
|
57
|
+
// return
|
|
58
|
+
// }
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
60
|
+
// await Promise.all(
|
|
61
|
+
// webhooks.map(async (webhook) => {
|
|
62
|
+
// await deleteRepoWebhook(webhook.id)
|
|
63
|
+
// logger.info("🚮 Webhook deleted: " + webhook.config.url)
|
|
64
|
+
// }),
|
|
65
|
+
// )
|
|
66
|
+
// }
|
|
67
67
|
|
|
68
|
-
const createRepoWebhook = async () =>
|
|
68
|
+
const createRepoWebhook = async (webhookUrl: string) =>
|
|
69
69
|
withErrorHandling(() =>
|
|
70
70
|
fetch(
|
|
71
71
|
`https://api.github.com/repos/${process.env.GITHUB_USERNAME}/${process.env.GITHUB_REPO}/hooks`,
|
|
@@ -117,7 +117,7 @@ type Webhook = z.infer<typeof Webhook>
|
|
|
117
117
|
|
|
118
118
|
const retryTimeout = 2000
|
|
119
119
|
let retries = 0
|
|
120
|
-
export const setupWebhook = async (): Promise<void> => {
|
|
120
|
+
export const setupWebhook = async (webhookUrl: string): Promise<void> => {
|
|
121
121
|
const { data: webhooks, error } = await listRepoWebhooks()
|
|
122
122
|
|
|
123
123
|
if (error) {
|
|
@@ -129,7 +129,8 @@ export const setupWebhook = async (): Promise<void> => {
|
|
|
129
129
|
setTimeout(setupWebhook, retryTimeout)
|
|
130
130
|
return
|
|
131
131
|
}
|
|
132
|
-
logger.error("🚨 Failed fetching webhooks. Giving up."
|
|
132
|
+
logger.error("🚨 Failed fetching webhooks. Giving up.")
|
|
133
|
+
logger.error(` ${error.message}`)
|
|
133
134
|
return
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -142,9 +143,10 @@ export const setupWebhook = async (): Promise<void> => {
|
|
|
142
143
|
return
|
|
143
144
|
}
|
|
144
145
|
|
|
145
|
-
await webhookIsSetup()
|
|
146
|
+
await webhookIsSetup(webhookUrl)
|
|
146
147
|
|
|
147
|
-
const { data: webhook, error: createError } =
|
|
148
|
+
const { data: webhook, error: createError } =
|
|
149
|
+
await createRepoWebhook(webhookUrl)
|
|
148
150
|
|
|
149
151
|
if (createError) {
|
|
150
152
|
if (retries < 5) {
|
|
@@ -155,9 +157,10 @@ export const setupWebhook = async (): Promise<void> => {
|
|
|
155
157
|
setTimeout(setupWebhook, retryTimeout)
|
|
156
158
|
return
|
|
157
159
|
}
|
|
158
|
-
logger.error("🚨 Failed creating webhook. Giving up."
|
|
160
|
+
logger.error("🚨 Failed creating webhook. Giving up.")
|
|
161
|
+
logger.error(` ${createError.message}`)
|
|
159
162
|
return
|
|
160
163
|
}
|
|
161
164
|
|
|
162
|
-
logger.info("🪝 Webhook created: "
|
|
165
|
+
logger.info("🪝 Webhook created: " + webhook.config.url)
|
|
163
166
|
}
|