Repository navigation
Conversation
- Seeded organizations get GitHub's default Task, Bug and Feature types
unless their seed lists issue_types ([] seeds none).
- GET /orgs/{org}/issue-types for organization members and installations
on the organization; GET /repos/{owner}/{repo}/issue-types lists the
owning organization's types (none for personal repositories).
- Issue create and update accept `type`: an enabled type name (matched
without regard to case) or null to clear; unknown, disabled or
personal-repository types return 422 before any write.
- Issue objects carry `type`.
The typed/untyped issue webhooks are not included yet.
Closes #4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx
| }; | ||
| } | ||
|
|
||
| function issueTypeJson(issue: GitHubIssue, store: GitHubStore) { |
There was a problem hiding this comment.
🟡 issueTypeJson duplicates formatIssueType serializer.
| function issueTypeJson(issue: GitHubIssue, store: GitHubStore) { | |
| Move formatIssueType into helpers.ts next to formatLabel/formatMilestone (keeping the one-directional import graph), have issueTypeJson call it, and re-export/import it in routes/issue-types.ts and issue-types.ts. |
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/helpers.ts:392-397):
Problem: issueTypeJson duplicates formatIssueType serializer
Detail: The private issueTypeJson helper in helpers.ts builds the exact same 8-field object ({id, node_id, name, description, color, created_at, updated_at, is_enabled}) as formatIssueType in issue-types.ts, and breaks the file's format* naming convention for serializers (formatLabel, formatMilestone, ...). Two copies of the issue-type API shape in one PR will drift when a field is added or renamed. helpers.ts cannot import issue-types.ts (issue-types.ts already imports generateNodeId from helpers.js), so the shared formatter belongs in helpers.ts.
Suggested fix: Move formatIssueType into helpers.ts next to formatLabel/formatMilestone (keeping the one-directional import graph), have issueTypeJson call it, and re-export/import it in routes/issue-types.ts and issue-types.ts.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
The private issueTypeJson helper in helpers.ts builds the exact same 8-field object ({id, node_id, name, description, color, created_at, updated_at, is_enabled}) as formatIssueType in issue-types.ts, and breaks the file's format* naming convention for serializers (formatLabel, formatMilestone, ...). Two copies of the issue-type API shape in one PR will drift when a field is added or renamed. helpers.ts cannot import issue-types.ts (issue-types.ts already imports generateNodeId from helpers.js), so the shared formatter belongs in helpers.ts.
};
}
function issueTypeJson(issue: GitHubIssue, store: GitHubStore) {
const type = issue.type_id ? store.issueTypes.get(issue.type_id) : undefined;
if (!type) return null;
const { id, node_id, name, description, color, created_at, updated_at, is_enabled } = type;
return { id, node_id, name, description, color, created_at, updated_at, is_enabled };
}
/** Counts as GitHub reports them: `blocked_by` and `blocking` count open issues, the totals count all. */| ]; | ||
|
|
||
| export function seedIssueTypes(gh: GitHubStore, org: GitHubOrg, types: IssueTypeSeed[] = DEFAULT_ISSUE_TYPES): void { | ||
| for (const type of types) { |
There was a problem hiding this comment.
🟡 Seed config issue_types: null crashes with TypeError.
--- a/packages/@emulators/github/src/issue-types.ts
+++ b/packages/@emulators/github/src/issue-types.ts
@@ -20,7 +20,7 @@ export const DEFAULT_ISSUE_TYPES: IssueTypeSeed[] = [
];
-export function seedIssueTypes(gh: GitHubStore, org: GitHubOrg, types: IssueTypeSeed[] = DEFAULT_ISSUE_TYPES): void {
- for (const type of types) {
+export function seedIssueTypes(
+ gh: GitHubStore,
+ org: GitHubOrg,
+ types: IssueTypeSeed[] | null = DEFAULT_ISSUE_TYPES,
+): void {
+ for (const type of types ?? DEFAULT_ISSUE_TYPES) {
if (!type.name?.trim()) throw new Error(`Issue type for ${org.login} needs a name`);🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/issue-types.ts:21):
Problem: Seed config issue_types: null crashes with TypeError
Detail: The default parameter `types: IssueTypeSeed[] = DEFAULT_ISSUE_TYPES` only covers undefined. A JSON seed config with "issue_types": null (JSON has no undefined, and null round-trips through JSON.parse and materializeGitHubSeedConfig) passes null through and `for (const type of null)` throws "TypeError: types is not iterable" at seed/startup time, instead of seeding the defaults or failing with a clear config-validation error.
Suggested fix: Treat null like absent: widen the parameter to `IssueTypeSeed[] | null = DEFAULT_ISSUE_TYPES` and iterate `types ?? DEFAULT_ISSUE_TYPES`.
Suggested patch:
--- a/packages/@emulators/github/src/issue-types.ts
+++ b/packages/@emulators/github/src/issue-types.ts
@@ -20,7 +20,7 @@ export const DEFAULT_ISSUE_TYPES: IssueTypeSeed[] = [
];
-export function seedIssueTypes(gh: GitHubStore, org: GitHubOrg, types: IssueTypeSeed[] = DEFAULT_ISSUE_TYPES): void {
- for (const type of types) {
+export function seedIssueTypes(
+ gh: GitHubStore,
+ org: GitHubOrg,
+ types: IssueTypeSeed[] | null = DEFAULT_ISSUE_TYPES,
+): void {
+ for (const type of types ?? DEFAULT_ISSUE_TYPES) {
if (!type.name?.trim()) throw new Error(`Issue type for ${org.login} needs a name`);
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
The default parameter types: IssueTypeSeed[] = DEFAULT_ISSUE_TYPES only covers undefined. A JSON seed config with "issue_types": null (JSON has no undefined, and null round-trips through JSON.parse and materializeGitHubSeedConfig) passes null through and for (const type of null) throws "TypeError: types is not iterable" at seed/startup time, instead of seeding the defaults or failing with a clear config-validation error.
/** The issue types GitHub creates for a new organization. */
export const DEFAULT_ISSUE_TYPES: IssueTypeSeed[] = [
{ name: "Task", description: "A specific piece of work", color: "yellow" },
{ name: "Bug", description: "An unexpected problem or behavior", color: "red" },
{ name: "Feature", description: "A request, idea, or new functionality", color: "blue" },
];
export function seedIssueTypes(gh: GitHubStore, org: GitHubOrg, types: IssueTypeSeed[] = DEFAULT_ISSUE_TYPES): void {
for (const type of types) {
if (!type.name?.trim()) throw new Error(`Issue type for ${org.login} needs a name`);| } | ||
| } | ||
|
|
||
| if ("type" in body) patch.type_id = resolveIssueTypeId(gh, repo, body.type) ?? null; |
There was a problem hiding this comment.
🟡 Type change records no issue event or webhook.
| if ("type" in body) patch.type_id = resolveIssueTypeId(gh, repo, body.type) ?? null; | |
| Capture the previous type_id alongside prevMilestoneId and, when it differs after resolution, insertIssueEvent(...) with a type-change event (old/new type) — mirroring the label/milestone handling in the same handler. |
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/routes/issues.ts:445):
Problem: Type change records no issue event or webhook
Detail: In the PATCH handler, setting, changing or clearing an issue's type silently patches type_id: the surrounding code records insertIssueEvent entries plus webhooks.dispatch for state, label, assignee and milestone changes (prevLabelIds/prevAssigneeIds/prevMilestoneId diffs), but a type change produces no timeline entry and no dedicated webhook payload field, so the change is invisible in the issue events/timeline API the way GitHub's issue-type change events are.
Suggested fix: Capture the previous type_id alongside prevMilestoneId and, when it differs after resolution, insertIssueEvent(...) with a type-change event (old/new type) — mirroring the label/milestone handling in the same handler.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
In the PATCH handler, setting, changing or clearing an issue's type silently patches type_id: the surrounding code records insertIssueEvent entries plus webhooks.dispatch for state, label, assignee and milestone changes (prevLabelIds/prevAssigneeIds/prevMilestoneId diffs), but a type change produces no timeline entry and no dedicated webhook payload field, so the change is invisible in the issue events/timeline API the way GitHub's issue-type change events are.
if ("milestone" in body) {
if (body.milestone === null) {
patch.milestone_id = null;
} else {
const mn = typeof body.milestone === "number" ? body.milestone : parseInt(String(body.milestone), 10);
if (!Number.isFinite(mn)) throw new ApiError(422, "Validation failed");
const ms = gh.milestones.findBy("repo_id", repo.id).find((m) => m.number === mn);
if (!ms) throw new ApiError(422, "Validation failed");
patch.milestone_id = ms.id;
}
}
if ("type" in body) patch.type_id = resolveIssueTypeId(gh, repo, body.type) ?? null;
const prevLabelIds = new Set(issue.label_ids);| const repo = lookupRepo(gh, c.req.param("owner")!, c.req.param("repo")!); | ||
| if (!repo) throw notFoundResponse(); | ||
| assertRepoPermission(gh, c.get("authUser"), repo, ["issues", "metadata"]); | ||
| return c.json(repoIssueTypes(gh, repo).map(formatIssueType)); |
There was a problem hiding this comment.
🟡 Repo endpoint lists disabled types that writes reject.
| return c.json(repoIssueTypes(gh, repo).map(formatIssueType)); | |
| Filter to enabled types on the repository route (`repoIssueTypes(gh, repo).filter((t) => t.is_enabled)`), and keep the org route returning all types with their enabled flag, matching GitHub's split between the two endpoints. |
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/routes/issue-types.ts:29):
Problem: Repo endpoint lists disabled types that writes reject
Detail: GET /repos/:owner/:repo/issue-types returns repoIssueTypes() unfiltered, so disabled issue types are advertised, while resolveIssueTypeId rejects disabled names with 422 on issue writes. A client that lists a repository's types and submits one of the returned entries (e.g. the seeded-but-disabled "Chore") gets a 422 — the read surface publishes values the write path refuses. GitHub's repository-level endpoint returns the types assignable in the repository.
Suggested fix: Filter to enabled types on the repository route (`repoIssueTypes(gh, repo).filter((t) => t.is_enabled)`), and keep the org route returning all types with their enabled flag, matching GitHub's split between the two endpoints.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
GET /repos/:owner/:repo/issue-types returns repoIssueTypes() unfiltered, so disabled issue types are advertised, while resolveIssueTypeId rejects disabled names with 422 on issue writes. A client that lists a repository's types and submits one of the returned entries (e.g. the seeded-but-disabled "Chore") gets a 422 — the read surface publishes values the write path refuses. GitHub's repository-level endpoint returns the types assignable in the repository.
app.get("/repos/:owner/:repo/issue-types", (c) => {
const repo = lookupRepo(gh, c.req.param("owner")!, c.req.param("repo")!);
if (!repo) throw notFoundResponse();
assertRepoPermission(gh, c.get("authUser"), repo, ["issues", "metadata"]);
return c.json(repoIssueTypes(gh, repo).map(formatIssueType));
});
}| const authUser = c.get("authUser"); | ||
| const installation = authUser?.installation; | ||
| const user = authUser && !installation ? getActorUser(gh, authUser) : undefined; | ||
| const allowed = installation |
There was a problem hiding this comment.
🟡 Org issue-types route skips installation permission scopes.
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/routes/issue-types.ts:18-21):
Problem: Org issue-types route skips installation permission scopes
Detail: GET /orgs/:org/issue-types admits any GitHub App installation whose accountId/accountType match the org, without checking the installation's granted permissions or repository selection. The sibling route in the same file (GET /repos/:owner/:repo/issue-types) goes through assertRepoPermission, which for installations enforces installationCanAccessRepo plus hasInstallationPermission(["issues","metadata"]) (route-helpers.ts). An installation with no issue-related permissions can therefore enumerate org-wide issue types, including disabled ones and their descriptions.
Suggested fix: When authorizing by installation, also require a relevant read permission, e.g. reuse the logic behind assertRepoPermission ("issues" and/or "metadata") instead of only comparing accountType/accountId.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
GET /orgs/:org/issue-types admits any GitHub App installation whose accountId/accountType match the org, without checking the installation's granted permissions or repository selection. The sibling route in the same file (GET /repos/:owner/:repo/issue-types) goes through assertRepoPermission, which for installations enforces installationCanAccessRepo plus hasInstallationPermission(["issues","metadata"]) (route-helpers.ts). An installation with no issue-related permissions can therefore enumerate org-wide issue types, including disabled ones and their descriptions.
const authUser = c.get("authUser");
const installation = authUser?.installation;
const user = authUser && !installation ? getActorUser(gh, authUser) : undefined;
const allowed = installation
? installation.accountType === "Organization" && installation.accountId === org.id
: !!user && isOrgMember(gh, user.id, org.id);
if (!allowed) throw notFoundResponse();
return c.json(orgIssueTypes(gh, org.id).map(formatIssueType));
});| /** | ||
| * Resolves the `type` field of an issue write. `undefined` leaves the type unchanged, `null` clears it, | ||
| * and a name selects an enabled type of the repository's organization, matched without regard to case. | ||
| */ |
There was a problem hiding this comment.
⚪ resolveIssueTypeId undefined branch is unreachable.
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/issue-types.ts:61-62):
Problem: resolveIssueTypeId undefined branch is unreachable
Detail: The documented tri-state contract ("undefined leaves the type unchanged") never takes effect: the PATCH call site is guarded by `"type" in body` and JSON bodies cannot carry a literal undefined, and the POST call site immediately collapses undefined with `?? null`. Both callers therefore carry a redundant `?? null` and the undefined return path is dead.
Suggested fix: Simplify the contract to `number | null` (return null for absent input) and drop the `?? null` at both call sites in routes/issues.ts; or, if the tri-state is kept, remove the `?? null` on the PATCH path so undefined genuinely means "unchanged".
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
The documented tri-state contract ("undefined leaves the type unchanged") never takes effect: the PATCH call site is guarded by "type" in body and JSON bodies cannot carry a literal undefined, and the POST call site immediately collapses undefined with ?? null. Both callers therefore carry a redundant ?? null and the undefined return path is dead.
/**
* Resolves the `type` field of an issue write. `undefined` leaves the type unchanged, `null` clears it,
* and a name selects an enabled type of the repository's organization, matched without regard to case.
*/
export function resolveIssueTypeId(gh: GitHubStore, repo: GitHubRepo, raw: unknown): number | null | undefined {
if (raw === undefined) return undefined;
if (raw === null) return null;
if (typeof raw !== "string" || !raw.trim()) throw new ApiError(422, "Validation failed");
Code reviewVerdict: Looks good — only minor / nit comments below. · 🔴 0 · 🟠 0 · 🟡 5 · ⚪ 1 · 0/6 resolved
🤖 Fix all 6 open findings with your agent📋 Out-of-diff findings (6)
Reviewed 9 files · 0 inline · view all 6 findings ↗ · AI-generated — verify findings before acting · AI guidance and feedback aictrl · AI code review for fast-moving teams · aictrl.dev |
Dependencies (#12): - issue_dependencies_summary counts only related issues every reader of the issue can see (same repository or public), so the shared issue payload no longer reveals blockers in private repositories. - DELETE needs write on the blocked issue only, so an edge whose far end became unreadable can still be removed; a malformed id returns 400. - One findIssueForRepo helper for issue and dependency routes. Delivery IDs (#13): import randomUUID by name. Issue types (#14): formatIssueType lives in helpers.ts beside the issue serializer; a null issue_types seed means the defaults; the type resolver returns number | null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx
Review response — PR 14Fixes are in Issues addressed (pushed to this stack)
Review claims verified false (no change needed)
Not addressed here
|
| const blocking = edge ? gh.issues.get(blockingId) : undefined; | ||
| if (!edge || !blocking) throw notFoundResponse(); | ||
| gh.issueDependencies.delete(edge.id); | ||
| return c.json(formatIssue(blocking, gh, baseUrl)); |
There was a problem hiding this comment.
🟠 DELETE dependency returns unreadable far-end issue JSON.
| return c.json(formatIssue(blocking, gh, baseUrl)); | |
| Keep the permissive delete, but never serialize the unreadable far end: return 204 No Content, or return formatIssue(issue, ...) (the blocked issue the caller just proved write access to), or only serialize `blocking` when canRead(gh, c.get("authUser"), gh.repos.get(blocking.repo_id)) is true. |
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/routes/issue-dependencies.ts:104):
Problem: DELETE dependency returns unreadable far-end issue JSON
Detail: The reworked DELETE handler drops the far-end read check that issueById used to enforce (the comment even says "the far end may have become unreadable since"), yet still returns `formatIssue(blocking, gh, baseUrl)` — the FULL payload (title, body, labels, author, new `type` field, dependency summary) of an issue the caller may have no read access to. Every sibling path is hardened: POST resolves the far end via issueById which 404s unreadable repos, the LIST handlers filter `related()` by canRead, and this very PR tightens issueDependenciesSummary to hide cross-repo private far ends from the shared issue payload. DELETE alone both removes the edge and discloses the private far end's complete contents. Repro: seed org O with repos A (issue #1, attacker V has issues:write on A) and private B (issue id 5); an edge A#1 blocked_by 5 exists; V sends DELETE /repos/O/A/issues/1/dependencies/blocked_by/5 — pre-PR this 404'd, now it returns 200 with B#5's private title/body/labels/type. The PR's own test (deleting an edge into hubot/secret) demonstrates the flow. The 200-vs-404 differential is also an existence oracle for private issue ids.
Suggested fix: Keep the permissive delete, but never serialize the unreadable far end: return 204 No Content, or return formatIssue(issue, ...) (the blocked issue the caller just proved write access to), or only serialize `blocking` when canRead(gh, c.get("authUser"), gh.repos.get(blocking.repo_id)) is true.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
The reworked DELETE handler drops the far-end read check that issueById used to enforce (the comment even says "the far end may have become unreadable since"), yet still returns formatIssue(blocking, gh, baseUrl) — the FULL payload (title, body, labels, author, new type field, dependency summary) of an issue the caller may have no read access to. Every sibling path is hardened: POST resolves the far end via issueById which 404s unreadable repos, the LIST handlers filter related() by canRead, and this very PR tightens issueDependenciesSummary to hide cross-repo private far ends from the shared issue payload. DELETE alone both removes the edge and discloses the private far end's complete contents. Repro: seed org O with repos A (issue #1, attacker V has issues:write on A) and private B (issue id 5); an edge A#1 blocked_by 5 exists; V sends DELETE /repos/O/A/issues/1/dependencies/blocked_by/5 — pre-PR this 404'd, now it returns 200 with B#5's private title/body/labels/type. The PR's own test (deleting an edge into hubot/secret) demonstrates the flow. The 200-vs-404 differential is also an existence oracle for private issue ids.
const edge = gh.issueDependencies
.findBy("blocked_issue_id", issue.id)
.find((candidate) => candidate.blocking_issue_id === blockingId);
const blocking = edge ? gh.issues.get(blockingId) : undefined;
if (!edge || !blocking) throw notFoundResponse();
gh.issueDependencies.delete(edge.id);
return c.json(formatIssue(blocking, gh, baseUrl));| const { issue } = pathIssue(gh, c, "write"); | ||
| const blocking = issueById(gh, c.get("authUser"), c.req.param("issue_id")); | ||
| const raw = c.req.param("issue_id")!; | ||
| if (!/^\d+$/.test(raw)) throw new ApiError(400, "Problems parsing issue_id"); |
There was a problem hiding this comment.
🟡 DELETE 400 for bad issue_id vs POST's 422.
| if (!/^\d+$/.test(raw)) throw new ApiError(400, "Problems parsing issue_id"); | |
| Throw new ApiError(422, "Validation failed") for the malformed id, or extract a shared parse helper used by both issueById and the DELETE handler so the two endpoints agree. |
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/routes/issue-dependencies.ts:96):
Problem: DELETE 400 for bad issue_id vs POST's 422
Detail: The rewritten DELETE rejects a malformed :issue_id with 400 "Problems parsing issue_id", while the sibling POST in the same file resolves the same kind of id through issueById() (line 41) and rejects it with 422 "Validation failed". Across this PR (resolveIssueTypeId, milestone parsing in routes/issues.ts) malformed values consistently map to 422 "Validation failed"; the "Problems parsing XXX" message appears nowhere else in the package. Identical malformed input now yields different status codes depending on which endpoint of the same resource receives it. If the 400 deliberately mirrors an observed GitHub response, that intent is invisible; otherwise the error contract of the two dependency endpoints has split.
Suggested fix: Throw new ApiError(422, "Validation failed") for the malformed id, or extract a shared parse helper used by both issueById and the DELETE handler so the two endpoints agree.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
The rewritten DELETE rejects a malformed :issue_id with 400 "Problems parsing issue_id", while the sibling POST in the same file resolves the same kind of id through issueById() (line 41) and rejects it with 422 "Validation failed". Across this PR (resolveIssueTypeId, milestone parsing in routes/issues.ts) malformed values consistently map to 422 "Validation failed"; the "Problems parsing XXX" message appears nowhere else in the package. Identical malformed input now yields different status codes depending on which endpoint of the same resource receives it. If the 400 deliberately mirrors an observed GitHub response, that intent is invisible; otherwise the error contract of the two dependency endpoints has split.
// Removing an edge needs write on the blocked issue only: the far end may have become unreadable since.
const { issue } = pathIssue(gh, c, "write");
const raw = c.req.param("issue_id")!;
if (!/^\d+$/.test(raw)) throw new ApiError(400, "Problems parsing issue_id");
const blockingId = Number(raw);| } | ||
| } | ||
|
|
||
| if ("type" in body) patch.type_id = resolveIssueTypeId(gh, repo, body.type); |
There was a problem hiding this comment.
🟡 Type-only PATCH emits no issue event or webhook.
| if ("type" in body) patch.type_id = resolveIssueTypeId(gh, repo, body.type); | |
| Snapshot prevTypeId alongside prevLabelIds/prevMilestoneId and, when it changed, insertIssueEvent(..., "edited", ...) and webhooks.dispatch("issues", "edited", {..., changes: { type: true }}) mirroring the title/body block (or extend the edited gate with a typeEdited condition). |
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/routes/issues.ts:442):
Problem: Type-only PATCH emits no issue event or webhook
Detail: PATCH now persists type_id via resolveIssueTypeId, but a type-only change records no issue event and dispatches no `issues` webhook: the handler's event/webhook blocks cover state, labels, assignees, milestone and title/body ("edited" is gated solely on titleEdited/bodyEdited, ~line 640). Every other mutable issue attribute on this endpoint produces an IssueEvent + webhook, so event-stream consumers — the emulator's main audience — silently miss type changes while the issue JSON shows them. Flagged as an internal-consistency gap (exact GitHub event shape for type changes is uncertain). Repro: register a webhook for "issues"; PATCH an existing issue with {"type":"Bug"} — 200, response shows the new type, but no delivery and no timeline event, whereas a labels-only or milestone-only PATCH in the same flow emits both.
Suggested fix: Snapshot prevTypeId alongside prevLabelIds/prevMilestoneId and, when it changed, insertIssueEvent(..., "edited", ...) and webhooks.dispatch("issues", "edited", {..., changes: { type: true }}) mirroring the title/body block (or extend the edited gate with a typeEdited condition).
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
PATCH now persists type_id via resolveIssueTypeId, but a type-only change records no issue event and dispatches no issues webhook: the handler's event/webhook blocks cover state, labels, assignees, milestone and title/body ("edited" is gated solely on titleEdited/bodyEdited, ~line 640). Every other mutable issue attribute on this endpoint produces an IssueEvent + webhook, so event-stream consumers — the emulator's main audience — silently miss type changes while the issue JSON shows them. Flagged as an internal-consistency gap (exact GitHub event shape for type changes is uncertain). Repro: register a webhook for "issues"; PATCH an existing issue with {"type":"Bug"} — 200, response shows the new type, but no delivery and no timeline event, whereas a labels-only or milestone-only PATCH in the same flow emits both.
if ("type" in body) patch.type_id = resolveIssueTypeId(gh, repo, body.type);
const prevLabelIds = new Set(issue.label_ids);
const prevAssigneeIds = new Set(issue.assignee_ids);
const prevMilestoneId = issue.milestone_id;| // Organization members and installations on the organization may read its issue types. | ||
| app.get("/orgs/:org/issue-types", (c) => { | ||
| const login = c.req.param("org")!.toLowerCase(); | ||
| const org = gh.orgs.all().find((candidate) => candidate.login.toLowerCase() === login); |
There was a problem hiding this comment.
🟡 Org route hand-rolls case-insensitive org lookup.
| const org = gh.orgs.all().find((candidate) => candidate.login.toLowerCase() === login); | |
| Move getOrgByLogin into helpers.ts (as done for findIssueForRepo) and use it here so all /orgs/:org routes share one resolution semantic; drop the local toLowerCase scan. |
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/routes/issue-types.ts:13):
Problem: Org route hand-rolls case-insensitive org lookup
Detail: GET /orgs/:org/issue-types resolves the org with a bespoke case-insensitive scan, while every other /orgs/:org endpoint uses getOrgByLogin(gh, login) (routes/orgs.ts:38, used at 8+ call sites), an exact-match findOneBy("login", login); lookupRepo is exact-match too. Two problems: (a) duplicated org-resolution logic instead of a shared helper — this PR itself moved findIssueForRepo into helpers.ts to kill exactly this kind of copy; (b) behavioral split: a mixed-case org param (e.g. /orgs/ACME/issue-types) resolves here but 404s on every other /orgs/:org route of the emulator.
Suggested fix: Move getOrgByLogin into helpers.ts (as done for findIssueForRepo) and use it here so all /orgs/:org routes share one resolution semantic; drop the local toLowerCase scan.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
GET /orgs/:org/issue-types resolves the org with a bespoke case-insensitive scan, while every other /orgs/:org endpoint uses getOrgByLogin(gh, login) (routes/orgs.ts:38, used at 8+ call sites), an exact-match findOneBy("login", login); lookupRepo is exact-match too. Two problems: (a) duplicated org-resolution logic instead of a shared helper — this PR itself moved findIssueForRepo into helpers.ts to kill exactly this kind of copy; (b) behavioral split: a mixed-case org param (e.g. /orgs/ACME/issue-types) resolves here but 404s on every other /orgs/:org route of the emulator.
// Organization members and installations on the organization may read its issue types.
app.get("/orgs/:org/issue-types", (c) => {
const login = c.req.param("org")!.toLowerCase();
const org = gh.orgs.all().find((candidate) => candidate.login.toLowerCase() === login);
if (!org) throw notFoundResponse();| import type { GitHubIssueType, GitHubOrg, GitHubRepo } from "./entities.js"; | ||
| import type { GitHubStore } from "./store.js"; | ||
| import { generateNodeId } from "./helpers.js"; | ||
| export { formatIssueType } from "./helpers.js"; |
There was a problem hiding this comment.
⚪ formatIssueType re-export adds needless indirection.
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #14, packages/@emulators/github/src/issue-types.ts:5):
Problem: formatIssueType re-export adds needless indirection
Detail: issue-types.ts re-exports formatIssueType from ./helpers.js purely so routes/issue-types.ts can import it via ../issue-types.js. All other serializers (formatIssue, formatRepo, formatLabel, ...) live in helpers.ts and route files import them directly from ../helpers.js — routes/issue-types.ts already imports lookupRepo from there on line 4, so this one symbol arrives through a different path. Single copy and no cycle (correct), just a needless indirection that splits the serializer convention across two modules.
Suggested fix: Drop the re-export in issue-types.ts and import formatIssueType from "../helpers.js" in routes/issue-types.ts alongside lookupRepo.
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
issue-types.ts re-exports formatIssueType from ./helpers.js purely so routes/issue-types.ts can import it via ../issue-types.js. All other serializers (formatIssue, formatRepo, formatLabel, ...) live in helpers.ts and route files import them directly from ../helpers.js — routes/issue-types.ts already imports lookupRepo from there on line 4, so this one symbol arrives through a different path. Single copy and no cycle (correct), just a needless indirection that splits the serializer convention across two modules.
import type { GitHubIssueType, GitHubOrg, GitHubRepo } from "./entities.js";
import type { GitHubStore } from "./store.js";
import { generateNodeId } from "./helpers.js";
export { formatIssueType } from "./helpers.js";
Code reviewVerdict: Address the major findings before merging. · 🔴 0 · 🟠 1 · 🟡 3 · ⚪ 1 · 0/5 resolved
🤖 Fix all 5 open findings with your agent📋 Out-of-diff findings (5)
Reviewed 11 files · 0 inline · view all 5 findings ↗ · AI-generated — verify findings before acting · AI guidance and feedback aictrl · AI code review for fast-moving teams · aictrl.dev |
Summary
Adds organization issue types (closes #4). Besides the org endpoint the issue asked for, it adds the repository endpoint, which aictrl calls before filing a typed issue.
issue_types;[]seeds none.GET /orgs/{org}/issue-typesis readable by organization members and by installations on that organization; anyone else gets 404.GET /repos/{owner}/{repo}/issue-typeslists the owning organization's types, and returns none for a personal repository.type: the name of an enabled type, matched without regard to case, ornullto clear it. An unknown type, a disabled type, or any type on a personal repository returns 422 before anything is written.type:{ id, node_id, name, description, color, created_at, updated_at, is_enabled }ornull.Not included: the
typed/untypedissue webhooks.Stacked on #13; retarget after #11–#13 merge.
Verification
issue-types.test.ts: 5 tests, covering default, custom and empty seeds, repo listing (org and personal), 404 for non-members and anonymous callers, setting, changing, keeping and clearing a type, and 422 with no write.node:24-bookworm-slim, all of these pass: build,type-check,type-check:tsc, lint (0 errors), format, smoke, and all package tests (core 113, github 193, github-emulator 6).🤖 Generated with Claude Code
https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx