const axios  = require('axios')

async function processor(data) {
    let out = {}
    out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, '');
    out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '')
    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) {
        return {status: res.status,message:"issue created"}
    } else {
        return {status: res.status,message:"issue not created"}
    }
}

module.exports = {
    processor
}