Implement commits domain in GitHub simulator (/repos/{owner}/{repo}/commits*)#37
Conversation
/repos/{owner}/{repo}/commits*)
There was a problem hiding this comment.
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-demoand 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. |
| 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); |
| 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( |
| return $.response[200].json( | ||
| $.context.listCommitStatuses(owner, repo, commit.sha), | ||
| ); |
| return $.response[200].json( | ||
| $.context.listCommitComments(owner, repo, commit.sha), | ||
| ); |
| return [...(state.commitStatuses.get(commitItem.sha) ?? [])].sort( | ||
| (left, right) => | ||
| new Date(right.created_at).getTime() - | ||
| new Date(left.created_at).getTime(), |
pmcelhaney
left a comment
There was a problem hiding this comment.
@copilot implement all suggested changes and add appropriate tests
Implemented all requested reviewer suggestions and added test coverage in commit Included fixes:
|
pmcelhaney
left a comment
There was a problem hiding this comment.
@copilot refactor routes tests to test through HTTP like the tests in swagger-pet-store do
Implemented in commit |
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)RepoState:commits(by SHA)commitStatuses(by SHA)commitComments(by SHA)nextCommitCommentIdgetCommit(supports branch refs, exact SHA, unique short-SHA prefix)listCommits(newest-first, optionalsharef filter, pagination)saveCommitStatus/listCommitStatusesgetCombinedStatus(derives aggregate state from statuses)saveCommitComment/listCommitCommentsRoot context delegation (
routes/_.context.ts)$.context.*without domain-specific imports.HTTP route implementations (replacing random stubs)
GET /repos/{owner}/{repo}/commitsGET /repos/{owner}/{repo}/commits/{ref}GET/POST /repos/{owner}/{repo}/commits/{commit_sha}/commentsGET /repos/{owner}/{repo}/commits/{ref}/statusGET /repos/{owner}/{repo}/commits/{ref}/statusesScenario seeding
commitStatusesscenario and invoked it fromseedGitHub.counterfact/actions-demomain HEAD withci/lintandci/testsuccess statuses.Coverage updates