@notation/factory-cli 0.1.6 → 0.1.8

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/commands/repo.ts CHANGED
@@ -2,7 +2,7 @@ import { existsSync, realpathSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { createInterface } from "node:readline/promises";
4
4
  import { pathToFileURL } from "node:url";
5
- import { appName } from "@notation/factory-github/app-name";
5
+ import { appSlug } from "@notation/factory-github/app";
6
6
  import { collectResourceGraph } from "@notation/resource";
7
7
  import { loadConfig, openBrowser, type OutpostCliConfig, output } from "./shell.ts";
8
8
 
@@ -24,13 +24,6 @@ const githubConnections = async (infra: string) => {
24
24
  .map((group) => (group.config as { name: string }).name);
25
25
  };
26
26
 
27
- /** The slug GitHub gives an App with this name: `factory--test--gh` becomes `factory-test-gh`. */
28
- const appSlug = (name: string) =>
29
- name
30
- .toLowerCase()
31
- .replace(/[^a-z0-9]+/g, "-")
32
- .replace(/^-|-$/g, "");
33
-
34
27
  const gh = async <T>(path: string) =>
35
28
  JSON.parse(await output("gh", ["api", path])) as T;
36
29
 
@@ -134,10 +127,11 @@ export const repoInstall = async ({ repo: given }: { repo?: string }) => {
134
127
  console.log(".factory/infra.ts uses no GitHub connection, so there's nothing to install.");
135
128
  return;
136
129
  }
137
- const { hub } = await outpostConfig(dir);
138
- if (!hub) {
130
+ const { githubApps = {} } = await outpostConfig(dir);
131
+ const missing = names.filter((name) => githubApps[name] === undefined);
132
+ if (missing.length > 0) {
139
133
  throw new Error(
140
- `Set hub in .factory/config.ts to the hub's Notation app and stage, such as hub: { app: "factory", stage: "prod" }, which name its GitHub Apps.`,
134
+ `Set githubApps in .factory/config.ts to the ID of the hub's GitHub App for each connection, such as githubApps: { ${missing.map((name) => `${name}: 123456`).join(", ")} }. The App's ID is on its settings page, and \`factory infra up\` prints it when it creates the App.`,
141
135
  );
142
136
  }
143
137
  const { id: repoId, owner } = await gh<{ id: number; owner: { id: number } }>(`repos/${repo}`);
@@ -145,12 +139,7 @@ export const repoInstall = async ({ repo: given }: { repo?: string }) => {
145
139
  const prompt = createInterface({ input: process.stdin, output: process.stdout });
146
140
  try {
147
141
  for (const name of names) {
148
- const slug = appSlug(appName(hub, name));
149
- await gh(`apps/${slug}`).catch(() => {
150
- throw new Error(
151
- `There's no GitHub App ${slug} for the connection ${name} of the hub ${hub.app}/${hub.stage}. Run \`factory infra up\` in the hub's repo first.`,
152
- );
153
- });
142
+ const slug = await appSlug(String(githubApps[name]));
154
143
  const url = `https://github.com/apps/${slug}/installations/new/permissions?suggested_target_id=${owner.id}&repository_ids[]=${repoId}`;
155
144
  console.log(`Install the GitHub App ${slug} on ${repo}:\n ${url}`);
156
145
  openBrowser(url);
package/commands/shell.ts CHANGED
@@ -44,8 +44,8 @@ export type HubConfig = {
44
44
  export type OutpostCliConfig = {
45
45
  /** The outpost's repo, as `owner/name`, when its git remote doesn't name it. */
46
46
  repo?: string;
47
- /** The hub the outpost subscribes to: its Notation app and stage, which name the hub's GitHub Apps. */
48
- hub?: { app: string; stage: string };
47
+ /** The ID of the hub's GitHub App for each GitHub connection that `.factory/infra.ts` uses, by connection name. */
48
+ githubApps?: Record<string, number>;
49
49
  };
50
50
 
51
51
  /** Reads the default export of the config file at `file`, if there is one. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notation/factory-cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "author": "Daniel Grant",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,6 +21,6 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@notation/resource": "0.28.1",
24
- "@notation/factory-github": "0.1.6"
24
+ "@notation/factory-github": "0.1.8"
25
25
  }
26
26
  }