Skip to content

Context menu to create a vector index #232

Context menu to create a vector index

Context menu to create a vector index #232

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.YDBOT_TOKEN }}
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 issueNumber = issue.number;
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const projectQuery = await github.graphql(`
query($org: String!, $number: Int!) {
organization(login: $org) {
projectV2(number: $number) {
id
fields(first: 50) {
nodes {
... on ProjectV2Field {
id
name
}
}
}
}
}
}
`, { org, number: projectNumber });
const projectId = projectQuery.organization.projectV2.id;
const field = projectQuery.organization.projectV2.fields.nodes.find(f => f.name === "CalculatedPriority");
if (!field) {
core.setFailed("Field 'CalculatedPriority' not found.");
return;
}
const fieldId = field.id;
// Now paginate to find the matching item
let item = null;
let cursor = null;
let hasNextPage = true;
while (hasNextPage && !item) {
const response = await github.graphql(`
query($org: String!, $number: Int!, $after: String) {
organization(login: $org) {
projectV2(number: $number) {
items(first: 100, after: $after) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
content {
__typename
... on Issue {
number
repository {
name
owner { login }
}
}
}
}
}
}
}
}
`, { org, number: projectNumber, after: cursor });
const items = response.organization.projectV2.items.nodes;
item = items.find(n =>
n.content?.__typename === "Issue" &&
n.content?.number === issueNumber &&
n.content?.repository?.name === repoName &&
n.content?.repository?.owner?.login === repoOwner
);
hasNextPage = response.organization.projectV2.items.pageInfo.hasNextPage;
cursor = response.organization.projectV2.items.pageInfo.endCursor;
}
if (!item) {
console.log(`Issue #${issueNumber} not found in project (repo=${repoName}).`);
return;
}
// Update field
await github.graphql(`
mutation($input: UpdateProjectV2ItemFieldValueInput!) {
updateProjectV2ItemFieldValue(input: $input) {
projectV2Item {
id
}
}
}
`, {
input: {
projectId,
itemId: item.id,
fieldId,
value: { number: finalScore }
}
});
console.log(`✅ Updated CalculatedPriority of issue #${issueNumber} to ${finalScore}`);