Skip to content

Commit d8f699b

Browse files
authored
Merge pull request #178 from backstage/rugvip/draft
pr-automation: lower score for draft PRs or PRs not passing checks
2 parents 96dace4 + 46fdfcf commit d8f699b

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

pr-automation/collectInput.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const QUERY = `
3939
pullRequest(number: $issueNumber) {
4040
number
4141
title
42+
isDraft
4243
reviewDecision
4344
author {
4445
login
@@ -47,6 +48,9 @@ const QUERY = `
4748
target {
4849
... on Commit {
4950
committedDate
51+
statusCheckRollup {
52+
state
53+
}
5054
}
5155
}
5256
}
@@ -324,13 +328,31 @@ async function getPrAutomationData(
324328
| 'REVIEW_REQUIRED'
325329
| undefined;
326330

327-
const headCommitDate = (
328-
pr as { headRef?: { target?: { committedDate?: string } } }
329-
).headRef?.target?.committedDate;
331+
const headCommit = (
332+
pr as {
333+
headRef?: {
334+
target?: {
335+
committedDate?: string;
336+
statusCheckRollup?: { state?: string };
337+
};
338+
};
339+
}
340+
).headRef?.target;
341+
342+
const headCommitDate = headCommit?.committedDate;
343+
const checkStatus = headCommit?.statusCheckRollup?.state as
344+
| 'SUCCESS'
345+
| 'FAILURE'
346+
| 'PENDING'
347+
| 'ERROR'
348+
| 'EXPECTED'
349+
| undefined;
330350

331351
return {
332352
number: pr.number,
333353
title: pr.title,
354+
isDraft: (pr as { isDraft?: boolean }).isDraft ?? false,
355+
checkStatus,
334356
authorLogin: pr.author?.login ?? undefined,
335357
reviewDecision,
336358
labels:

pr-automation/main.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,19 @@ export async function main() {
176176
// Get copilot review priority boost
177177
const copilotPriority = getCopilotReviewPriority(data.reviews);
178178

179-
const priority = basePriority + authorScore + copilotPriority;
179+
// Apply penalty multipliers for draft PRs (20%) and failing checks (50%)
180+
const draftMultiplier = data.isDraft ? 0.2 : 1;
181+
const checksPassing = data.checkStatus === 'SUCCESS';
182+
const checksMultiplier = checksPassing ? 1 : 0.5;
183+
const priority = Math.round(
184+
(basePriority + authorScore + copilotPriority) *
185+
draftMultiplier *
186+
checksMultiplier,
187+
);
180188

181189
const priorityParts: string[] = [];
190+
if (data.isDraft) priorityParts.push('draft ×0.2');
191+
if (!checksPassing) priorityParts.push(`checks ${data.checkStatus} ×0.5`);
182192
if (reviewerApproved) priorityParts.push('reviewer approval');
183193
if (authorScore > 0) priorityParts.push(`author score +${authorScore}`);
184194
if (copilotPriority > 0) priorityParts.push(`copilot +${copilotPriority}`);

pr-automation/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,18 @@ export interface Comment {
4141
createdAt?: string;
4242
}
4343

44+
export type CheckStatusState =
45+
| 'SUCCESS'
46+
| 'FAILURE'
47+
| 'PENDING'
48+
| 'ERROR'
49+
| 'EXPECTED';
50+
4451
export interface PrData {
4552
number: number;
4653
title: string;
54+
isDraft: boolean;
55+
checkStatus?: CheckStatusState;
4756
authorLogin?: string;
4857
reviewDecision?: 'APPROVED' | 'CHANGES_REQUESTED' | 'REVIEW_REQUIRED';
4958
labels: string[];

0 commit comments

Comments
 (0)