forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbackOnAny.ts
More file actions
64 lines (55 loc) · 2.49 KB
/
Copy pathcallbackOnAny.ts
File metadata and controls
64 lines (55 loc) · 2.49 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
import { Context } from "probot";
import { Payload } from "../interfaces/Payload";
import { RecognizedProfits, RecognizedTimes } from "../interfaces/Recognized";
import { addLabelToIssue } from "./addLabelToIssue";
import { calculateBountyPrice } from "./calculateBountyPrice";
import { clearAllPriceLabelsOnIssue } from "./clearAllPriceLabelsOnIssue";
import getLowestLabel from "./getLowest";
export async function callbackOnAny(context: Context) {
const payload = context.payload as Payload;
if (payload.sender.type == "Bot") return;
if (context.name != "issues") return;
if (payload.issue.number != 9) return;
if (payload.action != "labeled" && payload.action != "unlabeled") return;
const labels = payload.issue.labels;
const issueTimes = labels.filter((label) => label.name.startsWith("Time:"));
const issueProfits = labels.filter((label) => label.name.startsWith("Profit:"));
if (!issueTimes.length && !issueProfits.length) return; // no labels
const lowestTime = getLowestLabel(issueTimes, RecognizedTimes);
const lowestProfit = getLowestLabel(issueProfits, RecognizedProfits);
// no time estimate, only profit labels
if (!lowestTime) {
// this should estimate the price range based on the profit labels
const range = {
"Profit: <10%": "Price: 100-400 USDC",
"Profit: <50%": "Price: 500-2000 USDC",
"Profit: <100%": "Price: 1000-4000 USDC",
"Profit: 100%+": "Price: 2000-8000 USDC",
// @ts-ignore-error
}[lowestProfit.key];
await clearAllPriceLabelsOnIssue(context);
await addLabelToIssue(context, range);
return;
// throw new Error(`No times found in issue labels ${JSON.stringify(labels.map((label) => label.name))}`);
}
// no business impact estimate
if (!lowestProfit) {
// @ts-ignore-error
const range = {
"Time: <1 Day": "Price: 100-1000 USDC",
"Time: <1 Week": "Price: 200-2000 USDC",
"Time: <2 Weeks": "Price: 300-3000 USDC",
"Time: <1 Month": "Price: 400-4000 USDC",
"Time: 1 Month+": "Price: 500-5000 USDC",
// @ts-ignore-error
}[lowestTime.key];
await clearAllPriceLabelsOnIssue(context);
await addLabelToIssue(context, range);
return;
// throw new Error(`No profits found in issue labels ${JSON.stringify(labels.map((label) => label.name))}`);
}
const bountyPrice = calculateBountyPrice(lowestTime, lowestProfit);
await clearAllPriceLabelsOnIssue(context);
await addLabelToIssue(context, `Price: ${bountyPrice} USDC`);
console.log(bountyPrice, `USDC`);
}