parent
e6287654c1
commit
97d4d6a99d
@ -0,0 +1,33 @@
|
||||
class Gitea {
|
||||
|
||||
constructor(url, user, pass) { // Nextcloud's base URL, not the api!
|
||||
this.api = `${url}/index.php/apps/deck/api/v1.0`
|
||||
this.user = user
|
||||
this.pass = pass
|
||||
}
|
||||
|
||||
checkTagExist() {
|
||||
|
||||
}
|
||||
|
||||
createTag() {
|
||||
|
||||
}
|
||||
|
||||
checkCardExist() {
|
||||
|
||||
}
|
||||
|
||||
createCard(board, card, title, tags) {
|
||||
|
||||
}
|
||||
|
||||
closeCard() {
|
||||
|
||||
}
|
||||
|
||||
deleteCard() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
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
|
@ -0,0 +1,54 @@
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const axios = require('axios')
|
||||
const app = express()
|
||||
|
||||
const Gitea = require('./gitea.js')
|
||||
const gitea = new Gitea("https://yourgiteainstall.com/api/v1", 'apikey')
|
||||
|
||||
const ncUser = ""
|
||||
const ncPass = ""
|
||||
const ncApi = "https://yournextcloudinstall.com/index.php/apps/deck/api/v1.0"
|
||||
const ncBoard = 2
|
||||
|
||||
|
||||
app.use(bodyParser.json())
|
||||
app.use(function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*")
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
||||
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, HEAD')
|
||||
next()
|
||||
})
|
||||
|
||||
// gitea only POSTs and only to a single URL. We'll need to parse json for more info on what's happening
|
||||
app.post("/", (req, res) => {
|
||||
let repo = req.body.repository.full_name
|
||||
let issue = req.body.issue.number
|
||||
let action = req.body.action
|
||||
gitea.createLabel('Deck',"#0082C9", repo) // Double check existace of issue label, if not; create.
|
||||
console.log(`${req.body.action} | [${req.body.repository.full_name}] #${req.body.issue.number}:${req.body.issue.title}`)
|
||||
// console.log(`(${req.body.issue.url})`)
|
||||
|
||||
|
||||
if(action == "label_updated" || action == "reopened" || action == "opened" || action == "label_cleared") {
|
||||
gitea.labelStatus('Deck', repo, issue).then((set) => {
|
||||
if(set) {
|
||||
console.log("Label Deck detected")
|
||||
gitea.comment(`Issue added to deck :-)`, repo, issue)
|
||||
} else {
|
||||
console.log("Label Deck not detected")
|
||||
}
|
||||
})
|
||||
}
|
||||
else if(action == 'closed'){
|
||||
console.log('Issue closed')
|
||||
}
|
||||
else {
|
||||
console.log(`Received unsupported action "${action}"`)
|
||||
// console.log(JSON.stringify(req.headers, null,2))
|
||||
// console.log(JSON.stringify(req.body, null,2))
|
||||
}
|
||||
res.send("okay") // generate some feedback for gitea
|
||||
})
|
||||
|
||||
app.listen(80, () => console.log(`Aapie running on 80`))
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue