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