backend/src/services/issue.services.js

33 lines
1.0 KiB
JavaScript
Raw Normal View History

const axios = require('axios')
const log = require('../utils/log.utils')
async function processor(data) {
log.out(`issueService.processor: Issue received`, "info")
let out = {}
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
}
}
var res = await axios.post(url, body, opts)
// Need to read the output from the POST and pass the result upwards to the client.
if (res.status == 201) {
log.out("issueService.sendToGitea: Issue sent to Gitea", "info")
return {status: res.status,message:"issue created"}
} else {
log.out(`issueService.sendToGitea: Failed to send issue to Gitea: ${res.body}`, "err")
return {status: res.status,message:"issue not created"}
}
}
module.exports = {
processor
}