|
| 1 | +name: Update Calculated Priority |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened, labeled, unlabeled, edited] |
| 6 | + |
| 7 | +jobs: |
| 8 | + update-priority: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Update CalculatedPriority field |
| 12 | + uses: actions/github-script@v7 |
| 13 | + with: |
| 14 | + github-token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }} |
| 15 | + script: | |
| 16 | + const labelWeights = { |
| 17 | + "prio/high": 1000, |
| 18 | + "prio/medium": 500, |
| 19 | + "prio/low": 100 |
| 20 | + }; |
| 21 | +
|
| 22 | + const issue = context.payload.issue; |
| 23 | + const labels = issue.labels.map(l => l.name); |
| 24 | + const basePriority = Math.min(...labels.map(l => labelWeights[l] || 10), 1000); |
| 25 | +
|
| 26 | + const createdAt = new Date(issue.created_at); |
| 27 | + const daysOld = Math.floor((Date.now() - createdAt.getTime()) / (1000 * 60 * 60 * 24)); |
| 28 | +
|
| 29 | + const finalScore = basePriority + daysOld; |
| 30 | +
|
| 31 | + const projectNumber = 24; |
| 32 | + const org = "ydb-platform"; |
| 33 | +
|
| 34 | + const result = await github.graphql(` |
| 35 | + query($org: String!, $number: Int!) { |
| 36 | + organization(login: $org) { |
| 37 | + projectV2(number: $number) { |
| 38 | + id |
| 39 | + fields(first: 50) { |
| 40 | + nodes { |
| 41 | + ... on ProjectV2Field { |
| 42 | + id |
| 43 | + name |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + items(first: 100) { |
| 48 | + nodes { |
| 49 | + id |
| 50 | + content { |
| 51 | + ... on Issue { |
| 52 | + id |
| 53 | + number |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + `, { org, number: projectNumber }); |
| 62 | +
|
| 63 | + const project = result.organization.projectV2; |
| 64 | + const field = project.fields.nodes.find(f => f.name === "CalculatedPriority"); |
| 65 | + if (!field) { |
| 66 | + core.setFailed("Field 'CalculatedPriority' not found."); |
| 67 | + return; |
| 68 | + } |
| 69 | +
|
| 70 | + const item = project.items.nodes.find(n => n.content?.number === issue.number); |
| 71 | + if (!item) { |
| 72 | + console.log(`Issue #${issue.number} not found in project.`); |
| 73 | + return; |
| 74 | + } |
| 75 | +
|
| 76 | + await github.graphql(` |
| 77 | + mutation($input: UpdateProjectV2ItemFieldValueInput!) { |
| 78 | + updateProjectV2ItemFieldValue(input: $input) { |
| 79 | + projectV2Item { |
| 80 | + id |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + `, { |
| 85 | + input: { |
| 86 | + projectId: project.id, |
| 87 | + itemId: item.id, |
| 88 | + fieldId: field.id, |
| 89 | + value: { number: finalScore } |
| 90 | + } |
| 91 | + }); |
| 92 | +
|
| 93 | + console.log(`Updated CalculatedPriority of issue #${issue.number} to ${finalScore}`); |
0 commit comments