pollhook 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +251 -2
- package/dist/adapters/branch-protection.js +42 -0
- package/dist/adapters/check-run.js +23 -0
- package/dist/adapters/check-suite.js +23 -0
- package/dist/adapters/code-scanning-alert.js +34 -0
- package/dist/adapters/commit-comment.js +20 -0
- package/dist/adapters/common.js +36 -0
- package/dist/adapters/dependabot-alert.js +26 -0
- package/dist/adapters/deploy-key.js +34 -0
- package/dist/adapters/deployment-protection-rule.js +60 -0
- package/dist/adapters/deployment-review.js +48 -0
- package/dist/adapters/deployment-status.js +30 -0
- package/dist/adapters/deployment.js +20 -0
- package/dist/adapters/dispatch.js +53 -0
- package/dist/adapters/fork.js +20 -0
- package/dist/adapters/issue-comment.js +25 -0
- package/dist/adapters/issues.js +45 -0
- package/dist/adapters/label.js +33 -0
- package/dist/adapters/member.js +38 -0
- package/dist/adapters/membership.js +57 -0
- package/dist/adapters/milestone.js +48 -0
- package/dist/adapters/page-build.js +29 -0
- package/dist/adapters/pull-request-review-comment.js +30 -0
- package/dist/adapters/pull-request-review.js +35 -0
- package/dist/adapters/pull-request.js +50 -0
- package/dist/adapters/push.js +78 -0
- package/dist/adapters/refs.js +94 -0
- package/dist/adapters/release.js +33 -0
- package/dist/adapters/repository-advisory.js +27 -0
- package/dist/adapters/repository-ruleset.js +33 -0
- package/dist/adapters/repository.js +71 -0
- package/dist/adapters/secret-scanning-alert.js +33 -0
- package/dist/adapters/security-and-analysis.js +24 -0
- package/dist/adapters/status.js +33 -0
- package/dist/adapters/team.js +34 -0
- package/dist/adapters/vulnerability-alert.js +17 -0
- package/dist/adapters/workflow-job.js +33 -0
- package/dist/adapters/workflow-run.js +34 -0
- package/dist/cli/args.js +54 -0
- package/dist/cli/commands.js +146 -0
- package/dist/cli/docs.js +55 -0
- package/dist/cli/format.js +23 -0
- package/dist/cli/rpc.js +57 -0
- package/dist/cli/spec.js +86 -0
- package/dist/cli/usage.js +7 -0
- package/dist/cli.js +33 -0
- package/dist/config/tuning.js +47 -0
- package/dist/config.js +125 -0
- package/dist/daemon/context.js +1 -0
- package/dist/daemon/handlers.js +102 -0
- package/dist/daemon/runtime.js +71 -0
- package/dist/daemon/waiter.js +48 -0
- package/dist/daemon/watch.js +27 -0
- package/dist/daemon.js +83 -0
- package/dist/db/cursors.js +16 -0
- package/dist/db/deliveries.js +55 -0
- package/dist/db/durations.js +36 -0
- package/dist/db/schema.js +40 -0
- package/dist/db/snapshots.js +36 -0
- package/dist/db/store.js +71 -0
- package/dist/db.js +1 -0
- package/dist/delivery.js +57 -0
- package/dist/github.js +175 -0
- package/dist/poller/refs.js +36 -0
- package/dist/poller/schedule.js +28 -0
- package/dist/poller/status.js +33 -0
- package/dist/poller.js +160 -0
- package/dist/registry.js +86 -0
- package/dist/types.js +1 -0
- package/dist/util.js +45 -0
- package/dist/waits.js +114 -0
- package/package.json +39 -4
package/dist/poller.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { adaptersFor } from "./registry.js";
|
|
2
|
+
import { HeadCache, refsFor } from "./poller/refs.js";
|
|
3
|
+
import { delayFor, resolveInterval, resolveStrategy } from "./poller/schedule.js";
|
|
4
|
+
import { DEGRADED_MS, isPermanent, statusFor, statusList, } from "./poller/status.js";
|
|
5
|
+
import { errorMessage, nowIso } from "./util.js";
|
|
6
|
+
const TICK_MS = 1000;
|
|
7
|
+
export class Poller {
|
|
8
|
+
nextDue = new Map();
|
|
9
|
+
statuses = new Map();
|
|
10
|
+
headCache = new HeadCache();
|
|
11
|
+
degraded = new Map();
|
|
12
|
+
timer = null;
|
|
13
|
+
stopped = false;
|
|
14
|
+
running = false;
|
|
15
|
+
config;
|
|
16
|
+
db;
|
|
17
|
+
gh;
|
|
18
|
+
emit;
|
|
19
|
+
constructor(config, db, gh, emit) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.db = db;
|
|
22
|
+
this.gh = gh;
|
|
23
|
+
this.emit = emit;
|
|
24
|
+
for (const repo of config.repos) {
|
|
25
|
+
this.statuses.set(repo.repo, statusFor("repo", repo.repo, repo.events));
|
|
26
|
+
}
|
|
27
|
+
for (const org of config.orgs) {
|
|
28
|
+
this.statuses.set(org.org, statusFor("org", org.org, org.events));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
start() {
|
|
32
|
+
this.schedule(0);
|
|
33
|
+
}
|
|
34
|
+
stop() {
|
|
35
|
+
this.stopped = true;
|
|
36
|
+
if (this.timer)
|
|
37
|
+
clearTimeout(this.timer);
|
|
38
|
+
}
|
|
39
|
+
markEvent(target) {
|
|
40
|
+
const status = this.statuses.get(target);
|
|
41
|
+
if (status)
|
|
42
|
+
status.lastEventAt = nowIso();
|
|
43
|
+
}
|
|
44
|
+
listStatuses() {
|
|
45
|
+
return statusList(this.statuses, this.nextDue, this.degraded);
|
|
46
|
+
}
|
|
47
|
+
async pollOnce() {
|
|
48
|
+
if (this.stopped)
|
|
49
|
+
return;
|
|
50
|
+
for (const repo of this.config.repos) {
|
|
51
|
+
await this.pollTarget("repo", repo.repo, repo.events, repo, repo.checkRefLimit);
|
|
52
|
+
}
|
|
53
|
+
for (const org of this.config.orgs) {
|
|
54
|
+
await this.pollTarget("org", org.org, org.events, org, 0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async pollTarget(kind, name, events, target, checkRefLimit) {
|
|
58
|
+
const roundError = await this.pollAdapters(kind, name, events, target, checkRefLimit);
|
|
59
|
+
const status = this.statuses.get(name);
|
|
60
|
+
if (!status)
|
|
61
|
+
return;
|
|
62
|
+
if (roundError) {
|
|
63
|
+
status.lastError = roundError;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
status.lastPollAt = nowIso();
|
|
67
|
+
status.lastError = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async pollAdapters(kind, name, events, target, checkRefLimit) {
|
|
71
|
+
let roundError = null;
|
|
72
|
+
let refs = [];
|
|
73
|
+
if (kind === "repo") {
|
|
74
|
+
try {
|
|
75
|
+
refs = await refsFor(this.db, this.headCache, this.gh, name, events, checkRefLimit);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
roundError = errorMessage(error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const adapter of adaptersFor(events, kind)) {
|
|
82
|
+
try {
|
|
83
|
+
const polled = await this.pollAdapter(kind, name, refs, resolveInterval(this.config, target, adapter), resolveStrategy(this.config, target, adapter), adapter);
|
|
84
|
+
if (polled)
|
|
85
|
+
this.clearDegraded(name, adapter.name);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (isPermanent(error)) {
|
|
89
|
+
this.markDegraded(name, adapter.name, error);
|
|
90
|
+
this.nextDue.set(`${kind}:${name}:${adapter.name}`, Date.now() + DEGRADED_MS);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
roundError = roundError ?? errorMessage(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return roundError;
|
|
98
|
+
}
|
|
99
|
+
markDegraded(name, event, error) {
|
|
100
|
+
const events = this.degraded.get(name) ?? new Map();
|
|
101
|
+
if (!events.has(event))
|
|
102
|
+
events.set(event, errorMessage(error));
|
|
103
|
+
this.degraded.set(name, events);
|
|
104
|
+
}
|
|
105
|
+
clearDegraded(name, event) {
|
|
106
|
+
this.degraded.get(name)?.delete(event);
|
|
107
|
+
}
|
|
108
|
+
async pollAdapter(kind, name, refs, intervalMs, strategy, adapter) {
|
|
109
|
+
const dueKey = `${kind}:${name}:${adapter.name}`;
|
|
110
|
+
if ((this.nextDue.get(dueKey) ?? 0) > Date.now())
|
|
111
|
+
return false;
|
|
112
|
+
const pressure = this.gh.pressure?.() ?? 1;
|
|
113
|
+
this.nextDue.set(dueKey, Date.now() + delayFor(adapter, intervalMs, this.db, name, strategy, pressure));
|
|
114
|
+
const primedKey = `primed:${kind}:${name}:${adapter.name}`;
|
|
115
|
+
const cold = this.db.getCursor(primedKey) === null;
|
|
116
|
+
await adapter.poll({
|
|
117
|
+
repo: name,
|
|
118
|
+
org: kind === "org" ? name : null,
|
|
119
|
+
refs,
|
|
120
|
+
db: this.db,
|
|
121
|
+
durations: this.db.durations,
|
|
122
|
+
gh: this.gh,
|
|
123
|
+
emit: cold
|
|
124
|
+
? () => { }
|
|
125
|
+
: (event, action, key, payload, state) => this.emit(name, event, action, key, payload, state),
|
|
126
|
+
});
|
|
127
|
+
if (cold)
|
|
128
|
+
this.db.setCursor(primedKey, null, "1");
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
poke(target) {
|
|
132
|
+
if (target && !this.statuses.has(target))
|
|
133
|
+
return false;
|
|
134
|
+
for (const key of this.nextDue.keys()) {
|
|
135
|
+
const [, name, adapter] = key.split(":");
|
|
136
|
+
if (target && name !== target)
|
|
137
|
+
continue;
|
|
138
|
+
if (this.degraded.get(name)?.has(adapter))
|
|
139
|
+
continue;
|
|
140
|
+
this.nextDue.delete(key);
|
|
141
|
+
}
|
|
142
|
+
if (!this.running && !this.stopped) {
|
|
143
|
+
if (this.timer)
|
|
144
|
+
clearTimeout(this.timer);
|
|
145
|
+
this.schedule(0);
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
loop() {
|
|
150
|
+
this.running = true;
|
|
151
|
+
void this.pollOnce().finally(() => {
|
|
152
|
+
this.running = false;
|
|
153
|
+
if (!this.stopped)
|
|
154
|
+
this.schedule(TICK_MS);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
schedule(delay) {
|
|
158
|
+
this.timer = setTimeout(() => this.loop(), delay);
|
|
159
|
+
}
|
|
160
|
+
}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { branchProtection } from "./adapters/branch-protection.js";
|
|
2
|
+
import { checkRun } from "./adapters/check-run.js";
|
|
3
|
+
import { checkSuite } from "./adapters/check-suite.js";
|
|
4
|
+
import { pageBuild } from "./adapters/page-build.js";
|
|
5
|
+
import { pullRequest } from "./adapters/pull-request.js";
|
|
6
|
+
import { pullRequestReview } from "./adapters/pull-request-review.js";
|
|
7
|
+
import { pullRequestReviewComment } from "./adapters/pull-request-review-comment.js";
|
|
8
|
+
import { push } from "./adapters/push.js";
|
|
9
|
+
import { createRef, deleteRef } from "./adapters/refs.js";
|
|
10
|
+
import { codeScanningAlert } from "./adapters/code-scanning-alert.js";
|
|
11
|
+
import { commitComment } from "./adapters/commit-comment.js";
|
|
12
|
+
import { dependabotAlert } from "./adapters/dependabot-alert.js";
|
|
13
|
+
import { deployKey } from "./adapters/deploy-key.js";
|
|
14
|
+
import { deployment } from "./adapters/deployment.js";
|
|
15
|
+
import { deploymentProtectionRule } from "./adapters/deployment-protection-rule.js";
|
|
16
|
+
import { deploymentReview } from "./adapters/deployment-review.js";
|
|
17
|
+
import { deploymentStatus } from "./adapters/deployment-status.js";
|
|
18
|
+
import { mergeGroup, workflowDispatch } from "./adapters/dispatch.js";
|
|
19
|
+
import { fork } from "./adapters/fork.js";
|
|
20
|
+
import { issueComment } from "./adapters/issue-comment.js";
|
|
21
|
+
import { issues } from "./adapters/issues.js";
|
|
22
|
+
import { label } from "./adapters/label.js";
|
|
23
|
+
import { member } from "./adapters/member.js";
|
|
24
|
+
import { membership } from "./adapters/membership.js";
|
|
25
|
+
import { team } from "./adapters/team.js";
|
|
26
|
+
import { milestone } from "./adapters/milestone.js";
|
|
27
|
+
import { publicEvent, repository } from "./adapters/repository.js";
|
|
28
|
+
import { repositoryAdvisory } from "./adapters/repository-advisory.js";
|
|
29
|
+
import { repositoryRuleset } from "./adapters/repository-ruleset.js";
|
|
30
|
+
import { securityAndAnalysis } from "./adapters/security-and-analysis.js";
|
|
31
|
+
import { secretScanningAlert } from "./adapters/secret-scanning-alert.js";
|
|
32
|
+
import { vulnerabilityAlert } from "./adapters/vulnerability-alert.js";
|
|
33
|
+
import { release } from "./adapters/release.js";
|
|
34
|
+
import { commitStatus } from "./adapters/status.js";
|
|
35
|
+
import { workflowJob } from "./adapters/workflow-job.js";
|
|
36
|
+
import { workflowRun } from "./adapters/workflow-run.js";
|
|
37
|
+
export const ADAPTERS = {
|
|
38
|
+
push,
|
|
39
|
+
create: createRef,
|
|
40
|
+
delete: deleteRef,
|
|
41
|
+
issues,
|
|
42
|
+
issue_comment: issueComment,
|
|
43
|
+
release,
|
|
44
|
+
label,
|
|
45
|
+
milestone,
|
|
46
|
+
repository,
|
|
47
|
+
public: publicEvent,
|
|
48
|
+
fork,
|
|
49
|
+
commit_comment: commitComment,
|
|
50
|
+
workflow_dispatch: workflowDispatch,
|
|
51
|
+
merge_group: mergeGroup,
|
|
52
|
+
dependabot_alert: dependabotAlert,
|
|
53
|
+
code_scanning_alert: codeScanningAlert,
|
|
54
|
+
secret_scanning_alert: secretScanningAlert,
|
|
55
|
+
deployment,
|
|
56
|
+
deployment_status: deploymentStatus,
|
|
57
|
+
deployment_protection_rule: deploymentProtectionRule,
|
|
58
|
+
deployment_review: deploymentReview,
|
|
59
|
+
deploy_key: deployKey,
|
|
60
|
+
repository_ruleset: repositoryRuleset,
|
|
61
|
+
repository_advisory: repositoryAdvisory,
|
|
62
|
+
repository_vulnerability_alert: vulnerabilityAlert,
|
|
63
|
+
security_and_analysis: securityAndAnalysis,
|
|
64
|
+
branch_protection_configuration: branchProtection,
|
|
65
|
+
member,
|
|
66
|
+
team,
|
|
67
|
+
membership,
|
|
68
|
+
workflow_run: workflowRun,
|
|
69
|
+
workflow_job: workflowJob,
|
|
70
|
+
check_suite: checkSuite,
|
|
71
|
+
check_run: checkRun,
|
|
72
|
+
pull_request: pullRequest,
|
|
73
|
+
pull_request_review: pullRequestReview,
|
|
74
|
+
pull_request_review_comment: pullRequestReviewComment,
|
|
75
|
+
page_build: pageBuild,
|
|
76
|
+
status: commitStatus,
|
|
77
|
+
};
|
|
78
|
+
export const IMPLEMENTED_EVENTS = Object.keys(ADAPTERS);
|
|
79
|
+
export function adaptersFor(events, scope = "repo") {
|
|
80
|
+
return events
|
|
81
|
+
.map((event) => ADAPTERS[event])
|
|
82
|
+
.filter((adapter) => (adapter.scope ?? "repo") === scope);
|
|
83
|
+
}
|
|
84
|
+
export function implementedEvents(scope) {
|
|
85
|
+
return IMPLEMENTED_EVENTS.filter((event) => (ADAPTERS[event].scope ?? "repo") === scope);
|
|
86
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
export function nowIso() {
|
|
4
|
+
return new Date().toISOString();
|
|
5
|
+
}
|
|
6
|
+
export function sha256(input) {
|
|
7
|
+
return createHash("sha256").update(input).digest("hex");
|
|
8
|
+
}
|
|
9
|
+
export function sleep(ms) {
|
|
10
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
+
}
|
|
12
|
+
export function expandHome(path) {
|
|
13
|
+
if (path === "~")
|
|
14
|
+
return homedir();
|
|
15
|
+
if (path.startsWith("~/"))
|
|
16
|
+
return `${homedir()}/${path.slice(2)}`;
|
|
17
|
+
return path;
|
|
18
|
+
}
|
|
19
|
+
export function formatDuration(ms) {
|
|
20
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
21
|
+
if (seconds < 60)
|
|
22
|
+
return `${seconds}s`;
|
|
23
|
+
const minutes = Math.floor(seconds / 60);
|
|
24
|
+
if (minutes < 60)
|
|
25
|
+
return seconds % 60 ? `${minutes}m${seconds % 60}s` : `${minutes}m`;
|
|
26
|
+
return `${Math.floor(minutes / 60)}h${minutes % 60}m`;
|
|
27
|
+
}
|
|
28
|
+
export function unique(values) {
|
|
29
|
+
return [...new Set(values)];
|
|
30
|
+
}
|
|
31
|
+
export function pick(value, path) {
|
|
32
|
+
let current = value;
|
|
33
|
+
for (const part of path.split(".")) {
|
|
34
|
+
if (current == null)
|
|
35
|
+
return undefined;
|
|
36
|
+
current = current[part];
|
|
37
|
+
}
|
|
38
|
+
return current;
|
|
39
|
+
}
|
|
40
|
+
export function errorMessage(error) {
|
|
41
|
+
return error instanceof Error ? error.message : String(error);
|
|
42
|
+
}
|
|
43
|
+
export function isStatus(error, status) {
|
|
44
|
+
return error instanceof Error && error.message.startsWith(`${status} `);
|
|
45
|
+
}
|
package/dist/waits.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { pick } from "./util.js";
|
|
2
|
+
const FAILED = new Set(["failure", "timed_out", "cancelled", "action_required", "stale"]);
|
|
3
|
+
const SUCCESS = new Set(["success", "neutral", "skipped"]);
|
|
4
|
+
export function resolveWait(db, request) {
|
|
5
|
+
switch (request.kind) {
|
|
6
|
+
case "run":
|
|
7
|
+
return resolveRun(db, request);
|
|
8
|
+
case "checks":
|
|
9
|
+
return resolveChecks(db, request);
|
|
10
|
+
case "pr":
|
|
11
|
+
return resolvePullRequest(db, request);
|
|
12
|
+
case "pages":
|
|
13
|
+
return resolvePages(db, request);
|
|
14
|
+
case "event":
|
|
15
|
+
return resolveEvent(db, request);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function resolveRun(db, request) {
|
|
19
|
+
const snapshot = db.getSnapshot(request.repo, "workflow_run", request.id);
|
|
20
|
+
if (!snapshot)
|
|
21
|
+
return null;
|
|
22
|
+
const run = snapshot.data;
|
|
23
|
+
if (run?.status !== "completed")
|
|
24
|
+
return null;
|
|
25
|
+
return {
|
|
26
|
+
exitCode: SUCCESS.has(run.conclusion) ? 0 : 1,
|
|
27
|
+
body: {
|
|
28
|
+
name: run.name,
|
|
29
|
+
conclusion: run.conclusion,
|
|
30
|
+
head_sha: run.head_sha,
|
|
31
|
+
url: run.html_url,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function resolveChecks(db, request) {
|
|
36
|
+
const pull = db.getSnapshot(request.repo, "pull_request", String(request.pr));
|
|
37
|
+
const head = pull?.data?.head?.sha;
|
|
38
|
+
if (!head)
|
|
39
|
+
return null;
|
|
40
|
+
const runs = db
|
|
41
|
+
.listSnapshots(request.repo, "check_run")
|
|
42
|
+
.filter((row) => row.data?.head_sha === head);
|
|
43
|
+
if (runs.length === 0)
|
|
44
|
+
return null;
|
|
45
|
+
if (runs.some((row) => row.data?.status !== "completed"))
|
|
46
|
+
return null;
|
|
47
|
+
const failing = runs
|
|
48
|
+
.filter((row) => FAILED.has(row.data?.conclusion))
|
|
49
|
+
.map((row) => row.data?.name ?? row.key);
|
|
50
|
+
return {
|
|
51
|
+
exitCode: failing.length > 0 ? 1 : 0,
|
|
52
|
+
body: {
|
|
53
|
+
head_sha: head,
|
|
54
|
+
total: runs.length,
|
|
55
|
+
failing,
|
|
56
|
+
restarted: Boolean(request.initialHead && request.initialHead !== head),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function resolvePullRequest(db, request) {
|
|
61
|
+
const snapshot = db.getSnapshot(request.repo, "pull_request", String(request.pr));
|
|
62
|
+
if (!snapshot)
|
|
63
|
+
return null;
|
|
64
|
+
const pull = snapshot.data;
|
|
65
|
+
const base = {
|
|
66
|
+
number: request.pr,
|
|
67
|
+
state: pull?.state,
|
|
68
|
+
merged: pull?.merged,
|
|
69
|
+
mergeable: pull?.mergeable,
|
|
70
|
+
};
|
|
71
|
+
if (request.until === "merged") {
|
|
72
|
+
if (pull?.merged === true)
|
|
73
|
+
return { exitCode: 0, body: base };
|
|
74
|
+
if (pull?.state === "closed")
|
|
75
|
+
return { exitCode: 1, body: base };
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (request.until === "closed") {
|
|
79
|
+
return pull?.state === "closed" ? { exitCode: 0, body: base } : null;
|
|
80
|
+
}
|
|
81
|
+
if (request.until === "reviewed") {
|
|
82
|
+
const reviews = db
|
|
83
|
+
.listSnapshots(request.repo, "pull_request_review")
|
|
84
|
+
.filter((row) => row.key.startsWith(`${request.pr}:`) && row.data?.state !== "DISMISSED");
|
|
85
|
+
if (reviews.length === 0)
|
|
86
|
+
return null;
|
|
87
|
+
return { exitCode: 0, body: { ...base, reviews: reviews.length } };
|
|
88
|
+
}
|
|
89
|
+
if (pull?.mergeable === false) {
|
|
90
|
+
return { exitCode: 0, body: { ...base, mergeable_state: pull?.mergeable_state } };
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
function resolvePages(db, request) {
|
|
95
|
+
const builds = db
|
|
96
|
+
.listSnapshots(request.repo, "page_build")
|
|
97
|
+
.filter((row) => row.data?.build?.commit === request.sha);
|
|
98
|
+
const latest = builds[0];
|
|
99
|
+
if (!latest)
|
|
100
|
+
return null;
|
|
101
|
+
const status = latest.data?.build?.status;
|
|
102
|
+
if (status !== "built" && status !== "errored")
|
|
103
|
+
return null;
|
|
104
|
+
return {
|
|
105
|
+
exitCode: status === "built" ? 0 : 1,
|
|
106
|
+
body: { status, commit: request.sha, url: latest.data?.build?.url },
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function resolveEvent(db, request) {
|
|
110
|
+
const recent = db.listDeliveries(50, request.repo);
|
|
111
|
+
const match = recent.find((delivery) => delivery.event === request.event &&
|
|
112
|
+
Object.entries(request.match).every(([path, expected]) => String(pick(delivery.payload, path)) === expected));
|
|
113
|
+
return match ? { exitCode: 0, body: match.payload } : null;
|
|
114
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pollhook",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "GitHub webhook deliveries without webhooks: a local listener fed by REST API polling",
|
|
5
|
+
"bin": {
|
|
6
|
+
"pollhook": "./dist/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start": "node src/cli.ts daemon",
|
|
14
|
+
"test": "node --test test/*.test.ts",
|
|
15
|
+
"typecheck": "tsc --noEmit",
|
|
16
|
+
"build": "tsc -p tsconfig.build.json",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"docs": "node scripts/cli-docs.ts",
|
|
19
|
+
"docs:check": "node scripts/cli-docs.ts --check",
|
|
20
|
+
"lint": "oxlint src test scripts",
|
|
21
|
+
"format": "oxfmt",
|
|
22
|
+
"format:check": "oxfmt --check src test scripts"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^26.6.10",
|
|
26
|
+
"knip": "^6.48.0",
|
|
27
|
+
"listr2": "^11.4.1",
|
|
28
|
+
"oxfmt": "^0.80.0",
|
|
29
|
+
"oxlint": "^1.95.0",
|
|
30
|
+
"publint": "^0.3.25",
|
|
31
|
+
"typescript": "^7.0.2"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=24"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/radomir-dev/pollhook.git"
|
|
40
|
+
}
|
|
41
|
+
}
|