Refactor AI label review workflow and improve config

This commit is contained in:
CanbiZ 2025-09-18 12:03:52 +02:00 committed by GitHub
parent 76dcc45e9f
commit 694d9c203e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

29
.github/workflows/autolabeler.yml generated vendored
View File

@ -121,11 +121,12 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
# 🔹 Priority-Config laden (kompakt mit jq -c)
- name: Load priority config - name: Load priority config
id: config
run: | run: |
echo "PRIORITY_JSON=$(jq -c . .github/label-priority.json)" >> $GITHUB_ENV echo "PRIORITY_JSON=$(jq -c . .github/label-priority.json)" >> $GITHUB_ENV
# 🔹 PR-Daten sammeln
- name: Fetch PR metadata - name: Fetch PR metadata
id: pr id: pr
uses: actions/github-script@v7 uses: actions/github-script@v7
@ -137,12 +138,14 @@ jobs:
repo: context.repo.repo, repo: context.repo.repo,
pull_number: pr.number pull_number: pr.number
}); });
return { const prData = {
title: pr.title, title: pr.title || "",
body: pr.body || "", body: pr.body || "",
files: files.data.map(f => f.filename) files: files.data.map(f => f.filename)
}; };
require('fs').writeFileSync(process.env.GITHUB_ENV, `PR_DATA=${JSON.stringify(prData)}\n`, {flag: 'a'});
# 🔹 AI-Analyse (OpenAI)
- name: AI Label Review - name: AI Label Review
id: ai id: ai
uses: actions/github-script@v7 uses: actions/github-script@v7
@ -151,21 +154,17 @@ jobs:
with: with:
script: | script: |
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const prData = { const prData = JSON.parse(process.env.PR_DATA);
title: ${{ steps.pr.outputs.title }},
body: ${{ steps.pr.outputs.body }},
files: ${{ steps.pr.outputs.files }}
};
const prompt = ` const prompt = `
You are a GitHub labeling bot. You are a GitHub labeling bot.
Task: Task:
- Analyze PR title, body, and file list. - Analyze PR title, body, and file list.
- For each possible label, return a confidence score (01). - For each possible label, return a confidence score (01).
- Consider conflicts: bugfix vs refactor, feature vs breaking change. - If both bugfix and refactor apply, prefer refactor.
- Output JSON: {"labels":[{"name":"bugfix","score":0.9},{"name":"refactor","score":0.6}]} - Output JSON: {"labels":[{"name":"bugfix","score":0.9},{"name":"refactor","score":0.6}]}
Valid labels: [new script, update script, delete script, bugfix, feature, breaking change, maintenance, refactor, website, json, api, core, github, addon, pve-tool, vm]. Valid labels: [new script, update script, delete script, bugfix, feature, maintenance, refactor, website, json, api, core, github, addon, pve-tool, vm].
PR data: ${JSON.stringify(prData)} PR data: ${JSON.stringify(prData)}
`; `;
@ -182,10 +181,12 @@ jobs:
temperature: 0 temperature: 0
}) })
}); });
const data = await response.json(); const data = await response.json();
const labels = JSON.parse(data.choices[0].message.content).labels; const labels = JSON.parse(data.choices[0].message.content).labels;
core.setOutput("labels", JSON.stringify(labels)); core.setOutput("labels", JSON.stringify(labels));
# 🔹 Labels anwenden + unsichere vorschlagen
- name: Apply AI Labels - name: Apply AI Labels
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
@ -193,17 +194,19 @@ jobs:
const raw = JSON.parse('${{ steps.ai.outputs.labels }}'); const raw = JSON.parse('${{ steps.ai.outputs.labels }}');
const prNumber = context.payload.pull_request.number; const prNumber = context.payload.pull_request.number;
const config = JSON.parse(process.env.PRIORITY_JSON); const config = JSON.parse(process.env.PRIORITY_JSON);
console.log("Loaded priorities:", config.priorities);
let toApply = []; let toApply = [];
let toSuggest = []; let toSuggest = [];
raw.forEach(l => { raw.forEach(l => {
if (l.score >= 0.8) { if (l.score >= 0.8) {
// check conflicts
const conflicts = config.conflicts[l.name] || []; const conflicts = config.conflicts[l.name] || [];
const hasStrongerConflict = conflicts.some(c => const hasStrongerConflict = conflicts.some(c =>
raw.some(x => x.name === c && x.score >= 0.6 && config.priorities[c] >= config.priorities[l.name]) raw.some(x =>
x.name === c &&
x.score >= 0.6 &&
(config.priorities[c] || 0) >= (config.priorities[l.name] || 0)
)
); );
if (!hasStrongerConflict) { if (!hasStrongerConflict) {
toApply.push(l.name); toApply.push(l.name);