-
Notifications
You must be signed in to change notification settings - Fork 25
196 lines (172 loc) · 6.88 KB
/
Copy pathpriority-score.yml
File metadata and controls
196 lines (172 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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: |
// Priority estimation based on reach/impact/effort methodology
const reachWeights = {
"reach:high": 100,
"reach:medium": 75,
"reach:low": 50
};
const impactWeights = {
"impact:high": 200,
"impact:medium": 137.5,
"impact:low": 75
};
const effortWeights = {
"size/l": 9,
"size/m": 4,
"size/s": 1,
"size/xl": 18
};
// Bonus multipliers for special labels
const HEART_XENO_MULTIPLIER = 1.5;
const FEEDBACK_MULTIPLIER = 1.5;
const MAX_PRIORITY_SCORE = 100000;
const issue = context.payload.issue;
const labels = issue.labels.map(l => l.name);
// Find reach, impact, and effort values from labels
let reach = null;
let impact = null;
let effort = null;
let hasHeartXeno = false;
let hasFeedback = false;
for (const label of labels) {
if (reachWeights[label] !== undefined) {
reach = reachWeights[label];
}
if (impactWeights[label] !== undefined) {
impact = impactWeights[label];
}
if (effortWeights[label] !== undefined) {
effort = effortWeights[label];
}
if (label === ":heart: xeno") {
hasHeartXeno = true;
}
if (label === "feedback") {
hasFeedback = true;
}
}
// Fallback default values
const defaultReach = 75; // default to medium reach
const defaultImpact = 75; // default to low impact
const defaultEffort = 4; // default to medium effort
// Calculate priority score using formula: (reach * impact) / effort
const effectiveReach = reach || defaultReach;
const effectiveImpact = impact || defaultImpact;
const effectiveEffort = effort || defaultEffort;
let baseScore = Math.round((effectiveReach * effectiveImpact) / effectiveEffort);
// Apply bonus multipliers for special labels
let bonusMultiplier = 1;
if (hasHeartXeno) {
bonusMultiplier *= HEART_XENO_MULTIPLIER;
}
if (hasFeedback) {
bonusMultiplier *= FEEDBACK_MULTIPLIER;
}
// Calculate final score with cap to prevent excessively large values
let finalScore = Math.min(Math.round(baseScore * bonusMultiplier), MAX_PRIORITY_SCORE);
console.log(`📊 Priority calculation: reach=${reach || 'default'}, impact=${impact || 'default'}, effort=${effort || 'default'}, heartXeno=${hasHeartXeno}, feedback=${hasFeedback} → baseScore=${baseScore}, multiplier=${bonusMultiplier}, finalScore=${finalScore}`);
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}`);