Skip to content

Commit ec5aa2b

Browse files
committed
feat: add a config prop 'aggressiveFollowUps' to follow up based on priority level
1 parent d49d253 commit ec5aa2b

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/helpers/task-metadata.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,45 @@ function parseTimeLabel(
108108

109109
return taskTimeEstimate;
110110
}
111+
112+
export function parsePriorityLabel(
113+
labels: (
114+
| string
115+
| {
116+
id?: number;
117+
node_id?: string;
118+
url?: string;
119+
name?: string;
120+
description?: string | null;
121+
color?: string | null;
122+
default?: boolean;
123+
}
124+
)[]
125+
): number {
126+
let taskPriorityEstimate = 0;
127+
128+
for (const label of labels) {
129+
let priorityLabel = "";
130+
if (typeof label === "string") {
131+
priorityLabel = label;
132+
} else {
133+
priorityLabel = label.name || "";
134+
}
135+
136+
if (priorityLabel.startsWith("Priority:")) {
137+
const matched = priorityLabel.match(/Priority: (\d+)/i);
138+
if (!matched) {
139+
return 0;
140+
}
141+
142+
const [_, urgency] = matched;
143+
taskPriorityEstimate = Number(urgency);
144+
}
145+
146+
if (taskPriorityEstimate) {
147+
break;
148+
}
149+
}
150+
151+
return taskPriorityEstimate;
152+
}

src/helpers/task-update.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getAssigneesActivityForIssue } from "./get-assignee-activity";
88
import { parseIssueUrl } from "./github-url";
99
import { remindAssigneesForIssue, unassignUserFromIssue } from "./remind-and-remove";
1010
import { getCommentsFromMetadata } from "./structured-metadata";
11-
import { getTaskAssignmentDetails } from "./task-metadata";
11+
import { getTaskAssignmentDetails, parsePriorityLabel } from "./task-metadata";
1212

1313
const getMostRecentActivityDate = (assignedEventDate: DateTime, activityEventDate?: DateTime): DateTime => {
1414
return activityEventDate && activityEventDate > assignedEventDate ? activityEventDate : assignedEventDate;
@@ -18,7 +18,7 @@ export async function updateTaskReminder(context: ContextPlugin, repo: ListForOr
1818
const {
1919
octokit,
2020
logger,
21-
config: { eventWhitelist, warning, disqualification },
21+
config: { eventWhitelist, warning, disqualification, prioritySpeed },
2222
} = context;
2323
const handledMetadata = await getTaskAssignmentDetails(context, repo, issue);
2424
const now = DateTime.local();
@@ -46,6 +46,7 @@ export async function updateTaskReminder(context: ContextPlugin, repo: ListForOr
4646
.shift();
4747

4848
const assignedDate = DateTime.fromISO(assignedEvent.created_at);
49+
const priorityLevel = parsePriorityLabel(issue.labels);
4950
const activityDate = activityEvent?.created_at ? DateTime.fromISO(activityEvent.created_at) : undefined;
5051
let mostRecentActivityDate = getMostRecentActivityDate(assignedDate, activityDate);
5152

@@ -75,13 +76,13 @@ export async function updateTaskReminder(context: ContextPlugin, repo: ListForOr
7576
if (lastReminderComment) {
7677
const lastReminderTime = DateTime.fromISO(lastReminderComment.created_at);
7778
mostRecentActivityDate = lastReminderTime > mostRecentActivityDate ? lastReminderTime : mostRecentActivityDate;
78-
if (mostRecentActivityDate.plus({ milliseconds: disqualificationTimeDifference }) <= now) {
79+
if (mostRecentActivityDate.plus({ milliseconds: prioritySpeed ? disqualificationTimeDifference / priorityLevel : disqualificationTimeDifference }) <= now) {
7980
await unassignUserFromIssue(context, issue);
8081
} else {
8182
logger.info(`Reminder was sent for ${issue.html_url} already, not beyond disqualification deadline yet.`);
8283
}
8384
} else {
84-
if (mostRecentActivityDate.plus({ milliseconds: warning }) <= now) {
85+
if (mostRecentActivityDate.plus({ milliseconds: prioritySpeed ? warning / priorityLevel : warning }) <= now) {
8586
await remindAssigneesForIssue(context, issue);
8687
} else {
8788
logger.info(`Nothing to do for ${issue.html_url}, still within due-time.`);

src/types/plugin-input.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export const pluginSettingsSchema = T.Object(
6666
},
6767
{ default: {} }
6868
),
69+
/*
70+
* Whether to rush the follow ups by the priority level
71+
*/
72+
prioritySpeed: T.Boolean({ default: true }),
6973
/**
7074
* Delay to unassign users. 0 means disabled. Any other value is counted in days, e.g. 7 days
7175
*/

0 commit comments

Comments
 (0)