newStaffLDB-API #48

Merged
fred.boniface merged 85 commits from newStaffLDB-API into main 2023-10-03 21:35:03 +01:00
1 changed files with 23 additions and 20 deletions
Showing only changes of commit be9fb68c3d - Show all commits

View File

@ -1,4 +1,3 @@
/* eslint-disable no-useless-escape */
//const axios = require("axios");
import { logger } from "../utils/logger.utils";
@ -20,26 +19,30 @@ async function processor(data) {
}
async function sendToGitea(body) {
let key = process.env.OWL_GIT_ISSUEBOT;
let url = process.env.OWL_GIT_APIENDPOINT;
let opts = {
try {
const key = process.env.OWL_GIT_ISSUEBOT;
const url = process.env.OWL_GIT_APIENDPOINT;
const opts = {
method: "POST",
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");
if (res.status === 201) {
logger.debug("issueService.sendToGitea: Issue created");
return {status: res.status, message: "issue created"};
} else {
logger.error(res.body, "issueService.sendToGitea: Fail to send issue");
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 = {