Skip to content

Commit

Permalink
Merge pull request #1355 from 0xStrobe/main
Browse files Browse the repository at this point in the history
let build bot to use fetch
  • Loading branch information
0xStrobe committed Jan 29, 2023
2 parents 7f725cb + 883e69c commit 59b7e4e
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions scripts/build-msg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const axios = require('axios')
const fs = require('fs')

// read the build.log file into base64 string
Expand All @@ -10,20 +9,16 @@ const LOGGER_API_URL = process.env.LOGGER_API_URL

// upload the build.log file to the logger service
const uploadBuildLog = async () => {
const response = await axios.post(
LOGGER_API_URL,
{
data: buildLogBase64,
contentType: BUILD_LOG_CONTENT_TYPE
const response = await fetch(LOGGER_API_URL, {
method: 'POST',
headers: {
'Content-Type': BUILD_LOG_CONTENT_TYPE,
apikey: LOGGER_API_KEY
},
{
headers: {
apikey: LOGGER_API_KEY
}
}
)
// the logger service returns the id of the uploaded file as a string
return response.data
body: buildLogBase64
})
const data = await response.text()
return data
}

// convert the bash script above to JS
Expand Down Expand Up @@ -84,14 +79,22 @@ commitSummary += '\n' + `📸 ${COMMIT_HASH}`
const sendMessages = async () => {
const message = `\`\`\`\n===== COMMIT SUMMARY =====\n${commitSummary}\n\n===== BUILD SUMMARY =====\n${buildSummary}\n\`\`\``
const body = { content: message }
await axios.post(BUILD_STATUS_WEBHOOK, body)
await fetch(BUILD_STATUS_WEBHOOK, {
method: 'POST',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' }
})

const buildLogId = await uploadBuildLog()
const buildLogUrl = `${LOGGER_API_URL}/get/${buildLogId}`
const buildLogMessage = `${EMOJI_PEPENOTES} ${buildLogUrl}`
console.log(buildLogMessage)
const buildLogBody = { content: buildLogMessage }
await axios.post(BUILD_STATUS_WEBHOOK, buildLogBody)
await fetch(BUILD_STATUS_WEBHOOK, {
method: 'POST',
body: JSON.stringify(buildLogBody),
headers: { 'Content-Type': 'application/json' }
})

const authorMention = formatMention(COMMIT_AUTHOR)
const buildLlamasMentions = buildLlamas.map((llama) => formatMention(llama)).join(' ')
Expand All @@ -100,14 +103,22 @@ const sendMessages = async () => {
if (LLAMAS_LIST) {
const llamaMessage = `${EMOJI_CRINGE} ${authorMention}\n${EMOJI_TIRESOME} ${buildLlamasMentions}\n${EMOJI_BINOCULARS} ${BUILD_STATUS_DASHBOARD}`
const llamaBody = { content: llamaMessage }
await axios.post(BUILD_STATUS_WEBHOOK, llamaBody)
await fetch(BUILD_STATUS_WEBHOOK, {
method: 'POST',
body: JSON.stringify(llamaBody),
headers: { 'Content-Type': 'application/json' }
})
}
} else {
const emojis = [EMOJI_LLAMACHEER, EMOJI_BONG, EMOJI_BEEGLUBB, EMOJI_UPLLAMA, EMOJI_EVIL]
const randomEmoji = emojis[Math.floor(Math.random() * emojis.length)]
const llamaMessage = `${randomEmoji}`
const llamaBody = { content: llamaMessage }
await axios.post(BUILD_STATUS_WEBHOOK, llamaBody)
await fetch(BUILD_STATUS_WEBHOOK, {
method: 'POST',
body: JSON.stringify(llamaBody),
headers: { 'Content-Type': 'application/json' }
})
}
}

Expand Down

1 comment on commit 59b7e4e

@vercel
Copy link

@vercel vercel bot commented on 59b7e4e Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.