diff options
author | Timo Rothenpieler <timo@rothenpieler.org> | 2025-08-08 21:37:20 +0200 |
---|---|---|
committer | Timo Rothenpieler <timo@rothenpieler.org> | 2025-08-10 01:50:46 +0200 |
commit | 274e00ea84cab4f198ffab5a9a508445703a596e (patch) | |
tree | 619365a897c8cf602820119c25201081f301a537 | |
parent | 26a2a76346457e33408ca9ef5453b1d14cca2504 (diff) | |
download | ffmpeg-274e00ea84cab4f198ffab5a9a508445703a596e.tar.gz |
forgejo/autolabeler: clean up logic a bit and prevent self-looping
The loop-protection only takes effect for the automatic token, not for
ffmpeg-devels PAT.
-rw-r--r-- | .forgejo/labeler/labeler.js | 51 | ||||
-rw-r--r-- | .forgejo/workflows/autolabel.yml | 1 |
2 files changed, 25 insertions, 27 deletions
diff --git a/.forgejo/labeler/labeler.js b/.forgejo/labeler/labeler.js index 578ec29096..b1c05787f0 100644 --- a/.forgejo/labeler/labeler.js +++ b/.forgejo/labeler/labeler.js @@ -3,6 +3,17 @@ module.exports = async ({github, context}) => { 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({ @@ -15,47 +26,33 @@ module.exports = async ({github, context}) => { } } - 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 (removeNew) { + if (context.payload.action === 'closed' || + (context.payload.action !== 'opened' && ( + context.payload.action === 'assigned' || + context.payload.action === 'label_updated' || + context.payload.comment) && + await isOrgMember(context.payload.sender.login)) + ) { try { await github.rest.issues.removeLabel({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumber, - name: 'new' + // this should say 'new', but forgejo deviates from GitHub API here and expects the ID + name: '41' }); console.log('Removed "new" label'); } catch (error) { - console.log('Could not remove "new" label'); + if (error.status !== 404 && error.status !== 410) { + console.log('Could not remove "new" label'); + } } } else if (context.payload.action === 'opened') { labels.push('new'); console.log('Detected label: new'); } - 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' - }; - + if ((context.payload.action === 'opened' || context.payload.action === 'edited') && context.eventName !== 'issue_comment') { for (const [kw, label] of Object.entries(kwmap)) { if (title.includes(kw)) { labels.push(label); diff --git a/.forgejo/workflows/autolabel.yml b/.forgejo/workflows/autolabel.yml index 1651bc5164..cb4dac67aa 100644 --- a/.forgejo/workflows/autolabel.yml +++ b/.forgejo/workflows/autolabel.yml @@ -9,6 +9,7 @@ on: jobs: pr_labeler: runs-on: utilities + if: ${{ github.event.sender.login != 'ffmpeg-devel' }} steps: - name: Checkout uses: actions/checkout@v4 |