Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions plugins/github-watcher/source-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { z } from "zod";

export const STEWARDS_PLUGIN_ID = "stewards";

export const sourceSchema = z.enum(["linear", "github"]);
export const sourceSchema = z.enum(["linear", "github", "local"]);
export type Source = z.infer<typeof sourceSchema>;

/** A repository as GitHub spells it, `owner/name`, as a repo lease and a project's unit name. */
Expand All @@ -31,7 +31,7 @@ export const REPO_NAME = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u;
* bb reserves the id `github` for its bundled plugin and refuses a path
* install under it.
*/
export const SOURCE_PLUGIN_IDS: Record<Source, string> = { linear: "linear", github: "github-watcher" };
export const SOURCE_PLUGIN_IDS: Record<Source, string> = { linear: "linear", github: "github-watcher", local: "stewards" };

/**
* A GitHub Deployment, as bb-gate-hooks forwards it on a `deployment`
Expand Down Expand Up @@ -231,6 +231,14 @@ export const entitySnapshotSchema = z.object({
state: z.string(),
/** Linear's state type (triage, backlog, unstarted, started, completed, canceled); null on GitHub. */
stateType: z.string().nullable(),
/**
* The playbook the entity names, when its source names one: the local
* source reads `ticket` or `initiative` off the ticket. Optional and
* additive -- linear and github omit it, and stewards routes those by the
* project's label and state rules. Absent means the source has no playbook
* of its own, not that it named the empty string.
*/
playbook: z.string().optional(),
/** Linear: the team key. GitHub: "owner/repo". What a project lists and a lease hangs off. */
unit: z.string(),
labels: z.array(z.string()),
Expand Down
12 changes: 10 additions & 2 deletions plugins/linear/source-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { z } from "zod";

export const STEWARDS_PLUGIN_ID = "stewards";

export const sourceSchema = z.enum(["linear", "github"]);
export const sourceSchema = z.enum(["linear", "github", "local"]);
export type Source = z.infer<typeof sourceSchema>;

/** A repository as GitHub spells it, `owner/name`, as a repo lease and a project's unit name. */
Expand All @@ -31,7 +31,7 @@ export const REPO_NAME = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u;
* bb reserves the id `github` for its bundled plugin and refuses a path
* install under it.
*/
export const SOURCE_PLUGIN_IDS: Record<Source, string> = { linear: "linear", github: "github-watcher" };
export const SOURCE_PLUGIN_IDS: Record<Source, string> = { linear: "linear", github: "github-watcher", local: "stewards" };

/**
* A GitHub Deployment, as bb-gate-hooks forwards it on a `deployment`
Expand Down Expand Up @@ -231,6 +231,14 @@ export const entitySnapshotSchema = z.object({
state: z.string(),
/** Linear's state type (triage, backlog, unstarted, started, completed, canceled); null on GitHub. */
stateType: z.string().nullable(),
/**
* The playbook the entity names, when its source names one: the local
* source reads `ticket` or `initiative` off the ticket. Optional and
* additive -- linear and github omit it, and stewards routes those by the
* project's label and state rules. Absent means the source has no playbook
* of its own, not that it named the empty string.
*/
playbook: z.string().optional(),
/** Linear: the team key. GitHub: "owner/repo". What a project lists and a lease hangs off. */
unit: z.string(),
labels: z.array(z.string()),
Expand Down
40 changes: 39 additions & 1 deletion plugins/stewards/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { existsSync, readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import { isMissingPlugin, signatureLine, signedBy, snapshotPullSchema, sourceContract } from "./source-contract.js";
import { SOURCE_PLUGIN_IDS, entitySnapshotSchema, isMissingPlugin, signatureLine, signedBy, snapshotPullSchema, sourceContract, sourceSchema } from "./source-contract.js";

const here = (p: string) => fileURLToPath(new URL(p, import.meta.url));

Expand All @@ -14,6 +14,44 @@ describe("source-contract.ts", () => {
});
}

it("parses the local source, its plugin id and the optional playbook field (BB-361)", () => {
// A third source, served by stewards itself, joins the contract.
expect(sourceSchema.parse("local")).toBe("local");
expect(SOURCE_PLUGIN_IDS.local).toBe("stewards");
expect(SOURCE_PLUGIN_IDS).toEqual({ linear: "linear", github: "github-watcher", local: "stewards" });
// The playbook is optional and additive: a source that names one carries
// it (the local source), and a source that has none omits it rather than
// sending a placeholder.
const snapshot = {
source: "local" as const,
kind: "issue" as const,
id: "LOCAL-1",
key: "LOCAL-1",
url: null,
title: "A local ticket",
state: "Ready",
stateType: null,
unit: "local",
labels: [],
author: null,
assignees: [],
priority: null,
estimate: null,
description: "The spec.",
createdAt: null,
updatedAt: null,
comments: [],
parent: null,
children: [],
linkedPulls: [],
pull: null,
viewer: null,
};
expect(entitySnapshotSchema.parse({ ...snapshot, playbook: "initiative" })).toMatchObject({ source: "local", playbook: "initiative" });
expect(entitySnapshotSchema.parse(snapshot).playbook).toBeUndefined();
expect(entitySnapshotSchema.safeParse({ ...snapshot, playbook: 3 }).success).toBe(false);
});

it("reads the last signature in a body", () => {
expect(signedBy(`hello\n\n${signatureLine("thr_abc")}`)).toBe("thr_abc");
expect(signedBy(`> ${signatureLine("thr_old")}\n\nreply\n\n${signatureLine("thr_new")}`)).toBe("thr_new");
Expand Down
6 changes: 5 additions & 1 deletion plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ export const rpcContract = defineRpcContract({
linearTeams: z.array(z.string()),
repos: z.array(z.string()),
excludedRepos: z.array(z.string()),
playbooks: z.array(z.object({ kind: z.string(), name: z.string(), version: z.string().nullable(), source: z.enum(["linear", "github"]).nullable() })),
playbooks: z.array(z.object({ kind: z.string(), name: z.string(), version: z.string().nullable(), source: z.enum(["linear", "github", "local"]).nullable() })),
problems: z.array(z.string()),
nightly: z.object({ at: z.string(), timezone: z.string() }).nullable(),
lastNight: z.string().nullable(),
Expand Down Expand Up @@ -3871,6 +3871,10 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
// which it skips; stewards check says so.
deployment: [...new Set(projects.flatMap((p) => deploymentTargets(p).map((t) => t.repo)))].sort(),
},
// The local source is stewards itself: it leases nothing on
// bb-gate-hooks, so its set is empty and the loop below never sends
// it. Present only so the Record covers every Source (BB-361).
local: { units: [], entities: [], dependabot: [], deployment: [] },
};
for (const source of ["linear", "github"] as const) {
const body = JSON.stringify(sets[source]);
Expand Down
12 changes: 10 additions & 2 deletions plugins/stewards/source-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { z } from "zod";

export const STEWARDS_PLUGIN_ID = "stewards";

export const sourceSchema = z.enum(["linear", "github"]);
export const sourceSchema = z.enum(["linear", "github", "local"]);
export type Source = z.infer<typeof sourceSchema>;

/** A repository as GitHub spells it, `owner/name`, as a repo lease and a project's unit name. */
Expand All @@ -31,7 +31,7 @@ export const REPO_NAME = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u;
* bb reserves the id `github` for its bundled plugin and refuses a path
* install under it.
*/
export const SOURCE_PLUGIN_IDS: Record<Source, string> = { linear: "linear", github: "github-watcher" };
export const SOURCE_PLUGIN_IDS: Record<Source, string> = { linear: "linear", github: "github-watcher", local: "stewards" };

/**
* A GitHub Deployment, as bb-gate-hooks forwards it on a `deployment`
Expand Down Expand Up @@ -231,6 +231,14 @@ export const entitySnapshotSchema = z.object({
state: z.string(),
/** Linear's state type (triage, backlog, unstarted, started, completed, canceled); null on GitHub. */
stateType: z.string().nullable(),
/**
* The playbook the entity names, when its source names one: the local
* source reads `ticket` or `initiative` off the ticket. Optional and
* additive -- linear and github omit it, and stewards routes those by the
* project's label and state rules. Absent means the source has no playbook
* of its own, not that it named the empty string.
*/
playbook: z.string().optional(),
/** Linear: the team key. GitHub: "owner/repo". What a project lists and a lease hangs off. */
unit: z.string(),
labels: z.array(z.string()),
Expand Down
Loading