Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let build bot use fetch #1355

Merged
merged 2 commits into from
Jan 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 29 additions & 18 deletions scripts/build-msg.js
@@ -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