Skip to content

Commit 0a9dff8

Browse files
Merge pull request #56 from Knowledge-Graph-Hub/enable_ai
Fix AI Agent Mention Detection
2 parents 0a9d963 + b3ecc4d commit 0a9dff8

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

.github/workflows/ai-agent.yml

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,77 @@ jobs:
2626

2727
- name: Detect AI mention
2828
id: detect
29-
uses: dragon-ai-agent/github-mention-detector@v1.0.0
29+
uses: actions/github-script@v7
3030
with:
3131
github-token: ${{ secrets.PAT_FOR_PR }}
32-
fallback-controllers: 'jtr4v'
33-
mention-pattern: '@alzassistant\\s+(.*)'
32+
script: |
33+
// Load allowed users from config
34+
const fs = require('fs');
35+
let allowedUsers = [];
36+
try {
37+
const configContent = fs.readFileSync('.github/ai-controllers.json', 'utf8');
38+
allowedUsers = JSON.parse(configContent);
39+
} catch (error) {
40+
console.log('Error loading allowed users:', error);
41+
// Use fallback controllers if provided
42+
const fallback = 'jtr4v';
43+
allowedUsers = fallback ? fallback.split(',').map(u => u.trim()) : [];
44+
}
45+
46+
// Get content and user from event payload
47+
let content = '';
48+
let userLogin = '';
49+
let itemType = '';
50+
let itemNumber = 0;
51+
52+
if (context.eventName === 'issues') {
53+
content = context.payload.issue.body || '';
54+
userLogin = context.payload.issue.user.login;
55+
itemType = 'issue';
56+
itemNumber = context.payload.issue.number;
57+
} else if (context.eventName === 'pull_request') {
58+
content = context.payload.pull_request.body || '';
59+
userLogin = context.payload.pull_request.user.login;
60+
itemType = 'pull_request';
61+
itemNumber = context.payload.pull_request.number;
62+
} else if (context.eventName === 'issue_comment') {
63+
content = context.payload.comment.body || '';
64+
userLogin = context.payload.comment.user.login;
65+
itemType = 'issue';
66+
itemNumber = context.payload.issue.number;
67+
} else if (context.eventName === 'pull_request_review_comment') {
68+
content = context.payload.comment.body || '';
69+
userLogin = context.payload.comment.user.login;
70+
itemType = 'pull_request';
71+
itemNumber = context.payload.pull_request.number;
72+
}
73+
74+
// Check if user is allowed and mention exists
75+
const isAllowed = allowedUsers.includes(userLogin);
76+
const mentionRegex = new RegExp('@alzassistant\\s+(.*)', 'i');
77+
const mentionMatch = content.match(mentionRegex);
78+
79+
const qualifiedMention = isAllowed && mentionMatch !== null;
80+
const prompt = qualifiedMention ? mentionMatch[1].trim() : '';
81+
82+
console.log(`User: ${userLogin}, Allowed: ${isAllowed}, Has mention: ${mentionMatch !== null}, Content: "${content}"`);
83+
84+
// Set outputs
85+
core.setOutput('qualified-mention', qualifiedMention);
86+
core.setOutput('prompt', prompt);
87+
core.setOutput('user', userLogin);
88+
core.setOutput('item-type', itemType);
89+
core.setOutput('item-number', itemNumber);
90+
core.setOutput('controllers', allowedUsers.map(u => '@' + u).join(', '));
91+
92+
return {
93+
qualifiedMention,
94+
itemType,
95+
itemNumber,
96+
prompt,
97+
user: userLogin,
98+
controllers: allowedUsers.map(u => '@' + u).join(', ')
99+
};
34100
35101
respond-to-mention:
36102
needs: check-mention

0 commit comments

Comments
 (0)