Skip to content

feat(Automation): add automation to calculate issue priority #2365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/priority-score.yml
Original file line number Diff line number Diff line change
@@ -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}`);
Loading