Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

1,801 linesCodeBlameRaw
1//! REST: each route maps an HTTP request onto one operation.
2
3use serde_json::{Map, Value};
4
5use crate::about::AboutOp;
6use crate::run_artifacts::ArtifactsOp;
7use crate::caches::CachesOp;
8use crate::archives::ArchiveOp;
9use crate::deploy_keys::DeployKeysOp;
10use crate::deployments::DeploymentsOp;
11use crate::telemetry::TelemetryOp;
12use crate::packages::PackagesOp;
13use crate::folios::FoliosOp;
14use crate::coordination::CoordinationOp;
15use crate::protection::ProtectionOp;
16use crate::token_policy::TokenOp;
17use crate::sso::SsoOp;
18use crate::onboarding::OnboardingOp;
19use crate::operations::Op;
20use crate::checks::ChecksOp;
21use crate::rules::RulesOp;
22use crate::security::SecurityOp;
23
24pub struct Route {
25 pub method: &'static str,
26 /// Segments starting with `:` are parameters.
27 pub path: &'static str,
28 pub op: Op,
29 /// Query parameters the route reads, as `(name in the URL, input name)`.
30 pub query: &'static [(&'static str, &'static str)],
31}
32
33const fn route(
34 method: &'static str,
35 path: &'static str,
36 op: Op,
37 query: &'static [(&'static str, &'static str)],
38) -> Route {
39 Route {
40 method,
41 path,
42 op,
43 query,
44 }
45}
46
47pub const ROUTES: &[Route] = &[
48 route("GET", "/user", Op::Whoami, &[]),
49 route("POST", "/workspaces", Op::CreateWorkspace, &[]),
50 route("GET", "/workspaces/:workspace", Op::GetWorkspace, &[]),
51 route("DELETE", "/workspaces/:workspace", Op::DeleteWorkspace, &[]),
52 route("GET", "/user/emails", Op::ListEmails, &[]),
53 route("POST", "/user/emails", Op::AddEmail, &[]),
54 route("POST", "/user/emails/confirm", Op::ConfirmEmail, &[]),
55 route("DELETE", "/user/emails/:email", Op::RemoveEmail, &[]),
56 route("PATCH", "/user/email-settings", Op::UpdateEmailSettings, &[]),
57 // Your invites to g1t (Invite a friend).
58 route("GET", "/user/invites", Op::ListInvites, &[]),
59 route("POST", "/user/invites", Op::CreateInvite, &[]),
60 route("DELETE", "/user/invites/:id", Op::RevokeInvite, &[]),
61 route("POST", "/user/invites/:id/resend", Op::ResendInvite, &[]),
62 // Invitations to workspaces waiting for your answer.
63 route("GET", "/user/invitations", Op::ListInvitations, &[]),
64 route("POST", "/user/invitations/:id/accept", Op::AcceptInvitation, &[]),
65 route("POST", "/user/invitations/:id/decline", Op::DeclineInvitation, &[]),
66 route("GET", "/workspaces/:workspace/invitations", Op::ListWorkspaceInvites, &[]),
67 // A person's own Getting started in a workspace.
68 route("GET", "/workspaces/:workspace/onboarding", Op::Onboarding(OnboardingOp::GetOnboarding), &[]),
69 route("PATCH", "/workspaces/:workspace/onboarding", Op::Onboarding(OnboardingOp::UpdateOnboarding), &[]),
70 // A workspace's rules for personal access tokens, and its members' tokens.
71 route("GET", "/workspaces/:workspace/personal-access-token-policy", Op::Tokens(TokenOp::GetTokenPolicy), &[]),
72 route("PATCH", "/workspaces/:workspace/personal-access-token-policy", Op::Tokens(TokenOp::SetTokenPolicy), &[]),
73 route("GET", "/workspaces/:workspace/personal-access-tokens", Op::Tokens(TokenOp::ListMemberTokens), &[]),
74 route("POST", "/workspaces/:workspace/personal-access-tokens/:id", Op::Tokens(TokenOp::RevokeMemberToken), &[]),
75 route("GET", "/workspaces/:workspace/personal-access-token-requests", Op::Tokens(TokenOp::ListTokenRequests), &[]),
76 route("POST", "/workspaces/:workspace/personal-access-token-requests/:id", Op::Tokens(TokenOp::ReviewTokenRequest), &[]),
77 route("GET", "/workspaces/:workspace/sso", Op::Sso(SsoOp::GetSso), &[]),
78 route("PUT", "/workspaces/:workspace/sso", Op::Sso(SsoOp::ConfigureSso), &[]),
79 route("DELETE", "/workspaces/:workspace/sso", Op::Sso(SsoOp::DeleteSso), &[]),
80 route("PUT", "/workspaces/:workspace/sso/required", Op::Sso(SsoOp::SetSsoRequired), &[]),
81 route("GET", "/workspaces/:workspace/sso/identities", Op::Sso(SsoOp::ListSsoIdentities), &[]),
82 route("DELETE", "/workspaces/:workspace/sso/identities/:username", Op::Sso(SsoOp::UnlinkSsoIdentity), &[]),
83 route("POST", "/workspaces/:workspace/sso/scim", Op::Sso(SsoOp::EnableScim), &[]),
84 route("DELETE", "/workspaces/:workspace/sso/scim", Op::Sso(SsoOp::DisableScim), &[]),
85 route("POST", "/workspaces/:workspace/invitations", Op::InviteMember, &[]),
86 route("DELETE", "/workspaces/:workspace/invitations/:id", Op::RevokeWorkspaceInvite, &[]),
87 // Who has access. GitHub's addresses, but for adding someone, which
88 // takes an email address as well as a username.
89 route("GET", "/repos/:owner/:name/collaborators", Op::ListCollaborators, &[]),
90 route("POST", "/repos/:owner/:name/collaborators", Op::AddCollaborator, &[]),
91 route("PATCH", "/repos/:owner/:name/collaborators/:username", Op::UpdateCollaborator, &[]),
92 route("DELETE", "/repos/:owner/:name/collaborators/:username", Op::RemoveCollaborator, &[]),
93 route(
94 "GET",
95 "/repos/:owner/:name/collaborators/:username/permission",
96 Op::GetCollaboratorPermission,
97 &[],
98 ),
99 route("GET", "/repos/:owner/:name/invitations", Op::ListRepoInvitations, &[]),
100 route("DELETE", "/repos/:owner/:name/invitations/:id", Op::RevokeRepoInvitation, &[]),
101 route("GET", "/user/repository_invitations", Op::ListMyRepoInvitations, &[]),
102 // Deploy keys, at GitHub's addresses.
103 route("GET", "/repos/:owner/:name/keys", Op::DeployKeys(DeployKeysOp::ListDeployKeys), &[]),
104 route("POST", "/repos/:owner/:name/keys", Op::DeployKeys(DeployKeysOp::CreateDeployKey), &[]),
105 route("GET", "/repos/:owner/:name/keys/:id", Op::DeployKeys(DeployKeysOp::GetDeployKey), &[]),
106 route("DELETE", "/repos/:owner/:name/keys/:id", Op::DeployKeys(DeployKeysOp::DeleteDeployKey), &[]),
107 // Your notifications: threads, marking them, and what you subscribe
108 // to and watch. GitHub's addresses, with g1t's saved and snoozed.
109 route("GET", "/notifications", Op::ListNotifications, &[("all", "all"), ("participating", "participating"), ("view", "view"), ("reason", "reason"), ("severity", "severity"), ("since", "since"), ("before", "before"), ("cursor", "cursor"), ("per_page", "per_page")]),
110 route("PUT", "/notifications", Op::MarkNotificationsRead, &[]),
111 route("GET", "/notifications/threads/:id", Op::GetNotificationThread, &[]),
112 route("PATCH", "/notifications/threads/:id", Op::MarkThreadRead, &[]),
113 route("DELETE", "/notifications/threads/:id", Op::MarkThreadDone, &[]),
114 route("PUT", "/notifications/threads/:id/saved", Op::SaveThread, &[]),
115 route("DELETE", "/notifications/threads/:id/saved", Op::SaveThread, &[]),
116 route("PUT", "/notifications/threads/:id/snooze", Op::SnoozeThread, &[]),
117 route("DELETE", "/notifications/threads/:id/snooze", Op::SnoozeThread, &[]),
118 route("GET", "/notifications/threads/:id/subscription", Op::GetThreadSubscription, &[]),
119 route("PUT", "/notifications/threads/:id/subscription", Op::SetThreadSubscription, &[]),
120 route("DELETE", "/notifications/threads/:id/subscription", Op::DeleteThreadSubscription, &[]),
121 route("GET", "/repos/:owner/:name/notifications", Op::ListNotifications, &[("all", "all"), ("participating", "participating"), ("view", "view"), ("reason", "reason"), ("severity", "severity"), ("since", "since"), ("before", "before"), ("cursor", "cursor"), ("per_page", "per_page")]),
122 route("PUT", "/repos/:owner/:name/notifications", Op::MarkNotificationsRead, &[]),
123 route("GET", "/repos/:owner/:name/subscription", Op::GetRepoSubscription, &[]),
124 route("PUT", "/repos/:owner/:name/subscription", Op::SetRepoSubscription, &[]),
125 route("DELETE", "/repos/:owner/:name/subscription", Op::DeleteRepoSubscription, &[]),
126 route("GET", "/repos/:owner/:name/pulls/:number/subscription", Op::GetThreadSubscription, &[]),
127 route("PUT", "/repos/:owner/:name/pulls/:number/subscription", Op::SetThreadSubscription, &[]),
128 route("DELETE", "/repos/:owner/:name/pulls/:number/subscription", Op::DeleteThreadSubscription, &[]),
129 route("GET", "/workspaces/:workspace/work/:number/subscription", Op::GetThreadSubscription, &[]),
130 route("PUT", "/workspaces/:workspace/work/:number/subscription", Op::SetThreadSubscription, &[]),
131 route("DELETE", "/workspaces/:workspace/work/:number/subscription", Op::DeleteThreadSubscription, &[]),
132 route("GET", "/user/subscriptions", Op::ListWatchedRepos, &[]),
133 // Stars: yours, and who starred a repository.
134 route("GET", "/user/starred", Op::About(AboutOp::ListStarred), &[]),
135 route("GET", "/user/starred/:owner/:name", Op::About(AboutOp::CheckStarred), &[]),
136 route("PUT", "/user/starred/:owner/:name", Op::About(AboutOp::Star), &[]),
137 route("DELETE", "/user/starred/:owner/:name", Op::About(AboutOp::Unstar), &[]),
138 route("GET", "/repos/:owner/:name/stargazers", Op::About(AboutOp::ListStargazers), &[("page", "page")]),
139 // What the default branch says about a repository, kept by commit.
140 route("GET", "/repos/:owner/:name/languages", Op::About(AboutOp::GetLanguages), &[]),
141 route("GET", "/repos/:owner/:name/contributors", Op::About(AboutOp::ListContributors), &[]),
142 route("GET", "/repos/:owner/:name/license", Op::About(AboutOp::GetLicense), &[]),
143 // Releases: `latest` and `tags/…` before an id.
144 route("GET", "/repos/:owner/:name/releases", Op::About(AboutOp::ListReleases), &[]),
145 route("POST", "/repos/:owner/:name/releases", Op::About(AboutOp::CreateRelease), &[]),
146 route("GET", "/repos/:owner/:name/releases/latest", Op::About(AboutOp::GetLatestRelease), &[]),
147 route("GET", "/repos/:owner/:name/releases/tags/:tag", Op::About(AboutOp::GetReleaseByTag), &[]),
148 route("GET", "/repos/:owner/:name/releases/:id", Op::About(AboutOp::GetRelease), &[]),
149 route("PATCH", "/repos/:owner/:name/releases/:id", Op::About(AboutOp::UpdateRelease), &[]),
150 route("DELETE", "/repos/:owner/:name/releases/:id", Op::About(AboutOp::DeleteRelease), &[]),
151 // Your pinned projects in a workspace, in your order.
152 route("GET", "/user/pinned_projects/:workspace", Op::ListPinnedProjects, &[]),
153 route("PUT", "/user/pinned_projects/:workspace", Op::ReorderPinnedProjects, &[]),
154 route("PUT", "/user/pinned_projects/:workspace/:project", Op::PinProject, &[]),
155 route("DELETE", "/user/pinned_projects/:workspace/:project", Op::UnpinProject, &[]),
156 route("PATCH", "/user/repository_invitations/:id", Op::AcceptRepoInvitation, &[]),
157 route("DELETE", "/user/repository_invitations/:id", Op::DeclineRepoInvitation, &[]),
158 route("PATCH", "/workspaces/:workspace", Op::UpdateWorkspace, &[]),
159 // Members and owners: GitHub's organization members, by username.
160 route("GET", "/workspaces/:workspace/members", Op::ListMembers, &[]),
161 route("PATCH", "/workspaces/:workspace/members/:username", Op::UpdateMember, &[]),
162 route("DELETE", "/workspaces/:workspace/members/:username", Op::RemoveMember, &[]),
163 route("POST", "/workspaces/:workspace/transfer_ownership", Op::TransferOwnership, &[]),
164 route("DELETE", "/user/memberships/:workspace", Op::LeaveWorkspace, &[]),
165 // A workspace's projects: what each is, where it runs, its links.
166 route("GET", "/workspaces/:workspace/projects", Op::ListProjects, &[]),
167 // What happened across its repositories: merged pull requests, releases, deployments, pushes.
168 route(
169 "GET",
170 "/workspaces/:workspace/activity",
171 Op::GetWorkspaceActivity,
172 &[("since", "since"), ("until", "until"), ("kinds", "kinds"), ("limit", "limit")],
173 ),
174 route("GET", "/workspaces/:workspace/projects/:project", Op::GetProject, &[]),
175 route("PATCH", "/workspaces/:workspace/projects/:project", Op::UpdateProject, &[]),
176 // Its g1t.page deployments: whether it deploys, and how it builds.
177 route(
178 "GET",
179 "/workspaces/:workspace/projects/:project/deployments/settings",
180 Op::Deployments(DeploymentsOp::GetDeploymentSettings),
181 &[],
182 ),
183 route(
184 "PATCH",
185 "/workspaces/:workspace/projects/:project/deployments/settings",
186 Op::Deployments(DeploymentsOp::UpdateDeploymentSettings),
187 &[],
188 ),
189 // A project's observability: what its software did, and how it is collected.
190 route(
191 "GET",
192 "/workspaces/:workspace/projects/:project/observability/overview",
193 Op::Telemetry(TelemetryOp::GetOverview),
194 &[("from", "from"), ("to", "to"), ("environment", "environment"), ("service", "service"), ("deployment_id", "deployment_id"), ("step", "step")],
195 ),
196 route(
197 "GET",
198 "/workspaces/:workspace/projects/:project/observability/requests",
199 Op::Telemetry(TelemetryOp::ListRequests),
200 &[
201 ("from", "from"),
202 ("to", "to"),
203 ("q", "q"),
204 ("status", "status"),
205 ("errors_only", "errors_only"),
206 ("route", "route"),
207 ("min_duration_ms", "min_duration_ms"),
208 ("environment", "environment"),
209 ("service", "service"),
210 ("deployment_id", "deployment_id"),
211 ("cursor", "cursor"),
212 ("limit", "limit"),
213 ],
214 ),
215 route("GET", "/workspaces/:workspace/projects/:project/observability/requests/:id", Op::Telemetry(TelemetryOp::GetRequest), &[]),
216 route(
217 "GET",
218 "/workspaces/:workspace/projects/:project/observability/logs",
219 Op::Telemetry(TelemetryOp::ListLogs),
220 &[
221 ("from", "from"),
222 ("to", "to"),
223 ("q", "q"),
224 ("level", "level"),
225 ("trace_id", "trace_id"),
226 ("request_id", "request_id"),
227 ("environment", "environment"),
228 ("service", "service"),
229 ("deployment_id", "deployment_id"),
230 ("cursor", "cursor"),
231 ("limit", "limit"),
232 ],
233 ),
234 route(
235 "GET",
236 "/workspaces/:workspace/projects/:project/observability/traces",
237 Op::Telemetry(TelemetryOp::ListTraces),
238 &[
239 ("from", "from"),
240 ("to", "to"),
241 ("q", "q"),
242 ("errors_only", "errors_only"),
243 ("min_duration_ms", "min_duration_ms"),
244 ("environment", "environment"),
245 ("service", "service"),
246 ("cursor", "cursor"),
247 ("limit", "limit"),
248 ],
249 ),
250 route("GET", "/workspaces/:workspace/projects/:project/observability/traces/:trace_id", Op::Telemetry(TelemetryOp::GetTrace), &[]),
251 route(
252 "GET",
253 "/workspaces/:workspace/projects/:project/observability/errors",
254 Op::Telemetry(TelemetryOp::ListErrors),
255 &[("state", "state"), ("environment", "environment"), ("service", "service"), ("from", "from"), ("to", "to")],
256 ),
257 route("PATCH", "/workspaces/:workspace/projects/:project/observability/errors/:fingerprint", Op::Telemetry(TelemetryOp::UpdateError), &[]),
258 route("GET", "/workspaces/:workspace/projects/:project/observability/metrics", Op::Telemetry(TelemetryOp::ListMetrics), &[]),
259 route(
260 "GET",
261 "/workspaces/:workspace/projects/:project/observability/metrics/:metric",
262 Op::Telemetry(TelemetryOp::GetMetric),
263 &[("from", "from"), ("to", "to"), ("aggregate", "aggregate"), ("group_by", "group_by"), ("step", "step"), ("service", "service"), ("environment", "environment")],
264 ),
265 route("GET", "/workspaces/:workspace/projects/:project/observability/settings", Op::Telemetry(TelemetryOp::GetSettings), &[]),
266 route("PATCH", "/workspaces/:workspace/projects/:project/observability/settings", Op::Telemetry(TelemetryOp::UpdateSettings), &[]),
267 route("GET", "/workspaces/:workspace/projects/:project/observability/tokens", Op::Telemetry(TelemetryOp::ListTokens), &[]),
268 route("POST", "/workspaces/:workspace/projects/:project/observability/tokens", Op::Telemetry(TelemetryOp::CreateToken), &[]),
269 route("DELETE", "/workspaces/:workspace/projects/:project/observability/tokens/:id", Op::Telemetry(TelemetryOp::DeleteToken), &[]),
270 route("GET", "/workspaces/:workspace/projects/:project/observability/exports", Op::Telemetry(TelemetryOp::ListExports), &[]),
271 route("POST", "/workspaces/:workspace/projects/:project/observability/exports", Op::Telemetry(TelemetryOp::CreateExport), &[]),
272 route("PATCH", "/workspaces/:workspace/projects/:project/observability/exports/:id", Op::Telemetry(TelemetryOp::UpdateExport), &[]),
273 route("DELETE", "/workspaces/:workspace/projects/:project/observability/exports/:id", Op::Telemetry(TelemetryOp::DeleteExport), &[]),
274 route("GET", "/workspaces/:workspace/projects/:project/observability/usage", Op::Telemetry(TelemetryOp::GetUsage), &[]),
275 route("PUT", "/workspaces/:workspace/base_permission", Op::SetBasePermission, &[]),
276 route(
277 "GET",
278 "/workspaces/:workspace/outside_collaborators",
279 Op::ListOutsideCollaborators,
280 &[],
281 ),
282 // Teams: a workspace's groups of members, with roles on repositories.
283 route("GET", "/workspaces/:workspace/teams", Op::ListTeams, &[("q", "query")]),
284 route("POST", "/workspaces/:workspace/teams", Op::CreateTeam, &[]),
285 route("GET", "/workspaces/:workspace/teams/:team", Op::GetTeam, &[]),
286 route("PATCH", "/workspaces/:workspace/teams/:team", Op::UpdateTeam, &[]),
287 route("DELETE", "/workspaces/:workspace/teams/:team", Op::DeleteTeam, &[]),
288 route(
289 "GET",
290 "/workspaces/:workspace/teams/:team/members",
291 Op::ListTeamMembers,
292 &[("include_child_teams", "include_child_teams")],
293 ),
294 route("PUT", "/workspaces/:workspace/teams/:team/members/:username", Op::SetTeamMember, &[]),
295 route("DELETE", "/workspaces/:workspace/teams/:team/members/:username", Op::RemoveTeamMember, &[]),
296 route("GET", "/workspaces/:workspace/teams/:team/teams", Op::ListChildTeams, &[]),
297 route("GET", "/workspaces/:workspace/teams/:team/repos", Op::ListTeamRepos, &[]),
298 route("PUT", "/workspaces/:workspace/teams/:team/repos/:repo", Op::SetTeamRepo, &[]),
299 route("DELETE", "/workspaces/:workspace/teams/:team/repos/:repo", Op::RemoveTeamRepo, &[]),
300 route(
301 "PUT",
302 "/workspaces/:workspace/teams/:team/review_assignment",
303 Op::SetTeamReviewAssignment,
304 &[],
305 ),
306 route("GET", "/workspaces/:workspace/members/:username/teams", Op::ListUserTeams, &[]),
307 // A workspace's billing: usage, budget and invoices.
308 route(
309 "GET",
310 "/workspaces/:workspace/usage",
311 Op::GetUsage,
312 &[("from", "from"), ("until", "until"), ("products", "products"), ("projects", "projects"), ("group_by", "group_by")],
313 ),
314 route("GET", "/workspaces/:workspace/budget", Op::GetBudget, &[]),
315 route("PUT", "/workspaces/:workspace/budget", Op::SetBudget, &[]),
316 route("GET", "/workspaces/:workspace/invoices", Op::ListInvoices, &[]),
317 route("GET", "/workspaces/:workspace/billing_details", Op::GetBillingDetails, &[]),
318 // Code owners: the CODEOWNERS file, checked.
319 route("GET", "/repos/:owner/:name/codeowners/errors", Op::GetCodeownersErrors, &[("ref", "ref")]),
320 // Security alerts: secrets and vulnerable dependencies.
321 route(
322 "GET",
323 "/repos/:owner/:name/security/alerts",
324 Op::ListSecurityAlerts,
325 &[("state", "state"), ("kind", "kind")],
326 ),
327 route("POST", "/repos/:owner/:name/security/alerts/:id/dismiss", Op::DismissSecurityAlert, &[]),
328 route("POST", "/repos/:owner/:name/security/alerts/:id/reopen", Op::ReopenSecurityAlert, &[]),
329 // The security suite: secret scanning, code scanning, vulnerability
330 // alerts and the supply chain, at the common addresses.
331 route("GET", "/repos/:owner/:name/secret-scanning/alerts", Op::Security(SecurityOp::ListSecretAlerts), &[("state", "state"), ("secret_type", "secret_type"), ("validity", "validity"), ("bypassed", "bypassed")]),
332 route("GET", "/workspaces/:workspace/secret-scanning/alerts", Op::Security(SecurityOp::ListSecretAlerts), &[("state", "state"), ("secret_type", "secret_type"), ("validity", "validity"), ("bypassed", "bypassed")]),
333 route("GET", "/repos/:owner/:name/secret-scanning/alerts/:id", Op::Security(SecurityOp::GetSecretAlert), &[]),
334 route("PATCH", "/repos/:owner/:name/secret-scanning/alerts/:id", Op::Security(SecurityOp::UpdateSecretAlert), &[]),
335 route("GET", "/repos/:owner/:name/secret-scanning/alerts/:id/locations", Op::Security(SecurityOp::ListSecretLocations), &[]),
336 route("POST", "/repos/:owner/:name/secret-scanning/alerts/:id/bypass", Op::Security(SecurityOp::BypassPushProtection), &[]),
337 route("POST", "/repos/:owner/:name/secret-scanning/alerts/:id/validity", Op::Security(SecurityOp::CheckSecretValidity), &[]),
338 route("GET", "/workspaces/:workspace/secret-scanning/bypass-requests", Op::Security(SecurityOp::ListBypassRequests), &[("state", "state"), ("repo", "repo")]),
339 route("PATCH", "/workspaces/:workspace/secret-scanning/bypass-requests/:id", Op::Security(SecurityOp::ReviewBypassRequest), &[]),
340 route("POST", "/repos/:owner/:name/secret-scanning/custom-patterns/dry-run", Op::Security(SecurityOp::DryRunCustomPattern), &[]),
341 route("POST", "/workspaces/:workspace/secret-scanning/custom-patterns/dry-run", Op::Security(SecurityOp::DryRunCustomPattern), &[]),
342 route("GET", "/repos/:owner/:name/secret-scanning/custom-patterns", Op::Security(SecurityOp::ListCustomPatterns), &[]),
343 route("GET", "/workspaces/:workspace/secret-scanning/custom-patterns", Op::Security(SecurityOp::ListCustomPatterns), &[]),
344 route("POST", "/repos/:owner/:name/secret-scanning/custom-patterns", Op::Security(SecurityOp::CreateCustomPattern), &[]),
345 route("POST", "/workspaces/:workspace/secret-scanning/custom-patterns", Op::Security(SecurityOp::CreateCustomPattern), &[]),
346 route("PATCH", "/repos/:owner/:name/secret-scanning/custom-patterns/:id", Op::Security(SecurityOp::UpdateCustomPattern), &[]),
347 route("PATCH", "/workspaces/:workspace/secret-scanning/custom-patterns/:id", Op::Security(SecurityOp::UpdateCustomPattern), &[]),
348 route("DELETE", "/repos/:owner/:name/secret-scanning/custom-patterns/:id", Op::Security(SecurityOp::DeleteCustomPattern), &[]),
349 route("DELETE", "/workspaces/:workspace/secret-scanning/custom-patterns/:id", Op::Security(SecurityOp::DeleteCustomPattern), &[]),
350 route("GET", "/repos/:owner/:name/code-scanning/alerts", Op::Security(SecurityOp::ListCodeAlerts), &[("state", "state"), ("severity", "severity"), ("tool", "tool"), ("rule_id", "rule_id")]),
351 route("GET", "/workspaces/:workspace/code-scanning/alerts", Op::Security(SecurityOp::ListCodeAlerts), &[("state", "state"), ("severity", "severity"), ("tool", "tool"), ("rule_id", "rule_id")]),
352 route("GET", "/repos/:owner/:name/code-scanning/alerts/:number", Op::Security(SecurityOp::GetCodeAlert), &[]),
353 route("PATCH", "/repos/:owner/:name/code-scanning/alerts/:number", Op::Security(SecurityOp::UpdateCodeAlert), &[]),
354 route("GET", "/repos/:owner/:name/code-scanning/analyses", Op::Security(SecurityOp::ListAnalyses), &[]),
355 route("POST", "/repos/:owner/:name/code-scanning/sarifs", Op::Security(SecurityOp::UploadSarif), &[]),
356 route("GET", "/repos/:owner/:name/code-scanning/sarifs/:id", Op::Security(SecurityOp::GetSarifUpload), &[]),
357 route("GET", "/repos/:owner/:name/vulnerability-alerts", Op::Security(SecurityOp::ListVulnerabilityAlerts), &[("state", "state"), ("severity", "severity"), ("ecosystem", "ecosystem"), ("package", "package")]),
358 route("GET", "/workspaces/:workspace/vulnerability-alerts", Op::Security(SecurityOp::ListVulnerabilityAlerts), &[("state", "state"), ("severity", "severity"), ("ecosystem", "ecosystem"), ("package", "package")]),
359 route("GET", "/repos/:owner/:name/vulnerability-alerts/:id", Op::Security(SecurityOp::GetVulnerabilityAlert), &[]),
360 route("PATCH", "/repos/:owner/:name/vulnerability-alerts/:id", Op::Security(SecurityOp::UpdateVulnerabilityAlert), &[]),
361 route("GET", "/repos/:owner/:name/dependency-graph", Op::Security(SecurityOp::GetDependencyGraph), &[]),
362 route("GET", "/repos/:owner/:name/dependency-graph/sbom", Op::Security(SecurityOp::GetSbom), &[]),
363 route("GET", "/repos/:owner/:name/dependency-graph/compare/:basehead", Op::Security(SecurityOp::CompareDependencies), &[]),
364 route("POST", "/repos/:owner/:name/pulls/:number/dependency-review/rerun", Op::Security(SecurityOp::RerunDependencyReview), &[]),
365 route("GET", "/repos/:owner/:name/security/settings", Op::Security(SecurityOp::GetSettings), &[]),
366 route("PATCH", "/repos/:owner/:name/security/settings", Op::Security(SecurityOp::UpdateSettings), &[]),
367 route("GET", "/workspaces/:workspace/security/settings", Op::Security(SecurityOp::GetWorkspaceSettings), &[]),
368 route("PATCH", "/workspaces/:workspace/security/settings", Op::Security(SecurityOp::UpdateWorkspaceSettings), &[]),
369 route("GET", "/workspaces/:workspace/security/overview", Op::Security(SecurityOp::GetOverview), &[("days", "days")]),
370 // Reporting: a repository's advisories, and the vulnerability reports sent to its maintainers.
371 route("GET", "/repos/:owner/:name/security/advisories", Op::Security(SecurityOp::ListAdvisories), &[("state", "state")]),
372 route("POST", "/repos/:owner/:name/security/advisories", Op::Security(SecurityOp::CreateAdvisory), &[]),
373 route("GET", "/repos/:owner/:name/security/advisories/:id", Op::Security(SecurityOp::GetAdvisory), &[]),
374 route("PATCH", "/repos/:owner/:name/security/advisories/:id", Op::Security(SecurityOp::UpdateAdvisory), &[]),
375 route("POST", "/repos/:owner/:name/security/advisories/:id/state", Op::Security(SecurityOp::SetAdvisoryState), &[]),
376 route("GET", "/repos/:owner/:name/security/reports", Op::Security(SecurityOp::ListReports), &[("state", "state")]),
377 route("POST", "/repos/:owner/:name/security/reports", Op::Security(SecurityOp::ReportVulnerability), &[]),
378 route("PATCH", "/repos/:owner/:name/security/reports/:id", Op::Security(SecurityOp::ReviewReport), &[]),
379 route("GET", "/repos", Op::ListRepos, &[("q", "query")]),
380 route(
381 "GET",
382 "/search",
383 Op::Search,
384 &[("q", "query"), ("type", "type"), ("page", "page"), ("per_page", "per_page")],
385 ),
386 route("POST", "/repos", Op::CreateRepo, &[]),
387 route("GET", "/repos/:owner/:name", Op::GetRepo, &[]),
388 // A file's text or a directory's entries: `path` and `ref` in the query.
389 route("GET", "/repos/:owner/:name/contents", Op::GetContents, &[("path", "path"), ("ref", "ref")]),
390 route("GET", "/repos/:owner/:name/commits", Op::ListCommits, &[("ref", "ref"), ("path", "path"), ("limit", "limit")]),
391 // A branch, tag or commit as one archive: a redirect to a link good for
392 // ten minutes, as GitHub's go to codeload.
393 route("GET", "/repos/:owner/:name/tarball/:ref", Op::Archives(ArchiveOp::DownloadTarball), &[]),
394 route("GET", "/repos/:owner/:name/zipball/:ref", Op::Archives(ArchiveOp::DownloadZipball), &[]),
395 route("PATCH", "/repos/:owner/:name", Op::UpdateRepo, &[]),
396 route("POST", "/repos/:owner/:name/transfer", Op::TransferRepo, &[]),
397 route("POST", "/repos/:owner/:name/forks", Op::ForkRepo, &[]),
398 route("GET", "/repos/:owner/:name/forks", Op::ListForks, &[("limit", "limit")]),
399 route("POST", "/repos/:owner/:name/merge-upstream", Op::SyncFork, &[]),
400 route("POST", "/repos/:owner/:name/detach", Op::DetachFork, &[]),
401 route("DELETE", "/repos/:owner/:name", Op::DeleteRepo, &[]),
402 route(
403 "GET",
404 "/workspaces/:workspace/repos/deleted",
405 Op::ListDeletedRepos,
406 &[],
407 ),
408 route("POST", "/repos/:owner/:name/restore", Op::RestoreRepo, &[]),
409 route("POST", "/repos/:owner/:name/purge", Op::PurgeRepo, &[]),
410 route("POST", "/repos/:owner/:name/rename", Op::RenameRepo, &[]),
411 route("POST", "/repos/:owner/:name/archive", Op::ArchiveRepo, &[]),
412 route("POST", "/repos/:owner/:name/unarchive", Op::UnarchiveRepo, &[]),
413 route(
414 "POST",
415 "/repos/:owner/:name/visibility",
416 Op::SetRepoVisibility,
417 &[],
418 ),
419 route(
420 "POST",
421 "/repos/:owner/:name/branches/:branch/rename",
422 Op::RenameBranch,
423 &[],
424 ),
425 route("POST", "/repos/:owner/:name/branches", Op::CreateBranch, &[]),
426 route("DELETE", "/repos/:owner/:name/branches/:branch", Op::DeleteBranch, &[("head", "head")]),
427 route(
428 "GET",
429 "/repos/:owner/:name/settings",
430 Op::GetRepoSettings,
431 &[],
432 ),
433 route(
434 "PATCH",
435 "/repos/:owner/:name/settings",
436 Op::UpdateRepoSettings,
437 &[],
438 ),
439 route("GET", "/repos/:owner/:name/check-names", Op::ListCheckNames, &[]),
440 // Checks: GitHub's addresses for statuses, check runs and check suites.
441 route("POST", "/repos/:owner/:name/statuses/:sha", Op::Checks(ChecksOp::CreateCommitStatus), &[]),
442 route("GET", "/repos/:owner/:name/commits/:ref/statuses", Op::Checks(ChecksOp::ListCommitStatuses), &[]),
443 route("GET", "/repos/:owner/:name/commits/:ref/status", Op::Checks(ChecksOp::GetCombinedStatus), &[]),
444 route(
445 "GET",
446 "/repos/:owner/:name/commits/:ref/check-runs",
447 Op::Checks(ChecksOp::ListCheckRunsForRef),
448 &[("check_name", "check_name"), ("status", "status"), ("app", "app"), ("filter", "filter")],
449 ),
450 route(
451 "GET",
452 "/repos/:owner/:name/commits/:ref/check-suites",
453 Op::Checks(ChecksOp::ListCheckSuitesForRef),
454 &[("app", "app"), ("check_name", "check_name")],
455 ),
456 route("POST", "/repos/:owner/:name/check-runs", Op::Checks(ChecksOp::CreateCheckRun), &[]),
457 route("GET", "/repos/:owner/:name/check-runs/:id", Op::Checks(ChecksOp::GetCheckRun), &[]),
458 route("PATCH", "/repos/:owner/:name/check-runs/:id", Op::Checks(ChecksOp::UpdateCheckRun), &[]),
459 route("GET", "/repos/:owner/:name/check-runs/:id/annotations", Op::Checks(ChecksOp::ListCheckRunAnnotations), &[]),
460 route("POST", "/repos/:owner/:name/check-runs/:id/rerequest", Op::Checks(ChecksOp::RerequestCheckRun), &[]),
461 route("GET", "/repos/:owner/:name/check-suites/:id", Op::Checks(ChecksOp::GetCheckSuite), &[]),
462 route("POST", "/repos/:owner/:name/check-suites/:id/rerequest", Op::Checks(ChecksOp::RerequestCheckSuite), &[]),
463 // Rulesets: a repository's, a workspace's, the rules of one branch,
464 // and how they judged pushes and merges.
465 route("GET", "/repos/:owner/:name/rulesets", Op::Rules(RulesOp::ListRepoRulesets), &[("include_parents", "include_parents")]),
466 route("POST", "/repos/:owner/:name/rulesets", Op::Rules(RulesOp::CreateRepoRuleset), &[]),
467 route("GET", "/repos/:owner/:name/rulesets/:id", Op::Rules(RulesOp::GetRepoRuleset), &[]),
468 route("PUT", "/repos/:owner/:name/rulesets/:id", Op::Rules(RulesOp::UpdateRepoRuleset), &[]),
469 route("DELETE", "/repos/:owner/:name/rulesets/:id", Op::Rules(RulesOp::DeleteRepoRuleset), &[]),
470 route("GET", "/repos/:owner/:name/rules/branches/:branch", Op::Rules(RulesOp::GetBranchRules), &[("target", "target")]),
471 route(
472 "GET",
473 "/repos/:owner/:name/rules/evaluations",
474 Op::Rules(RulesOp::ListRuleEvaluations),
475 &[("ruleset_id", "ruleset_id"), ("verdict", "verdict"), ("problems_only", "problems_only"), ("before", "before"), ("limit", "limit")],
476 ),
477 route("GET", "/workspaces/:workspace/rulesets", Op::Rules(RulesOp::ListWorkspaceRulesets), &[]),
478 route("POST", "/workspaces/:workspace/rulesets", Op::Rules(RulesOp::CreateWorkspaceRuleset), &[]),
479 route("GET", "/workspaces/:workspace/rulesets/:id", Op::Rules(RulesOp::GetWorkspaceRuleset), &[]),
480 route("PUT", "/workspaces/:workspace/rulesets/:id", Op::Rules(RulesOp::UpdateWorkspaceRuleset), &[]),
481 route("DELETE", "/workspaces/:workspace/rulesets/:id", Op::Rules(RulesOp::DeleteWorkspaceRuleset), &[]),
482 route(
483 "GET",
484 "/workspaces/:workspace/rules/evaluations",
485 Op::Rules(RulesOp::ListWorkspaceRuleEvaluations),
486 &[("ruleset_id", "ruleset_id"), ("verdict", "verdict"), ("problems_only", "problems_only"), ("before", "before"), ("limit", "limit")],
487 ),
488 // Deployments wherever they run, their statuses, and environments.
489 route(
490 "GET",
491 "/repos/:owner/:name/deployments",
492 Op::Deployments(DeploymentsOp::ListDeployments),
493 &[("environment", "environment"), ("ref", "ref"), ("sha", "sha"), ("task", "task"), ("state", "state"), ("source", "source"), ("creator", "creator"), ("page", "page"), ("per_page", "per_page")],
494 ),
495 route("POST", "/repos/:owner/:name/deployments", Op::Deployments(DeploymentsOp::CreateDeployment), &[]),
496 // A g1t Actions job opening a g1t.page build it runs itself.
497 route("POST", "/repos/:owner/:name/deployments/builds", Op::Deployments(DeploymentsOp::StartDeploymentBuild), &[]),
498 route("GET", "/repos/:owner/:name/deployments/:id", Op::Deployments(DeploymentsOp::GetDeployment), &[]),
499 route("GET", "/repos/:owner/:name/deployments/:id/statuses", Op::Deployments(DeploymentsOp::ListDeploymentStatuses), &[]),
500 route("POST", "/repos/:owner/:name/deployments/:id/statuses", Op::Deployments(DeploymentsOp::CreateDeploymentStatus), &[]),
501 route("GET", "/repos/:owner/:name/environments", Op::Deployments(DeploymentsOp::ListEnvironments), &[]),
502 route("GET", "/repos/:owner/:name/environments/:environment", Op::Deployments(DeploymentsOp::GetEnvironment), &[]),
503 // Environments' protection rules, and the runs they hold.
504 route("PUT", "/repos/:owner/:name/environments/:environment", Op::Protection(ProtectionOp::UpdateEnvironment), &[]),
505 route("DELETE", "/repos/:owner/:name/environments/:environment", Op::Protection(ProtectionOp::DeleteEnvironment), &[]),
506 route(
507 "GET",
508 "/repos/:owner/:name/actions/runs/:id/pending_deployments",
509 Op::Protection(ProtectionOp::GetPendingDeployments),
510 &[],
511 ),
512 route(
513 "POST",
514 "/repos/:owner/:name/actions/runs/:id/pending_deployments",
515 Op::Protection(ProtectionOp::ReviewPendingDeployments),
516 &[],
517 ),
518 route("POST", "/repos/:owner/:name/actions/runs/:id/approve", Op::Protection(ProtectionOp::ApproveWorkflowRun), &[]),
519 route("GET", "/repos/:owner/:name/actions/permissions/workflow", Op::Protection(ProtectionOp::GetWorkflowPermissions), &[]),
520 route("PUT", "/repos/:owner/:name/actions/permissions/workflow", Op::Protection(ProtectionOp::SetWorkflowPermissions), &[]),
521 route(
522 "GET",
523 "/repos/:owner/:name/actions/permissions/fork-pr-contributor-approval",
524 Op::Protection(ProtectionOp::GetForkPrApproval),
525 &[],
526 ),
527 route(
528 "PUT",
529 "/repos/:owner/:name/actions/permissions/fork-pr-contributor-approval",
530 Op::Protection(ProtectionOp::SetForkPrApproval),
531 &[],
532 ),
533 route("GET", "/repos/:owner/:name/actions/permissions/access", Op::Protection(ProtectionOp::GetActionsAccess), &[]),
534 route("PUT", "/repos/:owner/:name/actions/permissions/access", Op::Protection(ProtectionOp::SetActionsAccess), &[]),
535 route("GET", "/repos/:owner/:name/actions/permissions", Op::Protection(ProtectionOp::GetActionsPermissions), &[]),
536 route("PUT", "/repos/:owner/:name/actions/permissions", Op::Protection(ProtectionOp::SetActionsPermissions), &[]),
537 route("POST", "/repos/:owner/:name/dispatches", Op::Protection(ProtectionOp::CreateRepositoryDispatch), &[]),
538 route(
539 "GET",
540 "/workspaces/:workspace/actions/permissions/workflow",
541 Op::Protection(ProtectionOp::GetWorkspaceWorkflowPermissions),
542 &[],
543 ),
544 route(
545 "PUT",
546 "/workspaces/:workspace/actions/permissions/workflow",
547 Op::Protection(ProtectionOp::SetWorkspaceWorkflowPermissions),
548 &[],
549 ),
550 route(
551 "GET",
552 "/workspaces/:workspace/actions/managed-workflows",
553 Op::Protection(ProtectionOp::ListWorkspaceManagedWorkflows),
554 &[],
555 ),
556 route(
557 "POST",
558 "/workspaces/:workspace/actions/managed-workflows",
559 Op::Protection(ProtectionOp::CreateWorkspaceManagedWorkflow),
560 &[],
561 ),
562 route(
563 "PATCH",
564 "/workspaces/:workspace/actions/managed-workflows/:workflow",
565 Op::Protection(ProtectionOp::UpdateWorkspaceManagedWorkflow),
566 &[],
567 ),
568 route(
569 "DELETE",
570 "/workspaces/:workspace/actions/managed-workflows/:workflow",
571 Op::Protection(ProtectionOp::DeleteWorkspaceManagedWorkflow),
572 &[],
573 ),
574 route("GET", "/repos/:owner/:name/queue", Op::GetMergeQueue, &[]),
575 route(
576 "GET",
577 "/repos/:owner/:name/events",
578 Op::ListEvents,
579 &[
580 ("before", "before"),
581 ("after", "after"),
582 ("types", "types"),
583 ("numbers", "numbers"),
584 ("since", "since"),
585 ("limit", "limit"),
586 ("wait", "wait"),
587 ],
588 ),
589 // A workspace's labels and milestones, which its work items and pull
590 // requests carry.
591 route("GET", "/workspaces/:workspace/labels", Op::ListLabels, &[]),
592 route("POST", "/workspaces/:workspace/labels", Op::CreateLabel, &[]),
593 route("POST", "/workspaces/:workspace/labels/defaults", Op::AddDefaultLabels, &[]),
594 route("PATCH", "/workspaces/:workspace/labels/:label", Op::UpdateLabel, &[]),
595 route("DELETE", "/workspaces/:workspace/labels/:label", Op::DeleteLabel, &[]),
596 route("GET", "/workspaces/:workspace/milestones", Op::ListMilestones, &[("state", "state")]),
597 route("POST", "/workspaces/:workspace/milestones", Op::CreateMilestone, &[]),
598 route("GET", "/workspaces/:workspace/milestones/:milestone", Op::GetMilestone, &[]),
599 route("PATCH", "/workspaces/:workspace/milestones/:milestone", Op::UpdateMilestone, &[]),
600 route("DELETE", "/workspaces/:workspace/milestones/:milestone", Op::DeleteMilestone, &[]),
601 // Work items: a workspace's tracked work, linked to its repositories.
602 route(
603 "GET",
604 "/workspaces/:workspace/work",
605 Op::ListWorkItems,
606 &[("state", "state"), ("label", "label"), ("milestone", "milestone"), ("assignee", "assignee"), ("repo", "repo"), ("role", "role")],
607 ),
608 route("POST", "/workspaces/:workspace/work", Op::OpenWorkItem, &[]),
609 route("POST", "/workspaces/:workspace/work/import", Op::ImportWorkItems, &[]),
610 route("PATCH", "/workspaces/:workspace/work/comments/:comment_id", Op::EditWorkItemComment, &[]),
611 route("DELETE", "/workspaces/:workspace/work/comments/:comment_id", Op::DeleteWorkItemComment, &[]),
612 route("GET", "/workspaces/:workspace/work/:number", Op::GetWorkItem, &[]),
613 route("PATCH", "/workspaces/:workspace/work/:number", Op::UpdateWorkItem, &[]),
614 route("POST", "/workspaces/:workspace/work/:number/close", Op::CloseWorkItem, &[]),
615 route("POST", "/workspaces/:workspace/work/:number/reopen", Op::ReopenWorkItem, &[]),
616 route("GET", "/workspaces/:workspace/work/:number/links", Op::ListWorkItemLinks, &[]),
617 route("POST", "/workspaces/:workspace/work/:number/links", Op::LinkWorkItem, &[]),
618 route("DELETE", "/workspaces/:workspace/work/:number/links", Op::UnlinkWorkItem, &[("repo", "repo")]),
619 route("GET", "/workspaces/:workspace/work/:number/labels", Op::ListWorkItemLabels, &[]),
620 route("POST", "/workspaces/:workspace/work/:number/labels", Op::AddWorkItemLabels, &[]),
621 route("PUT", "/workspaces/:workspace/work/:number/labels", Op::SetWorkItemLabels, &[]),
622 route("DELETE", "/workspaces/:workspace/work/:number/labels", Op::RemoveWorkItemLabels, &[]),
623 route("DELETE", "/workspaces/:workspace/work/:number/labels/:label", Op::RemoveWorkItemLabels, &[]),
624 route("POST", "/workspaces/:workspace/work/:number/comments", Op::AddWorkItemComment, &[]),
625 route("POST", "/workspaces/:workspace/work/:number/reactions", Op::ReactToWorkItem, &[]),
626 route("POST", "/workspaces/:workspace/work/:number/attachments", Op::UploadWorkItemAttachment, &[]),
627 route("GET", "/workspaces/:workspace/work/:number/decisions", Op::ListWorkItemDecisions, &[]),
628 // The work items linked to a repository: its Work tab. Read only.
629 route("GET", "/repos/:owner/:name/work", Op::ListRepoWorkItems, &[("state", "state"), ("label", "label"), ("milestone", "milestone"), ("assignee", "assignee"), ("role", "role")]),
630 // What `#N` names, read in a repository or a workspace: how an old
631 // link to a repository's issue finds the work item it became.
632 route("GET", "/repos/:owner/:name/refs/:number", Op::ResolveRef, &[]),
633 route("GET", "/workspaces/:workspace/refs/:number", Op::ResolveRef, &[]),
634 // Coordinating work: claims on work items, a work item's whole context,
635 // and sessions of people's own harnesses.
636 route("GET", "/workspaces/:workspace/work/:number/work", Op::Coordination(CoordinationOp::GetWork), &[]),
637 route("POST", "/workspaces/:workspace/work/:number/claim", Op::Coordination(CoordinationOp::ClaimWorkItem), &[]),
638 // Work with no work item yet: open one from a title and claim it.
639 route("POST", "/workspaces/:workspace/claims", Op::Coordination(CoordinationOp::ClaimWorkItem), &[]),
640 route("POST", "/workspaces/:workspace/work/:number/release", Op::Coordination(CoordinationOp::ReleaseClaim), &[]),
641 route("POST", "/workspaces/:workspace/work/:number/handoff", Op::Coordination(CoordinationOp::HandOffWorkItem), &[]),
642 route(
643 "GET",
644 "/workspaces/:workspace/claims",
645 Op::Coordination(CoordinationOp::ListClaims),
646 &[("state", "state"), ("item", "item"), ("repo", "repo")],
647 ),
648 route(
649 "GET",
650 "/workspaces/:workspace/sessions",
651 Op::Coordination(CoordinationOp::ListWorkspaceSessions),
652 &[
653 ("state", "state"),
654 ("kind", "kind"),
655 ("harness", "harness"),
656 ("person", "person"),
657 ("repo", "repo"),
658 ("item", "item"),
659 ("subagents", "subagents"),
660 ("limit", "limit"),
661 ],
662 ),
663 route("GET", "/workspaces/:workspace/sessions/:id", Op::Coordination(CoordinationOp::GetWorkspaceSession), &[("after", "after")]),
664 route("POST", "/repos/:owner/:name/sessions", Op::Coordination(CoordinationOp::StartSession), &[]),
665 route(
666 "GET",
667 "/repos/:owner/:name/sessions",
668 Op::Coordination(CoordinationOp::ListSessions),
669 &[("state", "state"), ("item", "item"), ("pull", "pull"), ("path", "path"), ("subagents", "subagents")],
670 ),
671 route("POST", "/repos/:owner/:name/agent-sessions", Op::Coordination(CoordinationOp::StartAgentSession), &[]),
672 route("GET", "/repos/:owner/:name/sessions/:id", Op::Coordination(CoordinationOp::GetSession), &[("after", "after")]),
673 route("PATCH", "/repos/:owner/:name/sessions/:id", Op::Coordination(CoordinationOp::UpdateSession), &[]),
674 route("POST", "/repos/:owner/:name/sessions/:id/end", Op::Coordination(CoordinationOp::EndSession), &[]),
675 route(
676 "POST",
677 "/repos/:owner/:name/sessions/:id/entries",
678 Op::Coordination(CoordinationOp::RecordSessionEntries),
679 &[],
680 ),
681 route(
682 "GET",
683 "/repos/:owner/:name/context",
684 Op::GetContext,
685 &[("reference", "reference")],
686 ),
687 route(
688 "GET",
689 "/workspaces/:workspace/integrations",
690 Op::ListIntegrations,
691 &[],
692 ),
693 route(
694 "POST",
695 "/workspaces/:workspace/integrations",
696 Op::ConnectIntegration,
697 &[],
698 ),
699 route(
700 "GET",
701 "/repos/:owner/:name/hooks",
702 Op::ListWebhooks,
703 &[],
704 ),
705 route(
706 "POST",
707 "/repos/:owner/:name/hooks",
708 Op::CreateWebhook,
709 &[],
710 ),
711 route(
712 "PATCH",
713 "/repos/:owner/:name/hooks/:id",
714 Op::UpdateWebhook,
715 &[],
716 ),
717 route(
718 "DELETE",
719 "/repos/:owner/:name/hooks/:id",
720 Op::DeleteWebhook,
721 &[],
722 ),
723 route(
724 "POST",
725 "/repos/:owner/:name/hooks/:id/pings",
726 Op::PingWebhook,
727 &[],
728 ),
729 route(
730 "GET",
731 "/repos/:owner/:name/hooks/:id/deliveries",
732 Op::ListWebhookDeliveries,
733 &[],
734 ),
735 route(
736 "POST",
737 "/repos/:owner/:name/hooks/:id/deliveries/:delivery/redeliver",
738 Op::RedeliverWebhook,
739 &[],
740 ),
741 route(
742 "GET",
743 "/workspaces/:workspace/hooks",
744 Op::ListWebhooks,
745 &[],
746 ),
747 route(
748 "POST",
749 "/workspaces/:workspace/hooks",
750 Op::CreateWebhook,
751 &[],
752 ),
753 route(
754 "PATCH",
755 "/workspaces/:workspace/hooks/:id",
756 Op::UpdateWebhook,
757 &[],
758 ),
759 route(
760 "DELETE",
761 "/workspaces/:workspace/hooks/:id",
762 Op::DeleteWebhook,
763 &[],
764 ),
765 route(
766 "POST",
767 "/workspaces/:workspace/hooks/:id/pings",
768 Op::PingWebhook,
769 &[],
770 ),
771 route(
772 "GET",
773 "/workspaces/:workspace/hooks/:id/deliveries",
774 Op::ListWebhookDeliveries,
775 &[],
776 ),
777 route(
778 "POST",
779 "/workspaces/:workspace/hooks/:id/deliveries/:delivery/redeliver",
780 Op::RedeliverWebhook,
781 &[],
782 ),
783 route(
784 "PATCH",
785 "/workspaces/:workspace/integrations/:id",
786 Op::UpdateIntegration,
787 &[],
788 ),
789 route(
790 "DELETE",
791 "/workspaces/:workspace/integrations/:id",
792 Op::DisconnectIntegration,
793 &[],
794 ),
795 route(
796 "POST",
797 "/workspaces/:workspace/integrations/:id/test",
798 Op::TestIntegration,
799 &[],
800 ),
801 route(
802 "GET",
803 "/workspaces/:workspace/ai/providers",
804 Op::ListAiProviders,
805 &[],
806 ),
807 route(
808 "POST",
809 "/workspaces/:workspace/ai/providers",
810 Op::AddAiProvider,
811 &[],
812 ),
813 route(
814 "PATCH",
815 "/workspaces/:workspace/ai/providers/:id",
816 Op::UpdateAiProvider,
817 &[],
818 ),
819 route(
820 "DELETE",
821 "/workspaces/:workspace/ai/providers/:id",
822 Op::RemoveAiProvider,
823 &[],
824 ),
825 route(
826 "POST",
827 "/workspaces/:workspace/ai/providers/:id/test",
828 Op::TestAiProvider,
829 &[],
830 ),
831 route(
832 "GET",
833 "/workspaces/:workspace/ai/ask",
834 Op::GetAskSettings,
835 &[],
836 ),
837 route(
838 "PUT",
839 "/workspaces/:workspace/ai/ask",
840 Op::SetAskSettings,
841 &[],
842 ),
843 route(
844 "GET",
845 "/repos/:owner/:name/actions/workflows",
846 Op::ListWorkflows,
847 &[],
848 ),
849 route(
850 "GET",
851 "/repos/:owner/:name/actions/workflows/:workflow",
852 Op::GetWorkflow,
853 &[("ref", "ref")],
854 ),
855 route(
856 "GET",
857 "/repos/:owner/:name/actions/workflows/:workflow/runs",
858 Op::ListWorkflowRuns,
859 &[("branch", "branch"), ("event", "event"), ("status", "status"), ("head_sha", "sha"), ("since", "since"), ("until", "until"), ("per_page", "limit")],
860 ),
861 route(
862 "POST",
863 "/repos/:owner/:name/actions/workflows/:workflow/dispatches",
864 Op::DispatchWorkflow,
865 &[],
866 ),
867 route(
868 "PATCH",
869 "/repos/:owner/:name/actions/workflows/:workflow",
870 Op::UpdateWorkflow,
871 &[],
872 ),
873 route(
874 "PUT",
875 "/repos/:owner/:name/actions/workflows/:workflow/enable",
876 Op::UpdateWorkflow,
877 &[],
878 ),
879 route(
880 "PUT",
881 "/repos/:owner/:name/actions/workflows/:workflow/disable",
882 Op::UpdateWorkflow,
883 &[],
884 ),
885 route(
886 "GET",
887 "/repos/:owner/:name/actions/runs",
888 Op::ListWorkflowRuns,
889 &[("workflow", "workflow"), ("branch", "branch"), ("event", "event"), ("pull", "pull"), ("head_sha", "sha"), ("status", "status"), ("since", "since"), ("until", "until"), ("per_page", "limit")],
890 ),
891 route(
892 "GET",
893 "/repos/:owner/:name/actions/runs/:id",
894 Op::GetWorkflowRun,
895 &[],
896 ),
897 route(
898 "GET",
899 "/repos/:owner/:name/actions/runs/:id/attempts/:attempt",
900 Op::GetWorkflowRun,
901 &[],
902 ),
903 route(
904 "POST",
905 "/repos/:owner/:name/actions/runs/:id/cancel",
906 Op::CancelWorkflowRun,
907 &[],
908 ),
909 route(
910 "POST",
911 "/repos/:owner/:name/actions/runs/:id/force-cancel",
912 Op::CancelWorkflowRun,
913 &[],
914 ),
915 route(
916 "POST",
917 "/repos/:owner/:name/actions/runs/:id/rerun",
918 Op::RerunWorkflowRun,
919 &[],
920 ),
921 route(
922 "POST",
923 "/repos/:owner/:name/actions/runs/:id/rerun-failed-jobs",
924 Op::RerunWorkflowRun,
925 &[],
926 ),
927 route(
928 "POST",
929 "/repos/:owner/:name/actions/jobs/:job/rerun",
930 Op::RerunWorkflowRun,
931 &[],
932 ),
933 route(
934 "GET",
935 "/repos/:owner/:name/actions/jobs/:job/logs",
936 Op::GetJobLogs,
937 &[("after", "after"), ("tail", "tail")],
938 ),
939 // Packages, at GitHub's addresses with the workspace in place of the
940 // organization. A name with a slash is one URL-encoded segment.
941 route("GET", "/workspaces/:workspace/packages", Op::Packages(PackagesOp::ListPackages), &[("package_type", "package_type"), ("q", "q"), ("state", "state")]),
942 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name", Op::Packages(PackagesOp::GetPackage), &[]),
943 route("PATCH", "/workspaces/:workspace/packages/:package_type/:package_name", Op::Packages(PackagesOp::UpdatePackage), &[]),
944 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name", Op::Packages(PackagesOp::DeletePackage), &[]),
945 route("POST", "/workspaces/:workspace/packages/:package_type/:package_name/restore", Op::Packages(PackagesOp::RestorePackage), &[]),
946 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/versions", Op::Packages(PackagesOp::ListVersions), &[("state", "state")]),
947 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/versions/:version_id", Op::Packages(PackagesOp::GetVersion), &[]),
948 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/versions/:version_id", Op::Packages(PackagesOp::DeleteVersion), &[]),
949 route("POST", "/workspaces/:workspace/packages/:package_type/:package_name/versions/:version_id/restore", Op::Packages(PackagesOp::RestoreVersion), &[]),
950 route("PUT", "/workspaces/:workspace/packages/:package_type/:package_name/repository", Op::Packages(PackagesOp::LinkPackage), &[]),
951 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/repository", Op::Packages(PackagesOp::UnlinkPackage), &[]),
952 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/access", Op::Packages(PackagesOp::ListAccess), &[]),
953 route("PUT", "/workspaces/:workspace/packages/:package_type/:package_name/access", Op::Packages(PackagesOp::SetAccess), &[]),
954 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/access", Op::Packages(PackagesOp::RemoveAccess), &[("username", "username"), ("team", "team")]),
955 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/actions-access", Op::Packages(PackagesOp::ListActionsAccess), &[]),
956 route("PUT", "/workspaces/:workspace/packages/:package_type/:package_name/actions-access", Op::Packages(PackagesOp::SetActionsAccess), &[]),
957 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/actions-access/:repository", Op::Packages(PackagesOp::RemoveActionsAccess), &[]),
958 // Artifacts, at GitHub's addresses. `…/zip` answers with a redirect to
959 // a signed link (lib.rs).
960 route("GET", "/repos/:owner/:name/actions/artifacts", Op::Artifacts(ArtifactsOp::ListArtifacts), &[("name", "name"), ("page", "page"), ("per_page", "per_page")]),
961 route("GET", "/repos/:owner/:name/actions/runs/:id/artifacts", Op::Artifacts(ArtifactsOp::ListRunArtifacts), &[("name", "name")]),
962 route("GET", "/repos/:owner/:name/actions/artifacts/:id", Op::Artifacts(ArtifactsOp::GetArtifact), &[]),
963 route("GET", "/repos/:owner/:name/actions/artifacts/:id/zip", Op::Artifacts(ArtifactsOp::DownloadArtifact), &[]),
964 route("DELETE", "/repos/:owner/:name/actions/artifacts/:id", Op::Artifacts(ArtifactsOp::DeleteArtifact), &[]),
965 route("GET", "/repos/:owner/:name/actions/permissions/artifact-and-log-retention", Op::Artifacts(ArtifactsOp::GetArtifactRetention), &[]),
966 route("PUT", "/repos/:owner/:name/actions/permissions/artifact-and-log-retention", Op::Artifacts(ArtifactsOp::SetArtifactRetention), &[]),
967 route(
968 "GET",
969 "/repos/:owner/:name/actions/caches",
970 Op::Caches(CachesOp::ListCaches),
971 &[("key", "key"), ("ref", "ref"), ("sort", "sort"), ("direction", "direction"), ("page", "page"), ("per_page", "per_page")],
972 ),
973 route("GET", "/repos/:owner/:name/actions/cache/usage", Op::Caches(CachesOp::GetCacheUsage), &[]),
974 route("DELETE", "/repos/:owner/:name/actions/caches", Op::Caches(CachesOp::DeleteCachesByKey), &[("key", "key"), ("ref", "ref")]),
975 route("DELETE", "/repos/:owner/:name/actions/caches/:id", Op::Caches(CachesOp::DeleteCache), &[]),
976 route(
977 "GET",
978 "/repos/:owner/:name/actions/secrets",
979 Op::ListActionsSecrets,
980 &[],
981 ),
982 route(
983 "PUT",
984 "/repos/:owner/:name/actions/secrets/:setting",
985 Op::SetActionsSecret,
986 &[],
987 ),
988 route(
989 "DELETE",
990 "/repos/:owner/:name/actions/secrets/:setting",
991 Op::DeleteActionsSecret,
992 &[],
993 ),
994 route(
995 "GET",
996 "/repos/:owner/:name/actions/variables",
997 Op::ListActionsVariables,
998 &[],
999 ),
1000 route(
1001 "POST",
1002 "/repos/:owner/:name/actions/variables",
1003 Op::SetActionsVariable,
1004 &[],
1005 ),
1006 route(
1007 "PATCH",
1008 "/repos/:owner/:name/actions/variables/:setting",
1009 Op::SetActionsVariable,
1010 &[],
1011 ),
1012 route(
1013 "DELETE",
1014 "/repos/:owner/:name/actions/variables/:setting",
1015 Op::DeleteActionsVariable,
1016 &[],
1017 ),
1018 route(
1019 "GET",
1020 "/workspaces/:workspace/actions/secrets",
1021 Op::ListActionsSecrets,
1022 &[],
1023 ),
1024 route(
1025 "PUT",
1026 "/workspaces/:workspace/actions/secrets/:setting",
1027 Op::SetActionsSecret,
1028 &[],
1029 ),
1030 route(
1031 "DELETE",
1032 "/workspaces/:workspace/actions/secrets/:setting",
1033 Op::DeleteActionsSecret,
1034 &[],
1035 ),
1036 route(
1037 "GET",
1038 "/workspaces/:workspace/actions/variables",
1039 Op::ListActionsVariables,
1040 &[],
1041 ),
1042 route(
1043 "POST",
1044 "/workspaces/:workspace/actions/variables",
1045 Op::SetActionsVariable,
1046 &[],
1047 ),
1048 route(
1049 "PATCH",
1050 "/workspaces/:workspace/actions/variables/:setting",
1051 Op::SetActionsVariable,
1052 &[],
1053 ),
1054 route(
1055 "DELETE",
1056 "/workspaces/:workspace/actions/variables/:setting",
1057 Op::DeleteActionsVariable,
1058 &[],
1059 ),
1060 // Self-hosted runners: a repository's own, or a workspace's.
1061 route("GET", "/repos/:owner/:name/actions/runners", Op::ListRunners, &[]),
1062 route("POST", "/repos/:owner/:name/actions/runners/registration-token", Op::CreateRunnerRegistrationToken, &[]),
1063 route("DELETE", "/repos/:owner/:name/actions/runners/:id", Op::RemoveRunner, &[]),
1064 route("GET", "/repos/:owner/:name/actions/runner-settings", Op::GetRunnerSettings, &[]),
1065 route("PATCH", "/repos/:owner/:name/actions/runner-settings", Op::UpdateRunnerSettings, &[]),
1066 route("GET", "/workspaces/:workspace/actions/runners", Op::ListRunners, &[]),
1067 route("POST", "/workspaces/:workspace/actions/runners/registration-token", Op::CreateRunnerRegistrationToken, &[]),
1068 route("DELETE", "/workspaces/:workspace/actions/runners/:id", Op::RemoveRunner, &[]),
1069 route("GET", "/workspaces/:workspace/actions/runner-settings", Op::GetRunnerSettings, &[]),
1070 route("PATCH", "/workspaces/:workspace/actions/runner-settings", Op::UpdateRunnerSettings, &[]),
1071 route("GET", "/workspaces/:workspace/actions/runner-groups", Op::ListRunnerGroups, &[]),
1072 route("POST", "/workspaces/:workspace/actions/runner-groups", Op::CreateRunnerGroup, &[]),
1073 route("PATCH", "/workspaces/:workspace/actions/runner-groups/:id", Op::UpdateRunnerGroup, &[]),
1074 route("DELETE", "/workspaces/:workspace/actions/runner-groups/:id", Op::DeleteRunnerGroup, &[]),
1075 // Comments on pull requests, and reactions to them.
1076 route("POST", "/repos/:owner/:name/pulls/:number/comments", Op::AddComment, &[]),
1077 route("PATCH", "/repos/:owner/:name/pulls/comments/:comment_id", Op::EditComment, &[]),
1078 route("DELETE", "/repos/:owner/:name/pulls/comments/:comment_id", Op::DeleteComment, &[]),
1079 route("POST", "/repos/:owner/:name/pulls/:number/reactions", Op::React, &[]),
1080 // An image to show in a work item's, a pull request's or a comment's Markdown.
1081 route("POST", "/repos/:owner/:name/attachments", Op::UploadAttachment, &[]),
1082 route(
1083 "GET",
1084 "/repos/:owner/:name/pulls",
1085 Op::ListPullRequests,
1086 &[("state", "state"), ("label", "label"), ("milestone", "milestone"), ("base", "base")],
1087 ),
1088 route(
1089 "POST",
1090 "/repos/:owner/:name/pulls",
1091 Op::CreatePullRequest,
1092 &[],
1093 ),
1094 route(
1095 "GET",
1096 "/repos/:owner/:name/pulls/:number",
1097 Op::GetPullRequest,
1098 &[],
1099 ),
1100 route(
1101 "PATCH",
1102 "/repos/:owner/:name/pulls/:number",
1103 Op::UpdatePullRequest,
1104 &[],
1105 ),
1106 route(
1107 "GET",
1108 "/repos/:owner/:name/pulls/:number/changes",
1109 Op::GetPullRequestChanges,
1110 &[("paths", "paths")],
1111 ),
1112 route(
1113 "POST",
1114 "/repos/:owner/:name/pulls/:number/reviews",
1115 Op::ReviewPullRequest,
1116 &[],
1117 ),
1118 route(
1119 "POST",
1120 "/repos/:owner/:name/pulls/:number/requested_reviewers",
1121 Op::RequestReviewers,
1122 &[],
1123 ),
1124 route(
1125 "DELETE",
1126 "/repos/:owner/:name/pulls/:number/requested_reviewers",
1127 Op::RemoveRequestedReviewers,
1128 &[],
1129 ),
1130 route(
1131 "GET",
1132 "/repos/:owner/:name/pulls/:number/session",
1133 Op::ReadSession,
1134 &[("after", "after")],
1135 ),
1136 route(
1137 "POST",
1138 "/repos/:owner/:name/pulls/:number/session",
1139 Op::RecordSession,
1140 &[],
1141 ),
1142 // Decision records on a pull request (a work item's are with it), and
1143 // why a line is the way it is.
1144 route("GET", "/repos/:owner/:name/pulls/:number/decisions", Op::ListDecisions, &[]),
1145 route("POST", "/repos/:owner/:name/pulls/:number/decisions", Op::RecordDecision, &[]),
1146 route("GET", "/repos/:owner/:name/why", Op::Why, &[("path", "path"), ("line", "line"), ("ref", "ref")]),
1147 route(
1148 "POST",
1149 "/repos/:owner/:name/pulls/:number/ready",
1150 Op::MarkPullRequestReady,
1151 &[],
1152 ),
1153 route("POST", "/repos/:owner/:name/pulls/:number/draft", Op::ConvertPullRequestToDraft, &[]),
1154 route(
1155 "POST",
1156 "/repos/:owner/:name/pulls/:number/close",
1157 Op::ClosePullRequest,
1158 &[],
1159 ),
1160 route("POST", "/repos/:owner/:name/pulls/:number/reopen", Op::ReopenPullRequest, &[]),
1161 route(
1162 "POST",
1163 "/repos/:owner/:name/pulls/:number/merge",
1164 Op::MergePullRequest,
1165 &[],
1166 ),
1167 route("GET", "/repos/:owner/:name/pulls/:number/merge-options", Op::GetPullRequestMergeOptions, &[]),
1168 route("PUT", "/repos/:owner/:name/pulls/:number/update-branch", Op::UpdatePullRequestBranch, &[]),
1169 route("PUT", "/repos/:owner/:name/pulls/:number/auto-merge", Op::EnablePullRequestAutoMerge, &[]),
1170 route("DELETE", "/repos/:owner/:name/pulls/:number/auto-merge", Op::DisablePullRequestAutoMerge, &[]),
1171 route("DELETE", "/repos/:owner/:name/pulls/:number/head-branch", Op::DeletePullRequestHeadBranch, &[]),
1172 route("POST", "/repos/:owner/:name/pulls/:number/head-branch/restore", Op::RestorePullRequestHeadBranch, &[]),
1173 // Commit comments: GitHub's addresses.
1174 route("GET", "/repos/:owner/:name/comments", Op::ListRepoCommitComments, &[("page", "page")]),
1175 route("PATCH", "/repos/:owner/:name/comments/:comment_id", Op::UpdateCommitComment, &[]),
1176 route("DELETE", "/repos/:owner/:name/comments/:comment_id", Op::DeleteCommitComment, &[]),
1177 route("GET", "/repos/:owner/:name/commits/:sha/comments", Op::ListCommitComments, &[]),
1178 route("POST", "/repos/:owner/:name/commits/:sha/comments", Op::CreateCommitComment, &[]),
1179 // Artifacts mode's docs, slides, designs and dashboards. Search comes
1180 // before an artifact by id, which it would otherwise match.
1181 route("GET", "/workspaces/:workspace/artifacts", Op::Folios(FoliosOp::List), &[("tab", "tab"), ("kind", "kind"), ("space", "space"), ("project", "project"), ("q", "q"), ("state", "state"), ("cursor", "cursor"), ("limit", "limit")]),
1182 route("POST", "/workspaces/:workspace/artifacts", Op::Folios(FoliosOp::Create), &[]),
1183 route("GET", "/workspaces/:workspace/artifacts/search", Op::Folios(FoliosOp::Search), &[("q", "q"), ("kind", "kind"), ("space", "space"), ("project", "project"), ("limit", "limit")]),
1184 route("GET", "/workspaces/:workspace/artifacts/:artifact_id", Op::Folios(FoliosOp::Get), &[]),
1185 route("PATCH", "/workspaces/:workspace/artifacts/:artifact_id", Op::Folios(FoliosOp::Update), &[]),
1186 route("DELETE", "/workspaces/:workspace/artifacts/:artifact_id", Op::Folios(FoliosOp::Trash), &[]),
1187 route("POST", "/workspaces/:workspace/artifacts/:artifact_id/restore", Op::Folios(FoliosOp::Restore), &[]),
1188 route("POST", "/workspaces/:workspace/artifacts/:artifact_id/purge", Op::Folios(FoliosOp::Purge), &[]),
1189 route("GET", "/workspaces/:workspace/artifacts/:artifact_id/content", Op::Folios(FoliosOp::GetContent), &[]),
1190 route("PUT", "/workspaces/:workspace/artifacts/:artifact_id/content", Op::Folios(FoliosOp::Edit), &[]),
1191 route("GET", "/workspaces/:workspace/artifacts/:artifact_id/access", Op::Folios(FoliosOp::GetAccess), &[]),
1192 route("PUT", "/workspaces/:workspace/artifacts/:artifact_id/access", Op::Folios(FoliosOp::SetAccess), &[]),
1193 route("GET", "/workspaces/:workspace/artifacts/:artifact_id/versions", Op::Folios(FoliosOp::ListVersions), &[]),
1194 route("POST", "/workspaces/:workspace/artifacts/:artifact_id/versions/:version_id/restore", Op::Folios(FoliosOp::RestoreVersion), &[]),
1195 route("GET", "/workspaces/:workspace/artifact-templates", Op::Folios(FoliosOp::ListTemplates), &[("kind", "kind")]),
1196 route("GET", "/workspaces/:workspace/artifact-spaces", Op::Folios(FoliosOp::ListSpaces), &[]),
1197 route("POST", "/workspaces/:workspace/datasets/query", Op::Folios(FoliosOp::QueryDataset), &[]),
1198];
1199
1200impl Route {
1201 /// Whether the route answers success with `204` and no body, as
1202 /// GitHub's address for the same does. MCP still answers `true`.
1203 pub fn no_content(&self) -> bool {
1204 matches!(
1205 self.op,
1206 Op::DeleteComment | Op::DeleteWorkItemComment | Op::DeleteCommitComment | Op::Caches(CachesOp::DeleteCache)
1207 )
1208 }
1209
1210 /// The names of the route's path parameters, in order.
1211 pub fn params(&self) -> impl Iterator<Item = &'static str> {
1212 self.path
1213 .split('/')
1214 .filter_map(|segment| segment.strip_prefix(':'))
1215 }
1216
1217 /// The values of the path parameters, if `path` is this route's.
1218 fn matches<'a>(&self, path: &'a str) -> Option<Vec<(&'static str, &'a str)>> {
1219 let mut values = Vec::new();
1220 let mut actual = path.trim_end_matches('/').split('/');
1221 for expected in self.path.split('/') {
1222 let segment = actual.next()?;
1223 match expected.strip_prefix(':') {
1224 Some(name) if !segment.is_empty() => values.push((name, segment)),
1225 Some(_) => return None,
1226 None if expected == segment => {}
1227 None => return None,
1228 }
1229 }
1230 actual.next().is_none().then_some(values)
1231 }
1232}
1233
1234/// A path segment with its `%XX` escapes decoded; as given when that is not
1235/// UTF-8.
1236fn percent_decoded(segment: &str) -> String {
1237 let bytes = segment.as_bytes();
1238 let mut out = Vec::with_capacity(bytes.len());
1239 let mut i = 0;
1240 while i < bytes.len() {
1241 let escaped = (bytes[i] == b'%')
1242 .then(|| segment.get(i + 1..i + 3))
1243 .flatten()
1244 .filter(|hex| hex.bytes().all(|byte| byte.is_ascii_hexdigit()))
1245 .and_then(|hex| u8::from_str_radix(hex, 16).ok());
1246 match escaped {
1247 Some(byte) => {
1248 out.push(byte);
1249 i += 3;
1250 }
1251 None => {
1252 out.push(bytes[i]);
1253 i += 1;
1254 }
1255 }
1256 }
1257 String::from_utf8(out).unwrap_or_else(|_| segment.to_owned())
1258}
1259
1260/// The route for a request, and the operation input it describes.
1261///
1262/// The input is the JSON body, overlaid with the query parameters the route
1263/// reads and then with what the path names: `owner` and `name` become
1264/// `repo`, as does a team's `repo` with its `workspace`, and `number`
1265/// becomes an integer.
1266pub fn resolve(
1267 method: &str,
1268 path: &str,
1269 query: &[(String, String)],
1270 body: Value,
1271) -> Option<(&'static Route, Value)> {
1272 let (route, params) = ROUTES
1273 .iter()
1274 .filter(|route| route.method == method)
1275 .find_map(|route| Some((route, route.matches(path)?)))?;
1276
1277 let mut input = match body {
1278 Value::Object(fields) => fields,
1279 _ => Map::new(),
1280 };
1281 for (name, key) in route.query {
1282 if let Some((_, value)) = query.iter().find(|(query_name, _)| query_name == name) {
1283 input.insert((*key).to_owned(), Value::String(value.clone()));
1284 }
1285 }
1286 let param = |wanted: &str| {
1287 params
1288 .iter()
1289 .find(|(name, _)| *name == wanted)
1290 .map(|(_, value)| *value)
1291 };
1292 if let (Some(owner), Some(name)) = (param("owner"), param("name")) {
1293 input.insert("repo".to_owned(), Value::String(format!("{owner}/{name}")));
1294 }
1295 // Every other name the path gives, under that name; the ones below that
1296 // need more (a repository, a number, an encoded name) are set after.
1297 for (key, value) in &params {
1298 if !matches!(*key, "owner" | "name") {
1299 input.insert((*key).to_owned(), Value::String(percent_decoded(value)));
1300 }
1301 }
1302 // A repository of a team's workspace, named by itself.
1303 if let (Some(workspace), Some(name)) = (param("workspace"), param("repo")) {
1304 input.insert("repo".to_owned(), Value::String(format!("{workspace}/{name}")));
1305 }
1306 // A branch name may hold slashes, sent URL-encoded as one segment, and
1307 // a label's name spaces.
1308 if let Some(branch) = param("branch") {
1309 input.insert("branch".to_owned(), Value::String(percent_decoded(branch)));
1310 }
1311 // An environment's name may hold slashes and spaces, URL-encoded.
1312 if let Some(environment) = param("environment") {
1313 input.insert("environment".to_owned(), Value::String(percent_decoded(environment)));
1314 }
1315 if let Some(label) = param("label") {
1316 input.insert("label".to_owned(), Value::String(percent_decoded(label)));
1317 }
1318 if let Some(milestone) = param("milestone") {
1319 // Not a number: zero, which no milestone has.
1320 input.insert("milestone".to_owned(), milestone.parse::<u32>().unwrap_or(0).into());
1321 }
1322 // GitHub says some things with the path alone.
1323 if route.path.ends_with("/enable") || route.path.ends_with("/disable") {
1324 input.insert("enabled".to_owned(), Value::Bool(route.path.ends_with("/enable")));
1325 }
1326 if route.path.ends_with("/rerun-failed-jobs") {
1327 input.insert("failed_only".to_owned(), Value::Bool(true));
1328 }
1329 if route.path.ends_with("/force-cancel") {
1330 input.insert("force".to_owned(), Value::Bool(true));
1331 }
1332 // Unsaving and waking a thread are a DELETE of what PUT made.
1333 if route.method == "DELETE" && route.path.ends_with("/saved") {
1334 input.insert("saved".to_owned(), Value::Bool(false));
1335 }
1336 if route.method == "DELETE" && route.path.ends_with("/snooze") {
1337 input.remove("until");
1338 }
1339 if let Some(number) = param("number") {
1340 // Not a number: zero, which no work item or pull request has.
1341 input.insert(
1342 "number".to_owned(),
1343 number.parse::<u32>().unwrap_or(0).into(),
1344 );
1345 }
1346 Some((route, Value::Object(input)))
1347}
1348
1349#[cfg(test)]
1350mod tests {
1351 use serde_json::json;
1352
1353 use super::*;
1354
1355 /// Every name a route's path gives reaches the operation: a name left
1356 /// off the lists above is dropped, and the operation answers that it
1357 /// was not given (the project routes were, until this test).
1358 #[test]
1359 fn every_path_parameter_reaches_the_input() {
1360 for route in ROUTES.iter() {
1361 let names: Vec<&str> = route.path.split('/').filter_map(|part| part.strip_prefix(':')).collect();
1362 if names.is_empty() {
1363 continue;
1364 }
1365 let path: String = route
1366 .path
1367 .split('/')
1368 .map(|part| match part.strip_prefix(':') {
1369 Some("number" | "milestone") => "7".to_owned(),
1370 Some(name) => format!("{name}-x"),
1371 None => part.to_owned(),
1372 })
1373 .collect::<Vec<_>>()
1374 .join("/");
1375 let (found, input) = resolve(route.method, &path, &[], json!({})).unwrap();
1376 // A path two routes could take is checked under the first.
1377 if found.path != route.path {
1378 continue;
1379 }
1380 for name in names {
1381 let key = match name {
1382 "owner" | "name" => "repo",
1383 "repo" if names_has_workspace(route.path) => "repo",
1384 other => other,
1385 };
1386 assert!(
1387 input.get(key).is_some_and(|value| !value.is_null()),
1388 "{} {}: :{name} does not reach the input",
1389 route.method,
1390 route.path
1391 );
1392 }
1393 }
1394 }
1395
1396 fn names_has_workspace(path: &str) -> bool {
1397 path.split('/').any(|part| part == ":workspace")
1398 }
1399
1400 #[test]
1401 fn a_path_resolves_to_its_operation_and_input() {
1402 let (route, input) = resolve(
1403 "POST",
1404 "/repos/flagon-io/hello/pulls/14/merge",
1405 &[],
1406 json!({ "keep_item_open": true, "number": 99, "repo": "someone/else" }),
1407 )
1408 .unwrap();
1409 assert_eq!(route.op, Op::MergePullRequest);
1410 // What the path names wins over the body.
1411 assert_eq!(
1412 input,
1413 json!({ "keep_item_open": true, "number": 14, "repo": "flagon-io/hello" })
1414 );
1415 }
1416
1417 #[test]
1418 fn a_branch_with_slashes_is_one_encoded_segment() {
1419 let (route, input) = resolve(
1420 "POST",
1421 "/repos/flagon-io/hello/branches/feature%2Flogin/rename",
1422 &[],
1423 json!({ "new_name": "feature/sign-in" }),
1424 )
1425 .unwrap();
1426 assert_eq!(route.op, Op::RenameBranch);
1427 assert_eq!(
1428 input,
1429 json!({ "new_name": "feature/sign-in", "branch": "feature/login", "repo": "flagon-io/hello" })
1430 );
1431 assert_eq!(percent_decoded("100%"), "100%");
1432 assert_eq!(percent_decoded("a%2bb%zz"), "a+b%zz");
1433 }
1434
1435 #[test]
1436 fn a_collaborator_is_named_by_username() {
1437 let (route, input) = resolve(
1438 "PATCH",
1439 "/repos/flagon-io/hello/collaborators/ada",
1440 &[],
1441 json!({ "role": "maintain" }),
1442 )
1443 .unwrap();
1444 assert_eq!(route.op, Op::UpdateCollaborator);
1445 assert_eq!(input, json!({ "role": "maintain", "username": "ada", "repo": "flagon-io/hello" }));
1446 let (route, input) = resolve("DELETE", "/user/repository_invitations/rin_1", &[], Value::Null).unwrap();
1447 assert_eq!(route.op, Op::DeclineRepoInvitation);
1448 assert_eq!(input, json!({ "id": "rin_1" }));
1449 }
1450
1451 #[test]
1452 fn teams_are_addressed_by_workspace_and_slug() {
1453 let query = [("q".to_owned(), "back".to_owned())];
1454 let (route, input) = resolve("GET", "/workspaces/acme/teams", &query, Value::Null).unwrap();
1455 assert_eq!(route.op, Op::ListTeams);
1456 assert_eq!(input, json!({ "query": "back", "workspace": "acme" }));
1457 let (route, input) = resolve("PATCH", "/workspaces/acme/teams/backend", &[], json!({ "name": "Back end" })).unwrap();
1458 assert_eq!(route.op, Op::UpdateTeam);
1459 assert_eq!(input, json!({ "name": "Back end", "workspace": "acme", "team": "backend" }));
1460 let (route, input) =
1461 resolve("PUT", "/workspaces/acme/teams/backend/members/ana", &[], json!({ "role": "maintainer" })).unwrap();
1462 assert_eq!(route.op, Op::SetTeamMember);
1463 assert_eq!(input, json!({ "role": "maintainer", "workspace": "acme", "team": "backend", "username": "ana" }));
1464 let query = [("include_child_teams".to_owned(), "true".to_owned())];
1465 let (route, input) = resolve("GET", "/workspaces/acme/teams/backend/members", &query, Value::Null).unwrap();
1466 assert_eq!(route.op, Op::ListTeamMembers);
1467 assert_eq!(input, json!({ "include_child_teams": "true", "workspace": "acme", "team": "backend" }));
1468 // A repository is named by itself, in the team's workspace.
1469 let (route, input) =
1470 resolve("PUT", "/workspaces/acme/teams/backend/repos/rocket", &[], json!({ "role": "write" })).unwrap();
1471 assert_eq!(route.op, Op::SetTeamRepo);
1472 assert_eq!(input, json!({ "role": "write", "workspace": "acme", "team": "backend", "repo": "acme/rocket" }));
1473 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1474 assert_eq!(op("DELETE", "/workspaces/acme/teams/backend/repos/rocket"), Op::RemoveTeamRepo);
1475 assert_eq!(op("GET", "/workspaces/acme/teams/backend/teams"), Op::ListChildTeams);
1476 assert_eq!(op("GET", "/workspaces/acme/teams/backend/repos"), Op::ListTeamRepos);
1477 assert_eq!(op("PUT", "/workspaces/acme/teams/backend/review_assignment"), Op::SetTeamReviewAssignment);
1478 assert_eq!(op("DELETE", "/workspaces/acme/teams/backend"), Op::DeleteTeam);
1479 assert_eq!(op("POST", "/workspaces/acme/teams"), Op::CreateTeam);
1480 assert_eq!(op("GET", "/workspaces/acme/teams/backend"), Op::GetTeam);
1481 assert_eq!(op("DELETE", "/workspaces/acme/teams/backend/members/ana"), Op::RemoveTeamMember);
1482 let (route, input) = resolve("GET", "/workspaces/acme/members/ana/teams", &[], Value::Null).unwrap();
1483 assert_eq!(route.op, Op::ListUserTeams);
1484 assert_eq!(input, json!({ "workspace": "acme", "username": "ana" }));
1485 }
1486
1487 #[test]
1488 fn reviewers_are_requested_and_code_owners_checked_on_a_repository() {
1489 let body = json!({ "reviewers": ["ana"], "team_reviewers": ["backend"] });
1490 let (route, input) = resolve("POST", "/repos/acme/rocket/pulls/7/requested_reviewers", &[], body.clone()).unwrap();
1491 assert_eq!(route.op, Op::RequestReviewers);
1492 assert_eq!(
1493 input,
1494 json!({ "reviewers": ["ana"], "team_reviewers": ["backend"], "repo": "acme/rocket", "number": 7 })
1495 );
1496 let (route, _) = resolve("DELETE", "/repos/acme/rocket/pulls/7/requested_reviewers", &[], body).unwrap();
1497 assert_eq!(route.op, Op::RemoveRequestedReviewers);
1498 let query = [("ref".to_owned(), "main".to_owned())];
1499 let (route, input) = resolve("GET", "/repos/acme/rocket/codeowners/errors", &query, Value::Null).unwrap();
1500 assert_eq!(route.op, Op::GetCodeownersErrors);
1501 assert_eq!(input, json!({ "ref": "main", "repo": "acme/rocket" }));
1502 }
1503
1504 #[test]
1505 fn events_are_followed_with_a_cursor_filters_and_a_wait() {
1506 let query = [
1507 ("after".to_owned(), "evt_1".to_owned()),
1508 ("types".to_owned(), "work.claimed,integration.failed".to_owned()),
1509 ("numbers".to_owned(), "12,14".to_owned()),
1510 ("wait".to_owned(), "25".to_owned()),
1511 ("limit".to_owned(), "20".to_owned()),
1512 ("since".to_owned(), "2026-10-12T00:00:00Z".to_owned()),
1513 ];
1514 let (route, input) = resolve("GET", "/repos/acme/rocket/events", &query, Value::Null).unwrap();
1515 assert_eq!(route.op, Op::ListEvents);
1516 let asked = crate::follow::asked(&input).unwrap();
1517 assert_eq!(asked.after.as_deref(), Some("evt_1"));
1518 assert_eq!(asked.types, vec!["integration.failed", "work.claimed"]);
1519 assert_eq!(asked.numbers, vec![12, 14]);
1520 assert_eq!(asked.wait_ms, 25_000);
1521 assert_eq!(asked.limit, Some(20));
1522 assert_eq!(asked.since.as_deref(), Some("2026-10-12T00:00:00Z"));
1523 }
1524
1525 #[test]
1526 fn notifications_are_addressed_as_threads_and_by_number() {
1527 let (route, input) = resolve("DELETE", "/notifications/threads/ntf_1", &[], Value::Null).unwrap();
1528 assert_eq!(route.op, Op::MarkThreadDone);
1529 assert_eq!(input, json!({ "id": "ntf_1" }));
1530 let (route, input) = resolve("DELETE", "/notifications/threads/ntf_1/saved", &[], Value::Null).unwrap();
1531 assert_eq!(route.op, Op::SaveThread);
1532 assert_eq!(input, json!({ "id": "ntf_1", "saved": false }));
1533 let (route, input) = resolve("DELETE", "/notifications/threads/ntf_1/snooze", &[], json!({ "until": "x" })).unwrap();
1534 assert_eq!(route.op, Op::SnoozeThread);
1535 assert_eq!(input, json!({ "id": "ntf_1" }));
1536 let query = [("all".to_owned(), "true".to_owned()), ("per_page".to_owned(), "50".to_owned())];
1537 let (route, input) = resolve("GET", "/repos/acme/rocket/notifications", &query, Value::Null).unwrap();
1538 assert_eq!(route.op, Op::ListNotifications);
1539 assert_eq!(input, json!({ "all": "true", "per_page": "50", "repo": "acme/rocket" }));
1540 let (route, input) = resolve("PUT", "/workspaces/acme/work/7/subscription", &[], json!({ "ignored": true })).unwrap();
1541 assert_eq!(route.op, Op::SetThreadSubscription);
1542 assert_eq!(input, json!({ "ignored": true, "number": 7, "workspace": "acme" }));
1543 let (route, input) = resolve("PUT", "/repos/acme/rocket/pulls/7/subscription", &[], json!({ "ignored": true })).unwrap();
1544 assert_eq!(route.op, Op::SetThreadSubscription);
1545 assert_eq!(input, json!({ "ignored": true, "number": 7, "repo": "acme/rocket" }));
1546 assert_eq!(resolve("GET", "/user/subscriptions", &[], Value::Null).unwrap().0.op, Op::ListWatchedRepos);
1547 }
1548
1549 #[test]
1550 fn labels_and_milestones_are_named_in_the_path() {
1551 let (route, input) = resolve("PATCH", "/workspaces/acme/labels/good%20first%20issue", &[], json!({ "color": "7057ff" })).unwrap();
1552 assert_eq!(route.op, Op::UpdateLabel);
1553 assert_eq!(input, json!({ "color": "7057ff", "label": "good first issue", "workspace": "acme" }));
1554 let (route, input) = resolve("DELETE", "/workspaces/acme/work/7/labels/bug", &[], Value::Null).unwrap();
1555 assert_eq!(route.op, Op::RemoveWorkItemLabels);
1556 assert_eq!(input, json!({ "label": "bug", "number": 7, "workspace": "acme" }));
1557 let (route, input) = resolve("DELETE", "/workspaces/acme/work/7/labels", &[], Value::Null).unwrap();
1558 assert_eq!(route.op, Op::RemoveWorkItemLabels);
1559 assert_eq!(input, json!({ "number": 7, "workspace": "acme" }));
1560 let (route, _) = resolve("POST", "/workspaces/acme/labels/defaults", &[], Value::Null).unwrap();
1561 assert_eq!(route.op, Op::AddDefaultLabels);
1562 let (route, input) = resolve("PATCH", "/workspaces/acme/milestones/3", &[], json!({ "state": "closed" })).unwrap();
1563 assert_eq!(route.op, Op::UpdateMilestone);
1564 assert_eq!(input, json!({ "state": "closed", "milestone": 3, "workspace": "acme" }));
1565 // A repository's labels and milestones are its workspace's now.
1566 assert!(resolve("GET", "/repos/acme/web/labels", &[], Value::Null).is_none());
1567 assert!(resolve("GET", "/repos/acme/web/milestones", &[], Value::Null).is_none());
1568 let (route, input) = resolve("PATCH", "/repos/acme/web/pulls/9", &[], json!({ "base": "release" })).unwrap();
1569 assert_eq!(route.op, Op::UpdatePullRequest);
1570 assert_eq!(input, json!({ "base": "release", "number": 9, "repo": "acme/web" }));
1571 }
1572
1573 #[test]
1574 fn merging_settings_and_commit_comments_have_their_addresses() {
1575 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1576 assert_eq!(op("GET", "/repos/acme/web/pulls/9/merge-options"), Op::GetPullRequestMergeOptions);
1577 assert_eq!(op("PUT", "/repos/acme/web/pulls/9/update-branch"), Op::UpdatePullRequestBranch);
1578 assert_eq!(op("PUT", "/repos/acme/web/pulls/9/auto-merge"), Op::EnablePullRequestAutoMerge);
1579 assert_eq!(op("DELETE", "/repos/acme/web/pulls/9/auto-merge"), Op::DisablePullRequestAutoMerge);
1580 assert_eq!(op("DELETE", "/repos/acme/web/pulls/9/head-branch"), Op::DeletePullRequestHeadBranch);
1581 assert_eq!(op("POST", "/repos/acme/web/pulls/9/head-branch/restore"), Op::RestorePullRequestHeadBranch);
1582 let (route, input) = resolve("GET", "/repos/acme/web/comments", &[("page".to_owned(), "2".to_owned())], Value::Null).unwrap();
1583 assert_eq!(route.op, Op::ListRepoCommitComments);
1584 assert_eq!(input, json!({ "page": "2", "repo": "acme/web" }));
1585 let (route, input) =
1586 resolve("POST", "/repos/acme/web/commits/9f2c4e1/comments", &[], json!({ "body": "Why?", "path": "a.rs", "line": 3 })).unwrap();
1587 assert_eq!(route.op, Op::CreateCommitComment);
1588 assert_eq!(input, json!({ "body": "Why?", "path": "a.rs", "line": 3, "sha": "9f2c4e1", "repo": "acme/web" }));
1589 assert_eq!(op("GET", "/repos/acme/web/commits/9f2c4e1/comments"), Op::ListCommitComments);
1590 // Still a commit's statuses, beside its comments.
1591 assert_eq!(op("GET", "/repos/acme/web/commits/main/statuses"), Op::Checks(ChecksOp::ListCommitStatuses));
1592 let (route, input) = resolve("PATCH", "/repos/acme/web/comments/cc_1", &[], json!({ "body": "Better" })).unwrap();
1593 assert_eq!(route.op, Op::UpdateCommitComment);
1594 assert_eq!(input, json!({ "body": "Better", "comment_id": "cc_1", "repo": "acme/web" }));
1595 let (route, _) = resolve("DELETE", "/repos/acme/web/comments/cc_1", &[], Value::Null).unwrap();
1596 assert!(route.op == Op::DeleteCommitComment && route.no_content());
1597 // A pull request's comments keep theirs.
1598 assert_eq!(op("PATCH", "/repos/acme/web/pulls/comments/cmt_1"), Op::EditComment);
1599 }
1600
1601 #[test]
1602 fn pull_requests_reopen_and_turn_draft_and_comments_are_named_by_id() {
1603 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1604 assert_eq!(op("POST", "/repos/acme/web/pulls/9/reopen"), Op::ReopenPullRequest);
1605 assert_eq!(op("POST", "/repos/acme/web/pulls/9/draft"), Op::ConvertPullRequestToDraft);
1606 assert_eq!(op("POST", "/repos/acme/web/pulls/9/close"), Op::ClosePullRequest);
1607 // Reopening and closing with a PATCH, as `state`.
1608 let (route, input) = resolve("PATCH", "/repos/acme/web/pulls/9", &[], json!({ "state": "open" })).unwrap();
1609 assert_eq!(route.op, Op::UpdatePullRequest);
1610 assert_eq!(input, json!({ "state": "open", "number": 9, "repo": "acme/web" }));
1611 let (route, input) =
1612 resolve("PATCH", "/repos/acme/web/pulls/comments/cmt_1", &[], json!({ "body": "Better" })).unwrap();
1613 assert_eq!(route.op, Op::EditComment);
1614 assert_eq!(input, json!({ "body": "Better", "comment_id": "cmt_1", "repo": "acme/web" }));
1615 let (route, input) = resolve("DELETE", "/repos/acme/web/pulls/comments/cmt_1", &[], Value::Null).unwrap();
1616 assert_eq!(route.op, Op::DeleteComment);
1617 assert_eq!(input, json!({ "comment_id": "cmt_1", "repo": "acme/web" }));
1618 assert_eq!(op("POST", "/repos/acme/web/pulls/7/comments"), Op::AddComment);
1619 assert_eq!(op("POST", "/repos/acme/web/pulls/7/reactions"), Op::React);
1620 assert_eq!(op("POST", "/repos/acme/web/attachments"), Op::UploadAttachment);
1621 assert_eq!(op("DELETE", "/repos/acme/web/pulls/7/subscription"), Op::DeleteThreadSubscription);
1622 // A work item's are in its workspace.
1623 let (route, input) =
1624 resolve("PATCH", "/workspaces/acme/work/comments/cmt_1", &[], json!({ "body": "Better" })).unwrap();
1625 assert_eq!(route.op, Op::EditWorkItemComment);
1626 assert_eq!(input, json!({ "body": "Better", "comment_id": "cmt_1", "workspace": "acme" }));
1627 assert_eq!(op("DELETE", "/workspaces/acme/work/comments/cmt_1"), Op::DeleteWorkItemComment);
1628 assert_eq!(op("POST", "/workspaces/acme/work/7/comments"), Op::AddWorkItemComment);
1629 assert_eq!(op("POST", "/workspaces/acme/work/7/reactions"), Op::ReactToWorkItem);
1630 assert_eq!(op("DELETE", "/workspaces/acme/work/7/subscription"), Op::DeleteThreadSubscription);
1631 }
1632
1633 #[test]
1634 fn work_items_are_addressed_by_workspace_and_number() {
1635 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1636 let query = [("state".to_owned(), "open".to_owned()), ("repo".to_owned(), "acme/web".to_owned()), ("role".to_owned(), "target".to_owned())];
1637 let (route, input) = resolve("GET", "/workspaces/acme/work", &query, Value::Null).unwrap();
1638 assert_eq!(route.op, Op::ListWorkItems);
1639 assert_eq!(input, json!({ "state": "open", "repo": "acme/web", "role": "target", "workspace": "acme" }));
1640 assert_eq!(op("POST", "/workspaces/acme/work"), Op::OpenWorkItem);
1641 assert_eq!(op("POST", "/workspaces/acme/work/import"), Op::ImportWorkItems);
1642 let (route, input) = resolve("GET", "/workspaces/acme/work/12", &[], Value::Null).unwrap();
1643 assert_eq!(route.op, Op::GetWorkItem);
1644 assert_eq!(input, json!({ "number": 12, "workspace": "acme" }));
1645 assert_eq!(op("PATCH", "/workspaces/acme/work/12"), Op::UpdateWorkItem);
1646 assert_eq!(op("POST", "/workspaces/acme/work/12/close"), Op::CloseWorkItem);
1647 assert_eq!(op("POST", "/workspaces/acme/work/12/reopen"), Op::ReopenWorkItem);
1648 assert_eq!(op("GET", "/workspaces/acme/work/12/links"), Op::ListWorkItemLinks);
1649 assert_eq!(op("POST", "/workspaces/acme/work/12/links"), Op::LinkWorkItem);
1650 let (route, input) = resolve("DELETE", "/workspaces/acme/work/12/links", &[("repo".to_owned(), "acme/api".to_owned())], Value::Null).unwrap();
1651 assert_eq!(route.op, Op::UnlinkWorkItem);
1652 assert_eq!(input, json!({ "repo": "acme/api", "number": 12, "workspace": "acme" }));
1653 assert_eq!(op("GET", "/workspaces/acme/work/12/decisions"), Op::ListWorkItemDecisions);
1654 assert_eq!(op("GET", "/repos/acme/web/work"), Op::ListRepoWorkItems);
1655 let (route, input) = resolve("GET", "/repos/acme/web/refs/7", &[], Value::Null).unwrap();
1656 assert_eq!(route.op, Op::ResolveRef);
1657 assert_eq!(input, json!({ "number": 7, "repo": "acme/web" }));
1658 assert_eq!(op("GET", "/workspaces/acme/refs/7"), Op::ResolveRef);
1659 // The repository's issues are gone, with no aliases.
1660 for path in ["/repos/acme/web/issues", "/repos/acme/web/issues/7", "/repos/acme/web/issues/7/comments"] {
1661 assert!(resolve("GET", path, &[], Value::Null).is_none(), "{path}");
1662 }
1663 }
1664
1665 #[test]
1666 fn observability_is_addressed_by_workspace_and_project() {
1667 let query = [("level".to_owned(), "error,warn".to_owned()), ("q".to_owned(), "timeout".to_owned())];
1668 let (route, input) = resolve("GET", "/workspaces/acme/projects/web/observability/logs", &query, Value::Null).unwrap();
1669 assert_eq!(route.op, Op::Telemetry(TelemetryOp::ListLogs));
1670 assert_eq!(input, json!({ "level": "error,warn", "q": "timeout", "workspace": "acme", "project": "web" }));
1671 let (route, input) =
1672 resolve("GET", "/workspaces/acme/projects/web/observability/metrics/http.server.request.duration", &[], Value::Null).unwrap();
1673 assert_eq!(route.op, Op::Telemetry(TelemetryOp::GetMetric));
1674 assert_eq!(input["metric"], json!("http.server.request.duration"));
1675 let (route, input) =
1676 resolve("PATCH", "/workspaces/acme/projects/web/observability/errors/f00d", &[], json!({ "state": "resolved" })).unwrap();
1677 assert_eq!(route.op, Op::Telemetry(TelemetryOp::UpdateError));
1678 assert_eq!(input, json!({ "state": "resolved", "workspace": "acme", "project": "web", "fingerprint": "f00d" }));
1679 }
1680
1681 #[test]
1682 fn billing_is_addressed_by_workspace() {
1683 let query = [("from".to_owned(), "2026-10-01".to_owned()), ("products".to_owned(), "agent,sandboxes".to_owned())];
1684 let (route, input) = resolve("GET", "/workspaces/acme/usage", &query, Value::Null).unwrap();
1685 assert_eq!(route.op, Op::GetUsage);
1686 assert_eq!(input, json!({ "from": "2026-10-01", "products": "agent,sandboxes", "workspace": "acme" }));
1687 let (route, input) = resolve("PUT", "/workspaces/acme/budget", &[], json!({ "alerts": [50] })).unwrap();
1688 assert_eq!(route.op, Op::SetBudget);
1689 assert_eq!(input, json!({ "alerts": [50], "workspace": "acme" }));
1690 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1691 assert_eq!(op("GET", "/workspaces/acme/budget"), Op::GetBudget);
1692 assert_eq!(op("GET", "/workspaces/acme/invoices"), Op::ListInvoices);
1693 assert_eq!(op("GET", "/workspaces/acme/billing_details"), Op::GetBillingDetails);
1694 }
1695
1696 #[test]
1697 fn checks_are_at_githubs_addresses() {
1698 let sha = "a".repeat(40);
1699 let body = json!({ "state": "success", "context": "ci/build" });
1700 let (route, input) = resolve("POST", &format!("/repos/acme/web/statuses/{sha}"), &[], body).unwrap();
1701 assert_eq!(route.op, Op::Checks(ChecksOp::CreateCommitStatus));
1702 assert_eq!(input, json!({ "state": "success", "context": "ci/build", "sha": sha, "repo": "acme/web" }));
1703 let (route, input) = resolve("GET", "/repos/acme/web/commits/release%2F1.x/status", &[], Value::Null).unwrap();
1704 assert_eq!(route.op, Op::Checks(ChecksOp::GetCombinedStatus));
1705 assert_eq!(input, json!({ "ref": "release/1.x", "repo": "acme/web" }));
1706 let query = [("check_name".to_owned(), "lint".to_owned())];
1707 let (route, input) = resolve("GET", "/repos/acme/web/commits/main/check-runs", &query, Value::Null).unwrap();
1708 assert_eq!(route.op, Op::Checks(ChecksOp::ListCheckRunsForRef));
1709 assert_eq!(input, json!({ "check_name": "lint", "ref": "main", "repo": "acme/web" }));
1710 let (route, input) = resolve("PATCH", "/repos/acme/web/check-runs/cr_1", &[], json!({ "conclusion": "success" })).unwrap();
1711 assert_eq!(route.op, Op::Checks(ChecksOp::UpdateCheckRun));
1712 assert_eq!(input, json!({ "conclusion": "success", "id": "cr_1", "repo": "acme/web" }));
1713 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1714 assert_eq!(op("POST", "/repos/acme/web/check-runs"), Op::Checks(ChecksOp::CreateCheckRun));
1715 assert_eq!(op("GET", "/repos/acme/web/check-runs/cr_1/annotations"), Op::Checks(ChecksOp::ListCheckRunAnnotations));
1716 assert_eq!(op("POST", "/repos/acme/web/check-suites/cs_1/rerequest"), Op::Checks(ChecksOp::RerequestCheckSuite));
1717 assert_eq!(op("GET", "/repos/acme/web/commits/main/check-suites"), Op::Checks(ChecksOp::ListCheckSuitesForRef));
1718 }
1719
1720 #[test]
1721 fn archives_are_at_githubs_addresses_and_redirect() {
1722 let sha = "4807077b296e6edbf410d55e72749d3e1170c291";
1723 let (route, input) = resolve("GET", &format!("/repos/acme/web/tarball/{sha}"), &[], Value::Null).unwrap();
1724 assert_eq!(route.op, Op::Archives(ArchiveOp::DownloadTarball));
1725 assert_eq!(input, json!({ "ref": sha, "repo": "acme/web" }));
1726 // A branch with slashes, URL-encoded as octokit sends it.
1727 let (route, input) = resolve("GET", "/repos/acme/web/zipball/release%2F1.x", &[], Value::Null).unwrap();
1728 assert_eq!(route.op, Op::Archives(ArchiveOp::DownloadZipball));
1729 assert_eq!(input, json!({ "ref": "release/1.x", "repo": "acme/web" }));
1730 // Both answer with a redirect to their link, as the artifact download does.
1731 assert!(route.op.redirects());
1732 assert!(Op::Archives(ArchiveOp::DownloadTarball).redirects());
1733 assert!(Op::Artifacts(ArtifactsOp::DownloadArtifact).redirects());
1734 assert!(!Op::GetRepo.redirects());
1735 // Anyone may ask for a public repository's.
1736 assert!(!route.op.needs_user());
1737 }
1738
1739 #[test]
1740 fn caches_are_at_githubs_addresses() {
1741 let query = [("key".to_owned(), "cargo-".to_owned()), ("ref".to_owned(), "refs/heads/main".to_owned()), ("sort".to_owned(), "size_in_bytes".to_owned())];
1742 let (route, input) = resolve("GET", "/repos/acme/web/actions/caches", &query, Value::Null).unwrap();
1743 assert_eq!(route.op, Op::Caches(CachesOp::ListCaches));
1744 assert_eq!(input, json!({ "key": "cargo-", "ref": "refs/heads/main", "sort": "size_in_bytes", "repo": "acme/web" }));
1745 let (route, _) = resolve("GET", "/repos/acme/web/actions/cache/usage", &[], Value::Null).unwrap();
1746 assert_eq!(route.op, Op::Caches(CachesOp::GetCacheUsage));
1747 // Deleting by key takes it from the query, as GitHub's does.
1748 let query = [("key".to_owned(), "npm-full-Linux-abc".to_owned())];
1749 let (route, input) = resolve("DELETE", "/repos/acme/web/actions/caches", &query, Value::Null).unwrap();
1750 assert_eq!(route.op, Op::Caches(CachesOp::DeleteCachesByKey));
1751 assert_eq!(input, json!({ "key": "npm-full-Linux-abc", "repo": "acme/web" }));
1752 assert!(!route.no_content());
1753 let (route, input) = resolve("DELETE", "/repos/acme/web/actions/caches/42", &[], Value::Null).unwrap();
1754 assert_eq!(route.op, Op::Caches(CachesOp::DeleteCache));
1755 assert_eq!(input, json!({ "id": "42", "repo": "acme/web" }));
1756 assert!(route.no_content());
1757 // Only someone signed in sees a repository's cache keys.
1758 assert!(Op::Caches(CachesOp::ListCaches).needs_user());
1759 }
1760
1761 #[test]
1762 fn query_parameters_are_renamed() {
1763 let query = [
1764 ("q".to_owned(), "parser".to_owned()),
1765 ("x".to_owned(), "y".to_owned()),
1766 ];
1767 let (route, input) = resolve("GET", "/repos", &query, Value::Null).unwrap();
1768 assert_eq!(route.op, Op::ListRepos);
1769 assert_eq!(input, json!({ "query": "parser" }));
1770 }
1771
1772 #[test]
1773 fn method_and_shape_must_match() {
1774 assert!(resolve("GET", "/workspaces/a/work/1/close", &[], Value::Null).is_none());
1775 assert!(resolve("GET", "/repos/a", &[], Value::Null).is_none());
1776 assert!(resolve("GET", "/workspaces/a/work/1/extra", &[], Value::Null).is_none());
1777 assert!(resolve("GET", "/repos/a/b/", &[], Value::Null).is_some());
1778 }
1779
1780 #[test]
1781 fn every_parameter_and_query_name_is_an_input() {
1782 for route in ROUTES {
1783 let properties = route.op.properties();
1784 for (_, key) in route.query {
1785 assert!(properties.contains_key(*key), "{}: {key}", route.path);
1786 }
1787 for name in route.params() {
1788 let covered = matches!(name, "owner" | "name") && properties.contains_key("repo")
1789 || properties.contains_key(name);
1790 assert!(covered, "{}: {name}", route.path);
1791 }
1792 }
1793 }
1794
1795 #[test]
1796 fn every_operation_has_a_route() {
1797 for op in Op::ALL {
1798 assert!(ROUTES.iter().any(|route| route.op == op), "{}", op.name());
1799 }
1800 }
1801}