gitea-bot/src/hooks/issueBranchRef.js

24 lines
549 B
JavaScript
Raw Normal View History

2022-07-09 01:06:27 +02:00
const gitea = require('../gitea-api')
2022-07-09 00:43:40 +02:00
const log = (msg) => {
console.log('[issueBranchRef]', msg)
}
module.exports = {
exec: (req) => {
2022-07-09 01:06:27 +02:00
if(req.headers['x-gitea-event'] !== 'push') {
2022-07-09 00:43:40 +02:00
return
}
2022-07-09 01:06:27 +02:00
const { ref, repository } = req.body
log(`Try referencing ref ${ref} to issue`)
const regex = /refs\/heads\/(feature|bugfix)\/(\d+)-/
const issueId = regex.exec(ref)[2]
const path = `/repos/${repository.full_name}/issues/${issueId}`
gitea.patch(path, { ref })
2022-07-09 00:43:40 +02:00
}
}