From 115512f6ea197d7ca7851d2d3d5a673b1bd0a258 Mon Sep 17 00:00:00 2001 From: Niclas Thobaben Date: Sat, 9 Jul 2022 01:06:27 +0200 Subject: [PATCH] implemented issueBranchRef --- README.md | 6 +++++- src/hooks/issueBranchRef.js | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07bb3c8..131d5d8 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,8 @@ issue number and optionally a `bug` label, resulting in the following format: > `feature/{issue}-{title}` the prefix is either`feature` or `bugfix`. Whitespaces in the title are replaced by -`-`. \ No newline at end of file +`-`. + +### issueBranchRef + +References matching branch to an existing issue. \ No newline at end of file diff --git a/src/hooks/issueBranchRef.js b/src/hooks/issueBranchRef.js index 3c47788..9bce6a0 100644 --- a/src/hooks/issueBranchRef.js +++ b/src/hooks/issueBranchRef.js @@ -1,3 +1,5 @@ +const gitea = require('../gitea-api') + const log = (msg) => { console.log('[issueBranchRef]', msg) } @@ -5,10 +7,18 @@ const log = (msg) => { module.exports = { exec: (req) => { - if(req.headers['x-gitea-event'] !== 'issues') { + if(req.headers['x-gitea-event'] !== 'push') { return } - log('issue branch ref') + 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 }) } } \ No newline at end of file