backend/src/services/issue.services.js
Fred Boniface e38946d4df Change issue.services from Axios to Fetch
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-09-28 11:41:48 +01:00

47 lines
1.3 KiB
JavaScript

/* eslint-disable no-useless-escape */
//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) {
let key = process.env.OWL_GIT_ISSUEBOT;
let url = process.env.OWL_GIT_APIENDPOINT;
let opts = {
headers: {
Authorization: key,
},
body: body,
};
//var res = await axios.post(url, body, opts);
const res = await fetch(url, opts);
/* Need to read the output from the POST and pass the result upwards to the
client.*/
if (res.status == 201) {
logger.info("issueService.sendToGitea: Issue sent to Gitea");
return { status: res.status, message: "issue created" };
} else {
logger.error(res.body, "issueService.sendToGitea: Fail to send issue");
return { status: res.status, message: "issue not created" };
}
}
module.exports = {
processor,
};