implemented PR issue ref
parent
f92f30b1a7
commit
e416aaca43
|
@ -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 })
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue