forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.ts
More file actions
40 lines (33 loc) · 1.31 KB
/
Copy pathanalytics.ts
File metadata and controls
40 lines (33 loc) · 1.31 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
import { calculateLabelValue } from "../../helpers/shared";
import { Context } from "../../types/context";
import { GitHubIssue } from "../../types/payload";
// Checks the issue whether it's an open task for public self assignment
export function taskPaymentMetaData(
context: Context,
issue: GitHubIssue
): {
eligibleForPayment: boolean;
timeLabel: string | null;
priorityLabel: string | null;
priceLabel: string | null;
} {
const { labels } = context.config;
const timeLabels = labels.time.filter((configLabel) => issue.labels.map((i) => i.name).includes(configLabel));
const priorityLabels = labels.priority.filter((configLabel) => issue.labels.map((i) => i.name).includes(configLabel));
const isTask = timeLabels.length > 0 && priorityLabels.length > 0;
const minTimeLabel =
timeLabels.length > 0
? timeLabels.reduce((a, b) => (calculateLabelValue(a) < calculateLabelValue(b) ? a : b))
: null;
const minPriorityLabel =
priorityLabels.length > 0
? priorityLabels.reduce((a, b) => (calculateLabelValue(a) < calculateLabelValue(b) ? a : b))
: null;
const priceLabel = issue.labels.find((label) => label.name.includes("Price"))?.name || null;
return {
eligibleForPayment: isTask,
timeLabel: minTimeLabel,
priorityLabel: minPriorityLabel,
priceLabel,
};
}