//const axios = require("axios"); import { logger } from "../utils/logger.utils"; const issueLabels = { bug: 120, enhancement: 122, question: 125, "user-support": 152, "web-user": 153, }; async function processor(data) { logger.debug("issueService.processor: Issue received"); let out = {}; out.labels = [issueLabels[data?.label] || 0, issueLabels["web-user"]]; out.title = data?.subject.replace(/<[^>]+>|[\*\$]/g, ""); out.body = data?.msg.replace(/<[^>]+>|[\*\$]/g, ""); return await sendToGitea(out); } async function sendToGitea(body) { try { const key = process.env.OWL_GIT_ISSUEBOT; const url = process.env.OWL_GIT_APIENDPOINT; const opts = { method: "POST", headers: { Authorization: key, }, body: body, }; const res = await fetch(url, opts); if (res.status === 201) { logger.debug("issueService.sendToGitea: Issue created"); return {status: res.status, message: "issue created"}; } else { logger.error(`issueService.sendtoGitea: Error creating issue RETURN: ${res.status}`); return {status: res.status, message: "issue not created"}; } } catch (err) { logger.error(err, `issueService.sendToGitea`); return {status:500, message: "Internal Server Error"}; } } module.exports = { processor, };