@kud/gh-webhook-replay 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +29 -0
  3. package/dist/index.js +143 -0
  4. package/package.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Erwann Mest
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @kud/gh-webhook-replay
2
+
3
+ Replay the latest `pull_request` webhook delivery on a GitHub repo hook — a thin
4
+ CLI over [`@kud/gh`](../gh). Useful for re-firing a Jenkins PR-builder that missed
5
+ an event.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install -g @kud/gh-webhook-replay
11
+ ```
12
+
13
+ Requires the [`gh`](https://cli.github.com) CLI, authenticated.
14
+
15
+ ## Usage
16
+
17
+ ```sh
18
+ gh-webhook-replay # pick a hook interactively (current repo)
19
+ gh-webhook-replay owner/repo # …for a specific repo
20
+ gh-webhook-replay --hook ghprbhook # headless: replay on the matched hook
21
+ gh-webhook-replay owner/repo --hook 42 # match by url substring or hook id
22
+ ```
23
+
24
+ Interactive: `↑↓` move · `↵` replay the selected hook's latest `pull_request`
25
+ delivery · `q` quit.
26
+
27
+ ## Licence
28
+
29
+ MIT © Erwann Mest
package/dist/index.js ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.tsx
4
+ import { useEffect, useState } from "react";
5
+ import { render, Box, Text, useApp, useInput } from "ink";
6
+ import { colors } from "@kud/ink-ui";
7
+ import {
8
+ fetchHookContexts,
9
+ fetchHooks,
10
+ fetchLatestPrDeliveryId,
11
+ replayDelivery,
12
+ replayLatestPrDelivery,
13
+ resolveCurrentRepo
14
+ } from "@kud/gh";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var hookLabel = (hook) => {
17
+ if (hook.contexts.length > 0) return hook.contexts.join(", ");
18
+ try {
19
+ return new URL(hook.config.url).pathname.replace(/^\/|\/$/g, "") || hook.name;
20
+ } catch {
21
+ return hook.name;
22
+ }
23
+ };
24
+ var hookHost = (hook) => {
25
+ try {
26
+ return new URL(hook.config.url).hostname;
27
+ } catch {
28
+ return hook.config.url;
29
+ }
30
+ };
31
+ var App = ({ repo }) => {
32
+ const { exit } = useApp();
33
+ const [phase, setPhase] = useState("loading");
34
+ const [hooks, setHooks] = useState([]);
35
+ const [cursor, setCursor] = useState(0);
36
+ const [msg, setMsg] = useState("");
37
+ useEffect(() => {
38
+ fetchHooks(repo).then(async (hs) => {
39
+ const withContexts = await Promise.all(
40
+ hs.map(async (h) => ({
41
+ ...h,
42
+ contexts: await fetchHookContexts(repo, h.id)
43
+ }))
44
+ );
45
+ setHooks(withContexts);
46
+ setPhase("pick");
47
+ }).catch((e) => {
48
+ setMsg(e.message);
49
+ setPhase("error");
50
+ });
51
+ }, []);
52
+ useEffect(() => {
53
+ if (phase !== "done" && phase !== "error") return;
54
+ const t = setTimeout(exit, 1800);
55
+ return () => clearTimeout(t);
56
+ }, [phase]);
57
+ useInput((input, key) => {
58
+ if (input === "q") return exit();
59
+ if (phase !== "pick") return;
60
+ if (key.upArrow || input === "k") setCursor((c) => Math.max(0, c - 1));
61
+ if (key.downArrow || input === "j")
62
+ setCursor((c) => Math.min(hooks.length - 1, c + 1));
63
+ if (key.return) {
64
+ const hook = hooks[cursor];
65
+ setPhase("replaying");
66
+ fetchLatestPrDeliveryId(repo, hook.id).then(
67
+ (id) => replayDelivery(repo, hook.id, id).then(() => {
68
+ setMsg(`delivery ${id}`);
69
+ setPhase("done");
70
+ })
71
+ ).catch((e) => {
72
+ setMsg(e.message);
73
+ setPhase("error");
74
+ });
75
+ }
76
+ });
77
+ if (phase === "loading")
78
+ return /* @__PURE__ */ jsx(Text, { color: colors.info, children: "Fetching webhooks\u2026" });
79
+ if (phase === "replaying")
80
+ return /* @__PURE__ */ jsx(Text, { color: colors.info, children: "Replaying latest pull_request\u2026" });
81
+ if (phase === "done")
82
+ return /* @__PURE__ */ jsxs(Text, { color: colors.success, children: [
83
+ "\u2713 Webhook replayed on ",
84
+ repo,
85
+ " \xB7 ",
86
+ msg
87
+ ] });
88
+ if (phase === "error") return /* @__PURE__ */ jsxs(Text, { color: colors.error, children: [
89
+ "\u2717 ",
90
+ msg
91
+ ] });
92
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
93
+ /* @__PURE__ */ jsxs(Text, { bold: true, color: colors.accent, children: [
94
+ repo,
95
+ " ",
96
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: "\xB7 pick a webhook to replay" })
97
+ ] }),
98
+ /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginTop: 1, children: hooks.map((hook, i) => {
99
+ const active = i === cursor;
100
+ return /* @__PURE__ */ jsxs(Box, { children: [
101
+ /* @__PURE__ */ jsx(Text, { color: colors.info, children: active ? "\u276F " : " " }),
102
+ /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
103
+ /* @__PURE__ */ jsx(Text, { bold: active, color: active ? colors.accent : void 0, children: hookLabel(hook) }),
104
+ /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
105
+ hookHost(hook),
106
+ " \xB7 ",
107
+ hook.events.join(", ")
108
+ ] })
109
+ ] })
110
+ ] }, hook.id);
111
+ }) }),
112
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: "\u2191\u2193 move \xB7 \u21B5 replay \xB7 q quit" }) })
113
+ ] });
114
+ };
115
+ var main = async () => {
116
+ const args = process.argv.slice(2);
117
+ const hookIdx = args.indexOf("--hook");
118
+ const hookPattern = hookIdx >= 0 ? args[hookIdx + 1] : void 0;
119
+ const positional = args.find(
120
+ (a, i) => !a.startsWith("-") && i !== hookIdx + 1
121
+ );
122
+ const repo = positional ?? await resolveCurrentRepo().catch(() => null);
123
+ if (!repo) {
124
+ console.error("\u2717 No repo \u2014 run inside a git repo, or pass owner/repo");
125
+ process.exit(1);
126
+ }
127
+ if (hookPattern) {
128
+ try {
129
+ const { hook, deliveryId } = await replayLatestPrDelivery(
130
+ repo,
131
+ hookPattern
132
+ );
133
+ console.log(`\u2713 Webhook replayed on ${repo}`);
134
+ console.log(` ${hook.config.url} \xB7 delivery ${deliveryId}`);
135
+ } catch (e) {
136
+ console.error(`\u2717 ${e.message}`);
137
+ process.exit(1);
138
+ }
139
+ return;
140
+ }
141
+ render(/* @__PURE__ */ jsx(App, { repo }), { alternateScreen: true });
142
+ };
143
+ void main();
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@kud/gh-webhook-replay",
3
+ "version": "0.1.0",
4
+ "description": "Replay the latest pull_request webhook delivery on a GitHub repo hook.",
5
+ "type": "module",
6
+ "bin": {
7
+ "gh-webhook-replay": "dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "scripts": {
16
+ "build": "tsup",
17
+ "dev": "tsup --watch",
18
+ "typecheck": "tsc --noEmit",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "github",
23
+ "webhook",
24
+ "ci",
25
+ "cli",
26
+ "ink"
27
+ ],
28
+ "author": "Erwann Mest <m@kud.io>",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/kud/gh",
33
+ "directory": "packages/gh-webhook-replay"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "dependencies": {
39
+ "@kud/gh": "0.1.0",
40
+ "@kud/ink-ui": "0.8.0",
41
+ "ink": "7.1.0",
42
+ "react": "19.2.7"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "22.20.1",
46
+ "@types/react": "19.2.17",
47
+ "tsup": "8.5.1",
48
+ "typescript": "5.9.3"
49
+ }
50
+ }