Skip to content

Implement commits domain in GitHub simulator (/repos/{owner}/{repo}/commits*)#37

Merged
pmcelhaney merged 5 commits into
mainfrom
copilot/pick-up-next-task-again
May 30, 2026
Merged

Implement commits domain in GitHub simulator (/repos/{owner}/{repo}/commits*)#37
pmcelhaney merged 5 commits into
mainfrom
copilot/pick-up-next-task-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

The GitHub simulator exposed repository, issues, PRs, and workflows, but commit-focused endpoints were still random stubs. This PR adds stateful commit APIs so commit listing, ref lookup, statuses, and commit comments behave consistently with seeded repository state.

  • Commits domain state + behavior (routes/repos/_.context.ts)

    • Added commit domain storage to RepoState:
      • commits (by SHA)
      • commitStatuses (by SHA)
      • commitComments (by SHA)
      • nextCommitCommentId
    • Added commit methods:
      • getCommit (supports branch refs, exact SHA, unique short-SHA prefix)
      • listCommits (newest-first, optional sha ref filter, pagination)
      • saveCommitStatus / listCommitStatuses
      • getCombinedStatus (derives aggregate state from statuses)
      • saveCommitComment / listCommitComments
    • Wired branch initialization to materialize branch HEAD commits into the repo commit map.
  • Root context delegation (routes/_.context.ts)

    • Added forwarding methods for new commits APIs so route files can call $.context.* without domain-specific imports.
  • HTTP route implementations (replacing random stubs)

    • Implemented:
      • GET /repos/{owner}/{repo}/commits
      • GET /repos/{owner}/{repo}/commits/{ref}
      • GET/POST /repos/{owner}/{repo}/commits/{commit_sha}/comments
      • GET /repos/{owner}/{repo}/commits/{ref}/status
      • GET /repos/{owner}/{repo}/commits/{ref}/statuses
    • Added repository existence checks and 404 behavior for missing repo/commit refs.
  • Scenario seeding

    • Added commitStatuses scenario and invoked it from seedGitHub.
    • Seeds counterfact/actions-demo main HEAD with ci/lint and ci/test success statuses.
  • Coverage updates

    • Extended context tests for commit resolution, pagination, combined status derivation, and commit comment creation.
    • Extended route tests for commit endpoints (happy path + 404s).
export const GET: reposGetCommit = async ($) => {
  const { owner, repo, ref } = $.path;
  if (!$.context.hasRepository(owner, repo)) return $.response[404].empty();

  const commit = $.context.getCommit(owner, repo, ref); // branch, SHA, or short SHA
  if (!commit) return $.response[404].empty();

  return $.response[200].json(commit);
};

Copilot AI requested review from Copilot and removed request for Copilot May 30, 2026 17:39
Copilot AI changed the title Implement commits domain in GitHub API simulator Implement commits domain in GitHub simulator (/repos/{owner}/{repo}/commits*) May 30, 2026
Copilot AI requested a review from pmcelhaney May 30, 2026 17:39
@pmcelhaney pmcelhaney marked this pull request as ready for review May 30, 2026 17:39
Copilot AI review requested due to automatic review settings May 30, 2026 17:39
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 implements stateful commit-related endpoints for the GitHub simulator, replacing random stubs with repository-backed commit, status, and comment behavior.

Changes:

  • Adds commit storage, ref resolution, status aggregation, and commit comment handling to the repos context.
  • Wires root context delegation and route handlers for /repos/{owner}/{repo}/commits*.
  • Seeds commit statuses for counterfact/actions-demo and adds route/context tests for the new behavior.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
github/routes/repos/_.context.ts Adds commit domain state and behavior.
github/routes/_.context.ts Forwards commit-related methods to repos context.
github/routes/repos/{owner}/{repo}/commits.ts Implements commit listing route.
github/routes/repos/{owner}/{repo}/commits/{ref}.ts Implements commit lookup by ref/SHA.
github/routes/repos/{owner}/{repo}/commits/{commit_sha}/comments.ts Implements commit comment listing and creation.
github/routes/repos/{owner}/{repo}/commits/{ref}/status.ts Implements combined commit status route.
github/routes/repos/{owner}/{repo}/commits/{ref}/statuses.ts Implements commit status listing route.
github/scenarios/index.ts Seeds default commit statuses.
github/test/routes.test.ts Adds HTTP route coverage for commit endpoints.
github/test/repos.context.test.ts Adds direct context coverage for commit behavior.
.github/todo/commits-v2.md Removes completed implementation plan.

Comment thread github/routes/repos/_.context.ts Outdated
Comment on lines +876 to +884
if (query?.sha) {
const resolved = this.resolveCommitRef(state, query.sha);
return paginate(
resolved ? commits.filter((item) => item.sha === resolved.sha) : [],
query,
);
}

return paginate(commits, query);
Comment on lines +951 to +965
const statuses = this.listCommitStatuses(owner, repo, commitItem.sha);
let combinedState = "success";

if (statuses.some((item) => item.state === "failure")) {
combinedState = "failure";
} else if (statuses.some((item) => item.state === "error")) {
combinedState = "error";
} else if (
statuses.length === 0 ||
statuses.some((item) => item.state === "pending")
) {
combinedState = "pending";
}

const simpleStatuses: Array<simple_commit_status> = statuses.map(
Comment on lines +14 to +16
return $.response[200].json(
$.context.listCommitStatuses(owner, repo, commit.sha),
);
Comment on lines +15 to +17
return $.response[200].json(
$.context.listCommitComments(owner, repo, commit.sha),
);
Comment thread github/routes/repos/_.context.ts Outdated
Comment on lines +933 to +936
return [...(state.commitStatuses.get(commitItem.sha) ?? [])].sort(
(left, right) =>
new Date(right.created_at).getTime() -
new Date(left.created_at).getTime(),
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 implement all suggested changes and add appropriate tests

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 30, 2026

@copilot implement all suggested changes and add appropriate tests

Implemented all requested reviewer suggestions and added test coverage in commit 7690a94.

Included fixes:

  • GET /repos/{owner}/{repo}/commits now defaults to the repository default branch when sha is omitted.
  • Combined status now derives from the latest status per context.
  • Status sorting now has stable latest-first tie-breaking when timestamps are equal.
  • Commit statuses/comments list routes now pass page/per_page query params through to context pagination.
  • Added context and route tests covering these behaviors.

Copilot AI requested a review from pmcelhaney May 30, 2026 17:56
@pmcelhaney pmcelhaney added this pull request to the merge queue May 30, 2026
@pmcelhaney pmcelhaney removed this pull request from the merge queue due to a manual request May 30, 2026
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 refactor routes tests to test through HTTP like the tests in swagger-pet-store do

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 30, 2026

@copilot refactor routes tests to test through HTTP like the tests in swagger-pet-store do

Implemented in commit 0db6e41. I refactored the commit route tests in github/test/routes.test.ts to exercise the routes via HTTP requests (including pagination and 404 cases) using a local HTTP test harness, instead of calling route handlers directly.

Copilot AI requested a review from pmcelhaney May 30, 2026 19:30
@pmcelhaney pmcelhaney added this pull request to the merge queue May 30, 2026
Merged via the queue into main with commit ba5e7dc May 30, 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