92 lines
4.3 KiB
YAML
92 lines
4.3 KiB
YAML
name: Similar Issues via AI MCP
|
|
|
|
on:
|
|
issues:
|
|
types: [opened]
|
|
|
|
jobs:
|
|
find-similar:
|
|
permissions:
|
|
contents: read
|
|
issues: write
|
|
models: read
|
|
runs-on: ubuntu-slim
|
|
steps:
|
|
- name: Check out repository
|
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
|
|
|
- name: Prepare prompt variables
|
|
id: prepare_input
|
|
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
|
with:
|
|
script: |
|
|
const issue = context.payload.issue || {};
|
|
const title = issue.title || '';
|
|
const body = issue.body || '';
|
|
const indent = ' ';
|
|
// Indent subsequent lines so YAML block scalar indentation remains valid
|
|
const bodyIndented = body.replace(/\n/g, '\n' + indent);
|
|
core.setOutput('issue_title_json', JSON.stringify(title));
|
|
core.setOutput('issue_body_indented_json', JSON.stringify(bodyIndented));
|
|
core.setOutput('issue_number', issue.number);
|
|
|
|
- name: Find similar issues with AI (MCP)
|
|
id: inference
|
|
uses: actions/ai-inference@334892bb203895caaed82ec52d23c1ed9385151e # v2.0.4
|
|
with:
|
|
prompt-file: ./.github/prompts/similar_issues.prompt.yml
|
|
input: |
|
|
issue_title: ${{ steps.prepare_input.outputs.issue_title_json }}
|
|
issue_body: ${{ steps.prepare_input.outputs.issue_body_indented_json }}
|
|
issue_number: ${{ steps.prepare_input.outputs.issue_number }}
|
|
repository: ${{ github.repository }}
|
|
enable-github-mcp: true
|
|
# Inference token can use GITHUB_TOKEN. MCP specifically requires a PAT.
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
github-mcp-token: ${{ secrets.USER_PAT }}
|
|
max-tokens: 8000
|
|
|
|
- name: Prepare comment body
|
|
id: prepare
|
|
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
|
env:
|
|
AI_RESPONSE: ${{ steps.inference.outputs.response }}
|
|
with:
|
|
script: |
|
|
let data;
|
|
try {
|
|
data = JSON.parse(process.env.AI_RESPONSE || '{}');
|
|
} catch (e) {
|
|
core.setOutput('has_matches', 'false');
|
|
return;
|
|
}
|
|
const matches = Array.isArray(data.matches) ? data.matches.filter(m => m.number !== context.payload.issue.number) : [];
|
|
if (!matches.length) {
|
|
core.setOutput('has_matches', 'false');
|
|
return;
|
|
}
|
|
const lines = [];
|
|
lines.push('I found similar issues that might help:');
|
|
for (const m of matches.slice(0, 3)) {
|
|
const num = m.number != null ? `#${m.number}` : '';
|
|
const title = m.title || 'Untitled';
|
|
const url = m.url || '';
|
|
const score = typeof m.similarity_score === 'number' ? ` (similarity: ${m.similarity_score.toFixed(2)})` : '';
|
|
lines.push(`- ${url}${score}`.trim());
|
|
}
|
|
core.setOutput('has_matches', 'true');
|
|
core.setOutput('comment_body', lines.join('\n'));
|
|
|
|
- name: Comment similar issues
|
|
if: steps.prepare.outputs.has_matches == 'true'
|
|
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
|
with:
|
|
script: |
|
|
const body = ${{ toJson(steps.prepare.outputs.comment_body) }};
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.payload.issue.number,
|
|
body
|
|
});
|