const axios = require('axios') class Gitea { constructor(api, key) { this.api = `${api}/repos` this.key = key } checkLabelExistance(label, repo) { return new Promise((resolve, reject) => { axios.get( `${this.api}/${repo}/labels`, {headers: {"Authorization" : `token ${this.key}`} }) .then((response) => { response.data.forEach((el) => { if (el.name == label) resolve(true) }) resolve(false) }) .catch(e => console.log(e)) }) } // check if label exists in repo, if not, craete it. Needs label name, label color, repo url and api key. createLabel(label, color, repo) { this.checkLabelExistance(label, repo).then((exists) => { if(!exists) { axios.post( `${this.api}/${repo}/labels`, {color: color,name: label}, {"headers": {"Authorization" : `token ${this.key}`} }) .then(console.log(`Label ${label} created`)) } }) .catch(e => console.log(e)) } labelStatus(label, repo, issue) { return new Promise((resolve, reject) => { axios.get( `${this.api}/${repo}/issues/${issue}`, {headers: {"Authorization" : `token ${this.key}`} }) .then((response) => { response.data.labels.forEach((el) => { if (el.name == label) resolve(true) }) resolve(false) }) .catch(e => console.log(e)) }) } comment(message, repo, issue) { axios.post( `${this.api}/${repo}/issues/${issue}/comments`, {body: message}, {"headers": {"Authorization" : `token ${this.key}`} }) .then(console.log(`Message posted`)) .catch(e => console.log(e)) } } module.exports = Gitea