From 86d41ad88f287b6bd5c9966ae87c7a6e6938059b Mon Sep 17 00:00:00 2001 From: Alexey Efimov Date: Wed, 4 Jun 2025 15:10:01 +0000 Subject: [PATCH] add automation to calculate issue priority --- .github/workflows/priority-score.yml | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/priority-score.yml diff --git a/.github/workflows/priority-score.yml b/.github/workflows/priority-score.yml new file mode 100644 index 000000000..86d2365c6 --- /dev/null +++ b/.github/workflows/priority-score.yml @@ -0,0 +1,93 @@ +name: Update Calculated Priority + +on: + issues: + types: [opened, labeled, unlabeled, edited] + +jobs: + update-priority: + runs-on: ubuntu-latest + steps: + - name: Update CalculatedPriority field + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }} + script: | + const labelWeights = { + "prio/high": 1000, + "prio/medium": 500, + "prio/low": 100 + }; + + const issue = context.payload.issue; + const labels = issue.labels.map(l => l.name); + const basePriority = Math.min(...labels.map(l => labelWeights[l] || 10), 1000); + + const createdAt = new Date(issue.created_at); + const daysOld = Math.floor((Date.now() - createdAt.getTime()) / (1000 * 60 * 60 * 24)); + + const finalScore = basePriority + daysOld; + + const projectNumber = 24; + const org = "ydb-platform"; + + const result = await github.graphql(` + query($org: String!, $number: Int!) { + organization(login: $org) { + projectV2(number: $number) { + id + fields(first: 50) { + nodes { + ... on ProjectV2Field { + id + name + } + } + } + items(first: 100) { + nodes { + id + content { + ... on Issue { + id + number + } + } + } + } + } + } + } + `, { org, number: projectNumber }); + + const project = result.organization.projectV2; + const field = project.fields.nodes.find(f => f.name === "CalculatedPriority"); + if (!field) { + core.setFailed("Field 'CalculatedPriority' not found."); + return; + } + + const item = project.items.nodes.find(n => n.content?.number === issue.number); + if (!item) { + console.log(`Issue #${issue.number} not found in project.`); + return; + } + + await github.graphql(` + mutation($input: UpdateProjectV2ItemFieldValueInput!) { + updateProjectV2ItemFieldValue(input: $input) { + projectV2Item { + id + } + } + } + `, { + input: { + projectId: project.id, + itemId: item.id, + fieldId: field.id, + value: { number: finalScore } + } + }); + + console.log(`Updated CalculatedPriority of issue #${issue.number} to ${finalScore}`);