You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
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.
This commit is contained in:
@@ -3,6 +3,17 @@ module.exports = async ({github, context}) => {
|
|||||||
const labels = [];
|
const labels = [];
|
||||||
const issueNumber = context.payload.pull_request?.number || context.payload.issue?.number;
|
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) {
|
async function isOrgMember(username) {
|
||||||
try {
|
try {
|
||||||
const response = await github.rest.orgs.checkMembershipForUser({
|
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 === 'closed' ||
|
||||||
|
(context.payload.action !== 'opened' && (
|
||||||
if (context.payload.action !== 'opened' && await isOrgMember(context.payload.sender.login)) {
|
context.payload.action === 'assigned' ||
|
||||||
if (context.payload.action === 'assigned' ||
|
context.payload.action === 'label_updated' ||
|
||||||
context.payload.action === 'labeled' ||
|
context.payload.comment) &&
|
||||||
context.payload.action === 'unlabeled' ||
|
await isOrgMember(context.payload.sender.login))
|
||||||
context.payload.comment) {
|
) {
|
||||||
removeNew = true;
|
|
||||||
console.log('Removing "new" label due to member interaction.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeNew) {
|
|
||||||
try {
|
try {
|
||||||
await github.rest.issues.removeLabel({
|
await github.rest.issues.removeLabel({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
issue_number: issueNumber,
|
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');
|
console.log('Removed "new" label');
|
||||||
} catch (error) {
|
} 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') {
|
} else if (context.payload.action === 'opened') {
|
||||||
labels.push('new');
|
labels.push('new');
|
||||||
console.log('Detected label: new');
|
console.log('Detected label: new');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.payload.action === 'opened' || context.payload.action === 'edited') {
|
if ((context.payload.action === 'opened' || context.payload.action === 'edited') && context.eventName !== 'issue_comment') {
|
||||||
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)) {
|
for (const [kw, label] of Object.entries(kwmap)) {
|
||||||
if (title.includes(kw)) {
|
if (title.includes(kw)) {
|
||||||
labels.push(label);
|
labels.push(label);
|
||||||
|
@@ -9,6 +9,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
pr_labeler:
|
pr_labeler:
|
||||||
runs-on: utilities
|
runs-on: utilities
|
||||||
|
if: ${{ github.event.sender.login != 'ffmpeg-devel' }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
Reference in New Issue
Block a user