implemented PR issue ref
nclazz/gitea-bot/pipeline/head This commit looks good Details

master
Niclas Thobaben 2022-07-09 12:17:51 +02:00
parent f92f30b1a7
commit e416aaca43
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
const gitea = require('../gitea-api')
const log = (msg) => {
console.log('[issuePrRef]', msg)
}
module.exports = {
exec: (req) => {
if(req.headers['x-gitea-event'] !== 'pull_request') {
return
}
const { pull_request } = req.body
log(`Try referencing ref ${pull_request.head.ref} to issue`)
const regex = /refs\/heads\/(feature|bugfix)\/ISS-(\d+)-/
const issueId = regex.exec(ref)[2]
let body = pull_request.body
if(body.includes('> <code>')) {
body = body.replaceAll(/> <code>.+<\/code>/g, `> <code>issue #${issueId}</code>`)
}else {
body += '\n\n'
body += `> <code>issue #${issueId}</code>`
}
const path = `/repos/${repository.full_name}/pulls/${pull_request.number}`
gitea.patch(path, { body })
}
}