You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
workers/api/src/routes/coding.ts is the busiest route file in the API (1738 lines), and three
things in it have been copy-pasted rather than shared. None of them is a bug today; each is a
place where a future fix lands in one copy and not the others.
The drift
The clone-URL regex, twice, verbatim. /github\.com[:/]([\w.-]+\/[\w.-]+?)(?:\.git)?\/?$/i appears at the add-repo path and again
in detect-github. The second site's own comment already says "same shape as the clone-URL
path" — the duplication was noticed when it was written.
githubRepo.split("/")[0], five times, in two shapes.
Three copies of full.split("/")[0] (latestRunFor, /deployment, /deployments) and two
of repo.githubRepo ? repo.githubRepo.split("/")[0] : "" (delegateToTarget, the
workflow-start route). "Take the owner out of an owner/repo" is a rule, and it is written
out five times.
/deployment inlines latestRunFor. latestRunFor is defined ~10 lines above GET …/repos/:repoId/deployment, and that route
then repeats its body verbatim — same guard order, same perPage: 1, same .catch(() => null), same "status" in res check. The only difference is the wire shape on
the unavailable path ({available:false} with no run key), which is a reason to adapt the
result, not to re-implement the lookup.
Scope — pure de-duplication, nothing else
Extract the shared helpers, change no behaviour and no wire shape. Specifically not in
scope:
Do not unify the two token fetches.delegateToTarget guards installationTokenForOwner with .catch(() => null); the workflow-start route does not, so a
token failure there propagates. That is a real behavioural difference and changing it is a
separate decision, not a de-dup.
Unit tests for the extracted helpers, following the pickNextIssue precedent already in this
file (pure helper exported from the route module, tested in routes/coding.test.ts).
workers/api/src/routes/coding.tsis the busiest route file in the API (1738 lines), and threethings in it have been copy-pasted rather than shared. None of them is a bug today; each is a
place where a future fix lands in one copy and not the others.
The drift
The clone-URL regex, twice, verbatim.
/github\.com[:/]([\w.-]+\/[\w.-]+?)(?:\.git)?\/?$/iappears at the add-repo path and againin
detect-github. The second site's own comment already says "same shape as the clone-URLpath" — the duplication was noticed when it was written.
githubRepo.split("/")[0], five times, in two shapes.Three copies of
full.split("/")[0](latestRunFor,/deployment,/deployments) and twoof
repo.githubRepo ? repo.githubRepo.split("/")[0] : ""(delegateToTarget, theworkflow-start route). "Take the owner out of an
owner/repo" is a rule, and it is writtenout five times.
/deploymentinlineslatestRunFor.latestRunForis defined ~10 lines aboveGET …/repos/:repoId/deployment, and that routethen repeats its body verbatim — same guard order, same
perPage: 1, same.catch(() => null), same"status" in rescheck. The only difference is the wire shape onthe unavailable path (
{available:false}with norunkey), which is a reason to adapt theresult, not to re-implement the lookup.
Scope — pure de-duplication, nothing else
Extract the shared helpers, change no behaviour and no wire shape. Specifically not in
scope:
mechanical cleanup into a provider layer would make this look like the start of an
architecture it is not.
delegateToTargetguardsinstallationTokenForOwnerwith.catch(() => null); the workflow-start route does not, so atoken failure there propagates. That is a real behavioural difference and changing it is a
separate decision, not a de-dup.
/deployments(plural) keeps its unauthenticated fallback. Its guard deliberately omitsgithubAppConfiguredso public repos show builds with no App installed (CODER-010, CODER-010: Builds fallback for public repos without the GitHub App (unauthenticated read) #121), soit cannot call
latestRunFor— it only shares the owner helper.Unit tests for the extracted helpers, following the
pickNextIssueprecedent already in thisfile (pure helper exported from the route module, tested in
routes/coding.test.ts).