2023-02-09 20:34:53 +00:00
|
|
|
const axios = require('axios')
|
|
|
|
const log = require('../utils/log.utils')
|
|
|
|
|
|
|
|
async function processor(data) {
|
|
|
|
log.out(`issueService.processor: Issue received`)
|
|
|
|
let out = {}
|
|
|
|
out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, '');
|
|
|
|
out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '')
|
2023-03-02 20:56:47 +00:00
|
|
|
return await sendToGitea(out);
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
return {status: res.status,message:"issue created"}
|
|
|
|
} else {
|
2023-03-02 20:56:47 +00:00
|
|
|
log.out(`issueService.sendToGitea: Failed to send issue to Gitea: ${res.body}`)
|
2023-02-09 20:34:53 +00:00
|
|
|
return {status: res.status,message:"issue not created"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
processor
|
|
|
|
}
|