co-maintainer 0.4.0 → 0.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Analyzes a GitHub repository and writes repository-specific contribution guidance.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -46,6 +46,7 @@ export async function parseArgs(args) {
46
46
  console.log(" co-maintainer review owner/repo PR_NUMBER [options]");
47
47
  console.log(" co-maintainer set --token=... --ai=... --low-model=... --high-model=... --auth=...");
48
48
  console.log(" co-maintainer serve --port=N");
49
+ console.log(" co-maintainer -v | --version");
49
50
  console.log(" --webhook-url=https://host/github/webhook [or CM_WEBHOOK_URL]");
50
51
  console.log(" --env=PATH --debug --log-time --gh-concurrent=N --ai-concurrent=N");
51
52
  console.log("Options: --include-codebase --include-pull-requests --include-pull-request-changes");
@@ -11,8 +11,8 @@ export declare function resolveAuthMethods(args: string[], config: Pick<UserConf
11
11
  export declare function resolveWebhookUrl(args: string[], port: number, configured?: string): string;
12
12
  /** `co-maintainer serve --port=N [--password=...] [--disable-auth=password]
13
13
  * [--enable-auth=github] [--inject-500]`. HMAC-verified `POST /github/webhook`
14
- * plus a dashboard gated by password and/or GitHub sign-in. Requires the
15
- * GitHub App via `co-maintainer set` (webhook secret is optional, only the
16
- * App ID and private key gate startup); GitHub sign-in additionally needs
14
+ * plus a dashboard gated by password and/or GitHub sign-in. The GitHub App
15
+ * is optional at startup and can be added later from the dashboard settings
16
+ * or `co-maintainer set`. GitHub sign-in needs
17
17
  * `--github-oauth-client-id`/`-client-secret`/`-allowed-user` set. */
18
18
  export declare function runServe(args: string[]): Promise<void>;
@@ -83,9 +83,9 @@ export function resolveWebhookUrl(args, port, configured) {
83
83
  }
84
84
  /** `co-maintainer serve --port=N [--password=...] [--disable-auth=password]
85
85
  * [--enable-auth=github] [--inject-500]`. HMAC-verified `POST /github/webhook`
86
- * plus a dashboard gated by password and/or GitHub sign-in. Requires the
87
- * GitHub App via `co-maintainer set` (webhook secret is optional, only the
88
- * App ID and private key gate startup); GitHub sign-in additionally needs
86
+ * plus a dashboard gated by password and/or GitHub sign-in. The GitHub App
87
+ * is optional at startup and can be added later from the dashboard settings
88
+ * or `co-maintainer set`. GitHub sign-in needs
89
89
  * `--github-oauth-client-id`/`-client-secret`/`-allowed-user` set. */
90
90
  export async function runServe(args) {
91
91
  const portArg = args
@@ -99,14 +99,8 @@ export async function runServe(args) {
99
99
  }
100
100
  const config = readConfig();
101
101
  const webhookUrl = resolveWebhookUrl(args, port, config.webhookUrl);
102
- const missing = [
103
- !config.githubAppId && "--github-app-id=...",
104
- !config.githubAppPrivateKey &&
105
- "--github-app-private-key=... (or --github-app-private-key-file=path)",
106
- ].filter(Boolean);
107
- if (missing.length > 0) {
108
- die(`serve requires the GitHub App to be configured first; run:\n` +
109
- ` co-maintainer set ${missing.join(" ")}`);
102
+ if (!config.githubAppId || !config.githubAppPrivateKey) {
103
+ console.log("[serve] GitHub App is not configured yet. Add it in the dashboard settings or with co-maintainer set.");
110
104
  }
111
105
  const auth = resolveAuthMethods(args, config);
112
106
  let githubOAuth;
@@ -157,13 +151,6 @@ export async function runServe(args) {
157
151
  }
158
152
  const app = createApp({
159
153
  password,
160
- githubApp: config.githubAppId && config.githubAppPrivateKey
161
- ? {
162
- appId: config.githubAppId,
163
- privateKeyPem: config.githubAppPrivateKey,
164
- }
165
- : undefined,
166
- webhookSecret: config.githubWebhookSecret,
167
154
  webhookUrl,
168
155
  inject500,
169
156
  auth,
@@ -6,7 +6,12 @@ import { runSet } from "./commands/set.js";
6
6
  import { runProbe } from "./commands/probe.js";
7
7
  import { runReviewFromCli } from "./commands/review.js";
8
8
  import { runInitOrRemake } from "../services/setup.js";
9
+ import { VERSION } from "../version.js";
9
10
  export async function run(args) {
11
+ if (args[0] === "-v" || args[0] === "--version") {
12
+ console.log(VERSION);
13
+ return;
14
+ }
10
15
  if (args[0] === "set") {
11
16
  await runSet(args.slice(1));
12
17
  return;
@@ -1,14 +1,8 @@
1
1
  import type { AuthMethods } from "./auth.ts";
2
2
  /** `password` is the dashboard password `serve` generates or takes via
3
- * `--password`. `githubApp` is unset until `co-maintainer set` has both
4
- * the App ID and private key. */
3
+ * `--password`. */
5
4
  export type AppDeps = {
6
5
  password: string;
7
- githubApp?: {
8
- appId: string;
9
- privateKeyPem: string;
10
- };
11
- webhookSecret?: string;
12
6
  webhookUrl?: string;
13
7
  secureCookie?: boolean;
14
8
  inject500?: boolean;
@@ -78,18 +78,33 @@ function health() {
78
78
  db,
79
79
  });
80
80
  }
81
+ /** Read per request so credentials saved from the dashboard take effect
82
+ * without restarting `serve`. */
83
+ function liveGithubConfig() {
84
+ const config = readConfig();
85
+ return {
86
+ githubApp: config.githubAppId && config.githubAppPrivateKey
87
+ ? {
88
+ appId: config.githubAppId,
89
+ privateKeyPem: config.githubAppPrivateKey,
90
+ }
91
+ : undefined,
92
+ webhookSecret: config.githubWebhookSecret,
93
+ };
94
+ }
81
95
  export function createApp(deps) {
82
96
  return {
83
97
  async fetch(request, remoteAddr = "unknown") {
84
98
  const url = new URL(request.url);
99
+ const { githubApp, webhookSecret } = liveGithubConfig();
85
100
  const mutating = ["POST", "PATCH", "PUT", "DELETE"].includes(request.method);
86
101
  if (url.pathname === "/api/health" && request.method === "GET") {
87
102
  return health();
88
103
  }
89
104
  if (url.pathname === "/github/webhook" && request.method === "POST") {
90
- return await handleWebhookRequest(request, deps.webhookSecret);
105
+ return await handleWebhookRequest(request, webhookSecret);
91
106
  }
92
- const page = await handlePageRequest(request, deps, remoteAddr);
107
+ const page = await handlePageRequest(request, { ...deps, githubApp }, remoteAddr);
93
108
  if (page)
94
109
  return page;
95
110
  if (url.pathname.startsWith("/api/remote/")) {
@@ -122,10 +137,10 @@ export function createApp(deps) {
122
137
  return handleJobsRoute(request, url);
123
138
  }
124
139
  if (url.pathname.startsWith("/api/repos")) {
125
- return await handleReposRoute(request, url, deps.githubApp);
140
+ return await handleReposRoute(request, url, githubApp);
126
141
  }
127
142
  if (url.pathname === "/api/installations") {
128
- return await handleInstallationsRoute(request, deps.githubApp);
143
+ return await handleInstallationsRoute(request, githubApp);
129
144
  }
130
145
  if (url.pathname.startsWith("/api/settings")) {
131
146
  return await handleSettingsRoute(request, url, deps.webhookUrl ?? "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Analyzes a GitHub repository and writes repository-specific contribution guidance.",
5
5
  "license": "MIT",
6
6
  "repository": {