Skip to content

Add Milestones domain support to the GitHub simulator#39

Merged
pmcelhaney merged 3 commits into
mainfrom
copilot/implement-next-task-again
Jun 1, 2026
Merged

Add Milestones domain support to the GitHub simulator#39
pmcelhaney merged 3 commits into
mainfrom
copilot/implement-next-task-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 1, 2026

This PR implements the Milestones domain in @counterfact/github so milestone endpoints are stateful and aligned with existing repository/issue behavior. It also seeds milestone fixtures and routes milestone state through repo context APIs.

  • Context model + milestone lifecycle

    • Added milestone storage to repository state (milestones, nextMilestoneNumber) in routes/repos/_.context.ts.
    • Implemented saveMilestone, getMilestone, updateMilestone, deleteMilestone, and listMilestones with generated canonical fields (id, node_id, URLs, timestamps, default creator/state, counters).
    • Added milestone query filtering/sorting support (state, sort, direction, pagination inputs).
  • Cross-domain consistency (issues/PRs ↔ milestones)

    • Extended issue and pull request save flows so milestone counters stay consistent when assignment/state changes.
    • Added internal milestone counter synchronization across issue + PR state transitions.
  • Route implementation

    • Replaced milestone stubs with real handlers:
      • GET/POST /repos/{owner}/{repo}/milestones
      • GET/PATCH/DELETE /repos/{owner}/{repo}/milestones/{milestone_number}
    • Added proper 404 behavior for missing repositories/milestones.
  • Seed data updates

    • Added milestones scenario in scenarios/index.ts with seeded v1.0 (open) and v0.9 (closed) milestones on counterfact/platform-api.
    • Linked the seeded open issue to the v1.0 milestone.
    • Wired milestone seeding into seedGitHub.
  • Test coverage expansion

    • Added repo-context milestone unit tests (create/list/update/delete + counter behavior).
    • Added HTTP route tests for milestone CRUD, filtering, and missing-resource 404 handling.
    • Extended scenario tests to assert milestone seed presence and issue linkage.
// Example: new route behavior is now context-backed (not random/stubbed)
export const GET: issuesListMilestones = async ($) => {
  if (!$.context.hasRepository($.path.owner, $.path.repo)) {
    return $.response[404].empty();
  }
  return $.response[200].json(
    $.context.listMilestones($.path.owner, $.path.repo, $.query),
  );
};

Copilot AI self-assigned this Jun 1, 2026
Copilot AI review requested due to automatic review settings June 1, 2026 00:20
Copilot AI review requested due to automatic review settings June 1, 2026 00:20
Copilot AI changed the title Implement milestones domain for GitHub simulator Add Milestones domain support to the GitHub simulator Jun 1, 2026
Copilot AI requested a review from pmcelhaney June 1, 2026 00:20
@pmcelhaney pmcelhaney requested a review from Copilot June 1, 2026 00:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds stateful Milestones support to the @counterfact/github simulator, integrating milestone lifecycle behavior with repository, issue, pull request, route, and scenario state.

Changes:

  • Adds milestone storage, CRUD/list APIs, routing, and root context forwarding.
  • Seeds milestone fixture data and links a seeded issue to a milestone.
  • Expands context, route, and scenario tests for milestone behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
github/routes/repos/_.context.ts Adds milestone state, lifecycle methods, list filtering/sorting, and counter synchronization.
github/routes/_.context.ts Forwards milestone methods from root context to repos context.
github/routes/repos/{owner}/{repo}/milestones.ts Implements milestone list/create route handlers.
github/routes/repos/{owner}/{repo}/milestones/{milestone_number}.ts Implements milestone get/update/delete route handlers.
github/scenarios/index.ts Adds milestone seed scenario and wires it into seedGitHub.
github/test/repos.context.test.ts Adds direct context unit tests for milestone CRUD and counters.
github/test/routes.test.ts Adds HTTP route tests for milestone lifecycle and 404 handling.
github/test/scenarios.test.ts Adds scenario assertions for seeded milestones and issue linkage.
.github/todo/milestones-v2.md Removes completed milestone implementation TODO.

Comment thread github/routes/repos/_.context.ts Outdated
Comment on lines +1270 to +1283
const closedAt =
input.state === "closed"
? (input.closed_at ?? existing?.closed_at ?? now)
: (input.closed_at ?? existing?.closed_at ?? "");
const milestoneItem: milestone = {
...(existing ?? {}),
...input,
id,
node_id: input.node_id ?? existing?.node_id ?? `MS_${id}`,
number,
url: `${API_URL}/repos/${owner}/${repo}/milestones/${number}`,
html_url: `${APP_URL}/${owner}/${repo}/milestone/${number}`,
labels_url: `${API_URL}/repos/${owner}/${repo}/milestones/${number}/labels`,
state: input.state ?? existing?.state ?? "open",
Comment on lines +1295 to +1298
state.milestones.set(number, milestoneItem);
state.nextMilestoneNumber = Math.max(state.nextMilestoneNumber, number + 1);
this.nextMilestoneId = Math.max(this.nextMilestoneId, id + 1);
this.syncMilestoneCounts(state);
Copy link
Copy Markdown
Contributor

@pmcelhaney pmcelhaney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address both comments

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 1, 2026

@copilot address both comments

Addressed both review items in commit eca118b.

  • Fixed milestone closed_at transition behavior when patching state (close now sets timestamp when needed; reopen clears by default).
  • Synced updated milestone objects into existing issue/PR milestone references so embedded milestone fields stay current after PATCH.
  • Added tests covering close/reopen closed_at semantics and issue/PR reference freshness after milestone updates.

Copilot AI requested a review from pmcelhaney June 1, 2026 00:37
@pmcelhaney pmcelhaney marked this pull request as ready for review June 1, 2026 00:46
@pmcelhaney pmcelhaney added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit 6943cea Jun 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants