diff options
author | Timo Rothenpieler <timo@rothenpieler.org> | 2025-08-08 21:37:20 +0200 |
---|---|---|
committer | Timo Rothenpieler <timo@rothenpieler.org> | 2025-08-09 23:18:57 +0200 |
commit | e992464f0faad27856b51b1f117a4a2f32add5f2 (patch) | |
tree | 3c0b025ba4fa9bde5009b7676351d2391d497d15 | |
parent | 638b521c7b09e00514aa13ade43c389b4b40ddfd (diff) | |
download | ffmpeg-e992464f0faad27856b51b1f117a4a2f32add5f2.tar.gz |
forgejo/autolabeler: add some logic to also auto-remove the "New" label
-rw-r--r-- | .forgejo/labeler/labeler.js | 71 | ||||
-rw-r--r-- | .forgejo/workflows/autolabel.yml | 6 |
2 files changed, 59 insertions, 18 deletions
diff --git a/.forgejo/labeler/labeler.js b/.forgejo/labeler/labeler.js index 7e17c4167c..578ec29096 100644 --- a/.forgejo/labeler/labeler.js +++ b/.forgejo/labeler/labeler.js @@ -1,27 +1,66 @@ module.exports = async ({github, context}) => { const title = (context.payload.pull_request?.title || context.payload.issue?.title || '').toLowerCase(); const labels = []; + const issueNumber = context.payload.pull_request?.number || context.payload.issue?.number; - const kwmap = { - 'avcodec': 'avcodec', - 'avdevice': 'avdevice', - 'avfilter': 'avfilter', - 'avformat': 'avformat', - 'avutil': 'avutil', - 'swresample': 'swresample', - 'swscale': 'swscale', - 'fftools': 'CLI' - }; + async function isOrgMember(username) { + try { + const response = await github.rest.orgs.checkMembershipForUser({ + org: context.repo.owner, + username: username + }); + return response.status === 204; + } catch (error) { + return false; + } + } + + var removeNew = context.payload.action === 'closed'; + + if (context.payload.action !== 'opened' && await isOrgMember(context.payload.sender.login)) { + if (context.payload.action === 'assigned' || + context.payload.action === 'labeled' || + context.payload.action === 'unlabeled' || + context.payload.comment) { + removeNew = true; + console.log('Removing "new" label due to member interaction.'); + } + } - if (context.payload.action === 'opened') { + if (removeNew) { + try { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + name: 'new' + }); + console.log('Removed "new" label'); + } catch (error) { + console.log('Could not remove "new" label'); + } + } else if (context.payload.action === 'opened') { labels.push('new'); console.log('Detected label: new'); } - for (const [kw, label] of Object.entries(kwmap)) { - if (title.includes(kw)) { - labels.push(label); - console.log('Detected label: ' + label); + if (context.payload.action === 'opened' || context.payload.action === 'edited') { + const kwmap = { + 'avcodec': 'avcodec', + 'avdevice': 'avdevice', + 'avfilter': 'avfilter', + 'avformat': 'avformat', + 'avutil': 'avutil', + 'swresample': 'swresample', + 'swscale': 'swscale', + 'fftools': 'CLI' + }; + + for (const [kw, label] of Object.entries(kwmap)) { + if (title.includes(kw)) { + labels.push(label); + console.log('Detected label: ' + label); + } } } @@ -29,7 +68,7 @@ module.exports = async ({github, context}) => { await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.payload.pull_request?.number || context.payload.issue?.number, + issue_number: issueNumber, labels: labels, }); } diff --git a/.forgejo/workflows/autolabel.yml b/.forgejo/workflows/autolabel.yml index 3eb8cd52ba..1651bc5164 100644 --- a/.forgejo/workflows/autolabel.yml +++ b/.forgejo/workflows/autolabel.yml @@ -1,8 +1,10 @@ on: pull_request_target: - types: [opened, edited, synchronize] + types: [opened, edited, synchronize, closed, assigned, labeled, unlabeled] issues: - types: [opened, edited] + types: [opened, edited, closed, assigned, labeled, unlabeled] + issue_comment: + types: [created] jobs: pr_labeler: |