2023-05-06 21:54:49 +01:00
|
|
|
/* eslint-disable no-useless-escape */
|
|
|
|
const axios = require('axios');
|
|
|
|
const log = require('../utils/log.utils');
|
2023-02-09 20:34:53 +00:00
|
|
|
|
|
|
|
async function processor(data) {
|
2023-05-06 21:54:49 +01:00
|
|
|
log.out('issueService.processor: Issue received', 'info');
|
2023-06-26 16:02:42 +01:00
|
|
|
console.log(data); // TEMPORARY MEASURE
|
2023-05-06 21:54:49 +01:00
|
|
|
let out = {};
|
2023-06-26 16:03:03 +01:00
|
|
|
out.labels = data?.labels || [];
|
2023-06-26 16:02:42 +01:00
|
|
|
out.title = data?.subject.replace(/<[^>]+>|[\*\$]/g, '');
|
|
|
|
out.body = data?.msg.replace(/<[^>]+>|[\*\$]/g, '');
|
2023-05-06 21:54:49 +01:00
|
|
|
return await sendToGitea(out);
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function sendToGitea(body) {
|
2023-05-06 21:54:49 +01:00
|
|
|
let key = process.env.OWL_GIT_ISSUEBOT;
|
|
|
|
let url = process.env.OWL_GIT_APIENDPOINT;
|
|
|
|
let opts = {
|
|
|
|
headers: {
|
|
|
|
Authorization: key
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
2023-05-06 21:54:49 +01:00
|
|
|
};
|
|
|
|
var res = await axios.post(url, body, opts);
|
2023-06-07 21:53:56 +01:00
|
|
|
/* Need to read the output from the POST and pass the result upwards to the
|
|
|
|
client.*/
|
2023-05-06 21:54:49 +01:00
|
|
|
if (res.status == 201) {
|
|
|
|
log.out('issueService.sendToGitea: Issue sent to Gitea', 'info');
|
|
|
|
return {status: res.status,message:'issue created'};
|
|
|
|
} else {
|
2023-06-07 21:53:56 +01:00
|
|
|
log.out(`issueService.sendToGitea: Fail to send issue: ${res.body}`, 'err');
|
2023-05-06 21:54:49 +01:00
|
|
|
return {status: res.status,message:'issue not created'};
|
|
|
|
}
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2023-05-06 21:54:49 +01:00
|
|
|
processor
|
|
|
|
};
|