forked from ubiquity-os-marketplace/command-start-stop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin-input.ts
111 lines (99 loc) · 4.06 KB
/
plugin-input.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { StaticDecode, TLiteral, Type as T, Union } from "@sinclair/typebox";
export enum AssignedIssueScope {
ORG = "org",
REPO = "repo",
NETWORK = "network",
}
export enum Role {
OWNER = "OWNER",
ADMIN = "ADMIN",
MEMBER = "MEMBER",
COLLABORATOR = "COLLABORATOR",
}
const rolesWithReviewAuthority = T.Array(T.Enum(Role), {
default: [Role.OWNER, Role.ADMIN, Role.MEMBER, Role.COLLABORATOR],
uniqueItems: true,
description: "When considering a user for a task: which roles should be considered as having review authority? All others are ignored.",
examples: [
[Role.OWNER, Role.ADMIN],
[Role.MEMBER, Role.COLLABORATOR],
],
});
const maxConcurrentTasks = T.Transform(
T.Record(T.String(), T.Integer(), {
default: { member: 10, contributor: 2 },
description: "The maximum number of tasks a user can have assigned to them at once, based on their role.",
examples: [{ member: 5, contributor: 1 }],
})
)
.Decode((obj) => {
// normalize the role keys to lowercase
obj = Object.keys(obj).reduce(
(acc, key) => {
acc[key.toLowerCase()] = obj[key];
return acc;
},
{} as Record<string, number>
);
// If admin is omitted, defaults to infinity
if (!obj["admin"]) {
obj["admin"] = Infinity;
}
return obj;
})
.Encode((value) => value);
type IntoStringLiteralUnion<T> = { [K in keyof T]: T[K] extends string ? TLiteral<T[K]> : never };
export function stringLiteralUnion<T extends string[]>(values: [...T]): Union<IntoStringLiteralUnion<T>> {
const literals = values.map((value) => T.Literal(value));
return T.Union(literals) as Union<IntoStringLiteralUnion<T>>;
}
const roles = stringLiteralUnion(["admin", "member", "collaborator", "contributor", "owner", "billing_manager", "read", "write"]);
const requiredLabel = T.Object({
name: T.String({ description: "The name of the required labels to start the task." }),
roles: T.Array(roles, {
description: "The list of allowed roles to start the task with the given label.",
uniqueItems: true,
default: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager", "write", "read"],
}),
});
export const pluginSettingsSchema = T.Object(
{
reviewDelayTolerance: T.String({
default: "1 Day",
examples: ["1 Day", "5 Days"],
description:
"When considering a user for a task: if they have existing PRs with no reviews, how long should we wait before 'increasing' their assignable task limit?",
}),
taskStaleTimeoutDuration: T.String({
default: "30 Days",
examples: ["1 Day", "5 Days"],
description: "When displaying the '/start' response, how long should we wait before considering a task 'stale' and provide a warning?",
}),
startRequiresWallet: T.Boolean({
default: true,
description: "If true, users must set their wallet address with the /wallet command before they can start tasks.",
}),
maxConcurrentTasks: maxConcurrentTasks,
assignedIssueScope: T.Enum(AssignedIssueScope, {
default: AssignedIssueScope.ORG,
description: "When considering a user for a task: should we consider their assigned issues at the org, repo, or network level?",
examples: [AssignedIssueScope.ORG, AssignedIssueScope.REPO, AssignedIssueScope.NETWORK],
}),
emptyWalletText: T.String({
default: "Please set your wallet address with the /wallet command first and try again.",
description: "a message to display when a user tries to start a task without setting their wallet address.",
}),
rolesWithReviewAuthority: T.Transform(rolesWithReviewAuthority)
.Decode((value) => value.map((role) => role.toUpperCase()))
.Encode((value) => value.map((role) => Role[role as keyof typeof Role])),
requiredLabelsToStart: T.Array(requiredLabel, {
default: [],
description: "If set, a task must have at least one of these labels to be started.",
examples: [["Priority: 5 (Emergency)"], ["Good First Issue"]],
}),
},
{
default: {},
}
);
export type PluginSettings = StaticDecode<typeof pluginSettingsSchema>;