feat: AI moderator supports discussions and discussion comments
This commit is contained in:
@@ -7,10 +7,15 @@ on:
|
|||||||
types: [created]
|
types: [created]
|
||||||
pull_request_review_comment:
|
pull_request_review_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
discussion:
|
||||||
|
types: [created]
|
||||||
|
discussion_comment:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
issues: write
|
issues: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
discussions: write
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -25,7 +30,11 @@ jobs:
|
|||||||
script: |
|
script: |
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const coc = (() => { try { return fs.readFileSync('.github/CODE_OF_CONDUCT.md', 'utf8'); } catch (e) { return ''; } })();
|
||||||
|
const contributing = (() => { try { return fs.readFileSync('CONTRIBUTING.md', 'utf8'); } catch (e) { return ''; } })();
|
||||||
|
|
||||||
const content = context.payload.issue?.body
|
const content = context.payload.issue?.body
|
||||||
|
|| context.payload.discussion?.body
|
||||||
|| context.payload.comment?.body
|
|| context.payload.comment?.body
|
||||||
|| '';
|
|| '';
|
||||||
if (!content.trim()) {
|
if (!content.trim()) {
|
||||||
@@ -33,12 +42,8 @@ jobs:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let coc = '';
|
const isComment = context.payload.comment !== undefined;
|
||||||
let contributing = '';
|
const isDiscussion = context.payload.discussion !== undefined;
|
||||||
try { coc = fs.readFileSync('.github/CODE_OF_CONDUCT.md', 'utf8'); } catch (e) {}
|
|
||||||
try { contributing = fs.readFileSync('CONTRIBUTING.md', 'utf8'); } catch (e) {}
|
|
||||||
|
|
||||||
const isComment = !!context.payload.comment;
|
|
||||||
|
|
||||||
const prompt = [
|
const prompt = [
|
||||||
'You are an AI moderator for the Antergos NeXT project.',
|
'You are an AI moderator for the Antergos NeXT project.',
|
||||||
@@ -64,7 +69,7 @@ jobs:
|
|||||||
' "severity": 1-10',
|
' "severity": 1-10',
|
||||||
'}',
|
'}',
|
||||||
'',
|
'',
|
||||||
'"action" options: "warn" (post warning), "hide" (minimize comment), "lock" (lock issue)',
|
'"action" options: "warn" (post warning), "hide" (minimize comment), "lock" (lock issue/discussion)',
|
||||||
'For issues use "warn" or "lock". For comments you may use "hide".',
|
'For issues use "warn" or "lock". For comments you may use "hide".',
|
||||||
'',
|
'',
|
||||||
'Content:',
|
'Content:',
|
||||||
@@ -106,27 +111,33 @@ jobs:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const issueNumber = context.payload.issue?.number
|
const number = context.payload.issue?.number
|
||||||
|| context.payload.pull_request?.number;
|
|| context.payload.pull_request?.number
|
||||||
if (!issueNumber) {
|
|| context.payload.discussion?.number;
|
||||||
console.log('No issue/PR number found');
|
if (!number) {
|
||||||
|
console.log('No issue/PR/discussion number found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const owner = context.repo.owner;
|
||||||
await github.rest.issues.addLabels({
|
const repo = context.repo.repo;
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number: issueNumber,
|
|
||||||
labels: ['ai-moderated']
|
|
||||||
});
|
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
try {
|
||||||
owner: context.repo.owner,
|
if (isDiscussion) {
|
||||||
repo: context.repo.repo,
|
await github.rest.discussions.addLabels({
|
||||||
issue_number: issueNumber,
|
owner, repo, discussion_number: number, labels: ['ai-moderated']
|
||||||
body: decision.message
|
});
|
||||||
});
|
await github.rest.discussions.createComment({
|
||||||
|
owner, repo, discussion_number: number, body: decision.message
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await github.rest.issues.addLabels({
|
||||||
|
owner, repo, issue_number: number, labels: ['ai-moderated']
|
||||||
|
});
|
||||||
|
await github.rest.issues.createComment({
|
||||||
|
owner, repo, issue_number: number, body: decision.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (decision.action === 'hide' && isComment) {
|
if (decision.action === 'hide' && isComment) {
|
||||||
const commentId = context.payload.comment.node_id;
|
const commentId = context.payload.comment.node_id;
|
||||||
@@ -143,13 +154,12 @@ jobs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (decision.action === 'lock') {
|
if (decision.action === 'lock') {
|
||||||
await github.rest.issues.lock({
|
if (isDiscussion) {
|
||||||
owner: context.repo.owner,
|
await github.rest.discussions.lock({ owner, repo, discussion_number: number });
|
||||||
repo: context.repo.repo,
|
} else {
|
||||||
issue_number: issueNumber,
|
await github.rest.issues.lock({ owner, repo, issue_number: number, lock_reason: 'too_heated' });
|
||||||
lock_reason: 'too_heated'
|
}
|
||||||
});
|
console.log('Locked');
|
||||||
console.log('Issue locked');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Action completed: ' + decision.action);
|
console.log('Action completed: ' + decision.action);
|
||||||
|
|||||||
Reference in New Issue
Block a user