@hikae/ledger-core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/issue.d.ts +51 -0
- package/dist/issue.js +97 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/issue.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type Row = Record<string, any>;
|
|
2
|
+
type Blocker = (issue: {
|
|
3
|
+
state: string;
|
|
4
|
+
labels: {
|
|
5
|
+
name: string;
|
|
6
|
+
}[];
|
|
7
|
+
}) => string | null | undefined;
|
|
8
|
+
export declare function applyIssue(row: Row | null, data: Row, now: string, blocker: Blocker): {
|
|
9
|
+
schema_version: number;
|
|
10
|
+
kind: string;
|
|
11
|
+
repository: any;
|
|
12
|
+
number: any;
|
|
13
|
+
url: any;
|
|
14
|
+
status: "triage" | "queued" | "in_progress" | "verifying" | "human_required" | "backlog" | "completed" | "closed";
|
|
15
|
+
added_at: any;
|
|
16
|
+
started_at: any;
|
|
17
|
+
completed_at: any;
|
|
18
|
+
blocker: string | null;
|
|
19
|
+
live: {
|
|
20
|
+
title: any;
|
|
21
|
+
author: any;
|
|
22
|
+
labels: any;
|
|
23
|
+
state: any;
|
|
24
|
+
updated_at: any;
|
|
25
|
+
};
|
|
26
|
+
history: any[];
|
|
27
|
+
last_synced_at: string;
|
|
28
|
+
} | null;
|
|
29
|
+
export declare function withStoredLabels(row: Row | null, stored: unknown, blocker: Blocker): Row | null;
|
|
30
|
+
export declare function toIssueCard(row: Row): {
|
|
31
|
+
kind: string;
|
|
32
|
+
url: any;
|
|
33
|
+
repository: any;
|
|
34
|
+
pr_number: any;
|
|
35
|
+
status: any;
|
|
36
|
+
priority: null;
|
|
37
|
+
title: any;
|
|
38
|
+
author: any;
|
|
39
|
+
action: any;
|
|
40
|
+
last_error: null;
|
|
41
|
+
labels: any;
|
|
42
|
+
updated_at: any;
|
|
43
|
+
added_at: any;
|
|
44
|
+
started_at: any;
|
|
45
|
+
approved_at: null;
|
|
46
|
+
changes_requested_at: null;
|
|
47
|
+
merged_at: null;
|
|
48
|
+
completed_at: any;
|
|
49
|
+
queue: null;
|
|
50
|
+
};
|
|
51
|
+
export {};
|
package/dist/issue.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { issueStage } from "./stage.js";
|
|
2
|
+
// Applies one Issue event to its row. Returns the next row, or null when the event is older than the row.
|
|
3
|
+
export function applyIssue(row, data, now, blocker) {
|
|
4
|
+
const i = data.issue;
|
|
5
|
+
if (row?.live?.updated_at &&
|
|
6
|
+
i.updated_at &&
|
|
7
|
+
i.updated_at < row.live.updated_at)
|
|
8
|
+
return null;
|
|
9
|
+
const labels = i.labels.map((name) => ({ name }));
|
|
10
|
+
const status = i.deleted
|
|
11
|
+
? "closed"
|
|
12
|
+
: issueStage({ state: i.state, state_reason: i.state_reason, labels });
|
|
13
|
+
const history = [...(row?.history || [])];
|
|
14
|
+
if (row?.status !== status)
|
|
15
|
+
history.push({ status, at: now, event: data.conclusion });
|
|
16
|
+
return {
|
|
17
|
+
schema_version: 1,
|
|
18
|
+
kind: "issue",
|
|
19
|
+
repository: data.repository.full_name,
|
|
20
|
+
number: i.number,
|
|
21
|
+
url: i.url,
|
|
22
|
+
status,
|
|
23
|
+
added_at: row?.added_at || i.created_at || now,
|
|
24
|
+
started_at: row?.started_at ??
|
|
25
|
+
(["in_progress", "verifying"].includes(status) ? now : null),
|
|
26
|
+
completed_at: status === "completed" ? i.closed_at || now : null,
|
|
27
|
+
blocker: status === "triage"
|
|
28
|
+
? "awaiting triage"
|
|
29
|
+
: status === "queued"
|
|
30
|
+
? (blocker({ state: i.state, labels }) ?? "waiting for a run slot")
|
|
31
|
+
: null,
|
|
32
|
+
live: {
|
|
33
|
+
title: i.title,
|
|
34
|
+
author: i.author,
|
|
35
|
+
labels: i.labels,
|
|
36
|
+
state: i.state,
|
|
37
|
+
updated_at: i.updated_at,
|
|
38
|
+
},
|
|
39
|
+
history: history.slice(-50),
|
|
40
|
+
last_synced_at: now,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// The factory stage of an open Issue lives in the state store, not in GitHub labels (docs/state-store.md); the
|
|
44
|
+
// webhook copy of the labels alone left every stored stage at triage on the board. `stored` is the store item's label
|
|
45
|
+
// list (null when the store has no row): it is merged with the GitHub labels and the stage is recomputed.
|
|
46
|
+
export function withStoredLabels(row, stored, blocker) {
|
|
47
|
+
if (!row ||
|
|
48
|
+
row.kind !== "issue" ||
|
|
49
|
+
row.live?.state !== "open" ||
|
|
50
|
+
!Array.isArray(stored))
|
|
51
|
+
return row;
|
|
52
|
+
const names = [
|
|
53
|
+
...new Set([
|
|
54
|
+
...(row.live.labels || []).map((l) => String(typeof l === "object" && l !== null ? (l.name ?? l) : l)),
|
|
55
|
+
...stored.map(String),
|
|
56
|
+
]),
|
|
57
|
+
];
|
|
58
|
+
// The factory's own pause (factory:held) reads as factory:paused, as on GitHub (src/state.mjs view).
|
|
59
|
+
if (names.includes("factory:held") && !names.includes("factory:paused"))
|
|
60
|
+
names.push("factory:paused");
|
|
61
|
+
const labels = names.map((name) => ({ name }));
|
|
62
|
+
const status = issueStage({ state: "open", labels });
|
|
63
|
+
return {
|
|
64
|
+
...row,
|
|
65
|
+
status,
|
|
66
|
+
blocker: status === "triage"
|
|
67
|
+
? "awaiting triage"
|
|
68
|
+
: status === "queued"
|
|
69
|
+
? (blocker({ state: "open", labels }) ?? "waiting for a run slot")
|
|
70
|
+
: null,
|
|
71
|
+
live: { ...row.live, labels: names },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// Board card for an Issue row, in the same shape as toCard() so the Web UI renders it in the same columns.
|
|
75
|
+
export function toIssueCard(row) {
|
|
76
|
+
return {
|
|
77
|
+
kind: "issue",
|
|
78
|
+
url: row.url,
|
|
79
|
+
repository: row.repository,
|
|
80
|
+
pr_number: row.number,
|
|
81
|
+
status: row.status,
|
|
82
|
+
priority: null,
|
|
83
|
+
title: row.live?.title ?? null,
|
|
84
|
+
author: row.live?.author ?? null,
|
|
85
|
+
action: row.blocker ?? null,
|
|
86
|
+
last_error: null,
|
|
87
|
+
labels: row.live?.labels ?? [],
|
|
88
|
+
updated_at: row.last_synced_at ?? null,
|
|
89
|
+
added_at: row.added_at ?? null,
|
|
90
|
+
started_at: row.started_at ?? null,
|
|
91
|
+
approved_at: null,
|
|
92
|
+
changes_requested_at: null,
|
|
93
|
+
merged_at: null,
|
|
94
|
+
completed_at: row.completed_at ?? null,
|
|
95
|
+
queue: null,
|
|
96
|
+
};
|
|
97
|
+
}
|
package/package.json
CHANGED