Skip to content

Commit 9f84cea

Browse files
authored
Merge pull request #174 from backstage/rugvip/higher
pr-automation: tweak priority caluclation to taper off more slowy with size + add config
2 parents a46d20f + 136d396 commit 9f84cea

5 files changed

Lines changed: 48 additions & 40 deletions

File tree

pr-automation/action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ inputs:
3434
actor:
3535
description: Override for the actor (user who triggered the event)
3636
required: false
37+
priority-base:
38+
description: Starting priority value before size-based reduction
39+
required: false
40+
default: "100"
41+
priority-exponent-base:
42+
description: Base of the exponential decay (0.5 = halve priority per divisor)
43+
required: false
44+
default: "0.5"
45+
priority-exponent-offset:
46+
description: Lines of additions before priority starts decreasing
47+
required: false
48+
default: "0"
49+
priority-exponent-divisor:
50+
description: Lines of additions per halving of priority
51+
required: false
52+
default: "500"
53+
priority-reviewer-bump:
54+
description: Priority boost when PR has reviewer-approved label
55+
required: false
56+
default: "100"
3757
outputs: {}
3858
runs:
3959
using: node24

pr-automation/getConfig.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ export function getConfig(): Config {
3636
statusFieldName: 'Status',
3737
priorityFieldName: 'Priority',
3838
priorityParams: {
39-
base: 100,
40-
exponentBase: 0.5,
41-
exponentOffset: 1,
42-
exponentDivisor: 99,
43-
min: 0,
44-
max: 100,
45-
reviewerBump: 100,
39+
base: parseNumber(core.getInput('priority-base'), 100),
40+
exponentBase: parseNumber(core.getInput('priority-exponent-base'), 0.5),
41+
exponentOffset: parseNumber(core.getInput('priority-exponent-offset'), 0),
42+
exponentDivisor: parseNumber(
43+
core.getInput('priority-exponent-divisor'),
44+
500,
45+
),
46+
reviewerBump: parseNumber(core.getInput('priority-reviewer-bump'), 100),
4647
},
4748
};
4849
}
Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
11
import { calculatePriority } from './calculatePriority';
22

33
describe('calculatePriority', () => {
4+
// 0 lines → 100, 500 lines → ~50, 5000 lines → 0
45
const defaultParams = {
56
base: 100,
67
exponentBase: 0.5,
7-
exponentOffset: 1,
8-
exponentDivisor: 99,
9-
min: 0,
10-
max: 100,
8+
exponentOffset: 0,
9+
exponentDivisor: 500,
1110
reviewerBump: 100,
1211
};
1312

14-
it('calculates priority within bounds and adds reviewer bump', () => {
15-
const priorityWithoutBump = calculatePriority(5, defaultParams, false);
16-
const priorityWithBump = calculatePriority(5, defaultParams, true);
13+
it('calculates expected priority values based on PR size', () => {
14+
expect(calculatePriority(0, defaultParams, false)).toBe(100);
15+
expect(calculatePriority(500, defaultParams, false)).toBe(50);
16+
expect(calculatePriority(5000, defaultParams, false)).toBe(0);
17+
});
18+
19+
it('adds reviewer bump to priority', () => {
20+
const priorityWithoutBump = calculatePriority(500, defaultParams, false);
21+
const priorityWithBump = calculatePriority(500, defaultParams, true);
1722

18-
expect(priorityWithoutBump).toBeGreaterThanOrEqual(0);
19-
expect(priorityWithoutBump).toBeLessThanOrEqual(100);
2023
expect(priorityWithBump).toBe(priorityWithoutBump + 100);
21-
expect(priorityWithBump).toBeGreaterThanOrEqual(100);
2224
});
2325

24-
it('respects min and max bounds and handles edge cases', () => {
25-
const paramsWithTightBounds = {
26-
...defaultParams,
27-
min: 10,
28-
max: 50,
29-
};
30-
const priorityHigh = calculatePriority(1000, paramsWithTightBounds, false);
31-
const priorityZero = calculatePriority(0, defaultParams, false);
32-
const priorityVeryHigh = calculatePriority(100000, defaultParams, false);
26+
it('clamps priority between 0 and base', () => {
27+
const paramsWithLowBase = { ...defaultParams, base: 50 };
3328

34-
expect(priorityHigh).toBeGreaterThanOrEqual(10);
35-
expect(priorityHigh).toBeLessThanOrEqual(50);
36-
expect(priorityZero).toBeGreaterThanOrEqual(0);
37-
expect(priorityZero).toBeLessThanOrEqual(100);
38-
expect(priorityVeryHigh).toBeGreaterThanOrEqual(0);
39-
expect(priorityVeryHigh).toBeLessThanOrEqual(100);
29+
expect(calculatePriority(0, paramsWithLowBase, false)).toBe(50);
30+
expect(calculatePriority(5000, paramsWithLowBase, false)).toBe(0);
4031
});
4132
});

pr-automation/logic/calculatePriority.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function calculatePriority(
1212
(additions - params.exponentOffset) / params.exponentDivisor,
1313
);
1414
let priority = Math.round(rawPriority);
15-
priority = Math.max(params.min, Math.min(params.max, priority));
15+
priority = Math.max(0, Math.min(params.base, priority));
1616

1717
if (hasReviewerApproved) {
1818
priority += params.reviewerBump;

pr-automation/types.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,14 @@ export interface SizeLabelConfig {
102102
}
103103

104104
export interface PriorityParams {
105-
/** Starting priority value before size-based reduction */
105+
/** Starting/max priority value before size-based reduction (min is always 0) */
106106
base: number;
107-
/** Base of the exponential decay (e.g., 0.5 = halve priority) */
107+
/** Base of the exponential decay (e.g., 0.5 = halve priority per divisor) */
108108
exponentBase: number;
109109
/** Lines of additions before priority starts decreasing */
110110
exponentOffset: number;
111-
/** Lines of additions per halving of priority (when exponentBase is 0.5) */
111+
/** Lines of additions per halving of priority (default 500: 0→100, 500→50, 5000→0) */
112112
exponentDivisor: number;
113-
/** Minimum allowed priority value */
114-
min: number;
115-
/** Maximum allowed priority value */
116-
max: number;
117113
/** Priority boost when PR has reviewer-approved label */
118114
reviewerBump: number;
119115
}

0 commit comments

Comments
 (0)