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,820 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 &[
607 ("state", "state"),
608 ("label", "label"),
609 ("milestone", "milestone"),
610 ("assignee", "assignee"),
611 ("repo", "repo"),
612 ("role", "role"),
613 ("horizon", "horizon"),
614 ("limit", "limit"),
615 ],
616 ),
617 route("POST", "/workspaces/:workspace/work", Op::OpenWorkItem, &[]),
618 route("POST", "/workspaces/:workspace/work/import", Op::ImportWorkItems, &[]),
619 route("PATCH", "/workspaces/:workspace/work/comments/:comment_id", Op::EditWorkItemComment, &[]),
620 route("DELETE", "/workspaces/:workspace/work/comments/:comment_id", Op::DeleteWorkItemComment, &[]),
621 route("GET", "/workspaces/:workspace/work/:number", Op::GetWorkItem, &[]),
622 route("PATCH", "/workspaces/:workspace/work/:number", Op::UpdateWorkItem, &[]),
623 route("POST", "/workspaces/:workspace/work/:number/close", Op::CloseWorkItem, &[]),
624 route("POST", "/workspaces/:workspace/work/:number/reopen", Op::ReopenWorkItem, &[]),
625 route("POST", "/workspaces/:workspace/work/:number/plan", Op::PlanWorkItem, &[]),
626 // The plan: where each open work item stands, and in what order the
627 // work is taken.
628 route("GET", "/workspaces/:workspace/plan", Op::GetPlan, &[("repo", "repo"), ("all", "all")]),
629 route("PATCH", "/workspaces/:workspace/plan", Op::ConfigurePlan, &[]),
630 route("GET", "/workspaces/:workspace/plan/next", Op::NextWorkItem, &[("repo", "repo")]),
631 route("GET", "/workspaces/:workspace/work/:number/links", Op::ListWorkItemLinks, &[]),
632 route("POST", "/workspaces/:workspace/work/:number/links", Op::LinkWorkItem, &[]),
633 route("DELETE", "/workspaces/:workspace/work/:number/links", Op::UnlinkWorkItem, &[("repo", "repo")]),
634 route("GET", "/workspaces/:workspace/work/:number/labels", Op::ListWorkItemLabels, &[]),
635 route("POST", "/workspaces/:workspace/work/:number/labels", Op::AddWorkItemLabels, &[]),
636 route("PUT", "/workspaces/:workspace/work/:number/labels", Op::SetWorkItemLabels, &[]),
637 route("DELETE", "/workspaces/:workspace/work/:number/labels", Op::RemoveWorkItemLabels, &[]),
638 route("DELETE", "/workspaces/:workspace/work/:number/labels/:label", Op::RemoveWorkItemLabels, &[]),
639 route("POST", "/workspaces/:workspace/work/:number/comments", Op::AddWorkItemComment, &[]),
640 route("POST", "/workspaces/:workspace/work/:number/reactions", Op::ReactToWorkItem, &[]),
641 route("POST", "/workspaces/:workspace/work/:number/attachments", Op::UploadWorkItemAttachment, &[]),
642 route("GET", "/workspaces/:workspace/work/:number/decisions", Op::ListWorkItemDecisions, &[]),
643 // The work items linked to a repository: its Work tab. Read only.
644 route("GET", "/repos/:owner/:name/work", Op::ListRepoWorkItems, &[("state", "state"), ("label", "label"), ("milestone", "milestone"), ("assignee", "assignee"), ("role", "role")]),
645 // What `#N` names, read in a repository or a workspace: how an old
646 // link to a repository's issue finds the work item it became.
647 route("GET", "/repos/:owner/:name/refs/:number", Op::ResolveRef, &[]),
648 route("GET", "/workspaces/:workspace/refs/:number", Op::ResolveRef, &[]),
649 // Coordinating work: claims on work items, a work item's whole context,
650 // and sessions of people's own harnesses.
651 route("GET", "/workspaces/:workspace/work/:number/work", Op::Coordination(CoordinationOp::GetWork), &[]),
652 route("POST", "/workspaces/:workspace/work/:number/claim", Op::Coordination(CoordinationOp::ClaimWorkItem), &[]),
653 // Work with no work item yet: open one from a title and claim it.
654 route("POST", "/workspaces/:workspace/claims", Op::Coordination(CoordinationOp::ClaimWorkItem), &[]),
655 route("POST", "/workspaces/:workspace/work/:number/release", Op::Coordination(CoordinationOp::ReleaseClaim), &[]),
656 route("POST", "/workspaces/:workspace/work/:number/handoff", Op::Coordination(CoordinationOp::HandOffWorkItem), &[]),
657 route(
658 "GET",
659 "/workspaces/:workspace/claims",
660 Op::Coordination(CoordinationOp::ListClaims),
661 &[("state", "state"), ("item", "item"), ("repo", "repo")],
662 ),
663 route(
664 "GET",
665 "/workspaces/:workspace/sessions",
666 Op::Coordination(CoordinationOp::ListWorkspaceSessions),
667 &[
668 ("state", "state"),
669 ("kind", "kind"),
670 ("harness", "harness"),
671 ("person", "person"),
672 ("repo", "repo"),
673 ("item", "item"),
674 ("subagents", "subagents"),
675 ("limit", "limit"),
676 ],
677 ),
678 route("GET", "/workspaces/:workspace/sessions/:id", Op::Coordination(CoordinationOp::GetWorkspaceSession), &[("after", "after")]),
679 route("POST", "/repos/:owner/:name/sessions", Op::Coordination(CoordinationOp::StartSession), &[]),
680 route(
681 "GET",
682 "/repos/:owner/:name/sessions",
683 Op::Coordination(CoordinationOp::ListSessions),
684 &[("state", "state"), ("item", "item"), ("pull", "pull"), ("path", "path"), ("subagents", "subagents")],
685 ),
686 route("POST", "/repos/:owner/:name/agent-sessions", Op::Coordination(CoordinationOp::StartAgentSession), &[]),
687 route("GET", "/repos/:owner/:name/sessions/:id", Op::Coordination(CoordinationOp::GetSession), &[("after", "after")]),
688 route("PATCH", "/repos/:owner/:name/sessions/:id", Op::Coordination(CoordinationOp::UpdateSession), &[]),
689 route("POST", "/repos/:owner/:name/sessions/:id/end", Op::Coordination(CoordinationOp::EndSession), &[]),
690 route(
691 "POST",
692 "/repos/:owner/:name/sessions/:id/entries",
693 Op::Coordination(CoordinationOp::RecordSessionEntries),
694 &[],
695 ),
696 route(
697 "GET",
698 "/repos/:owner/:name/context",
699 Op::GetContext,
700 &[("reference", "reference")],
701 ),
702 route(
703 "GET",
704 "/workspaces/:workspace/integrations",
705 Op::ListIntegrations,
706 &[],
707 ),
708 route(
709 "POST",
710 "/workspaces/:workspace/integrations",
711 Op::ConnectIntegration,
712 &[],
713 ),
714 route(
715 "GET",
716 "/repos/:owner/:name/hooks",
717 Op::ListWebhooks,
718 &[],
719 ),
720 route(
721 "POST",
722 "/repos/:owner/:name/hooks",
723 Op::CreateWebhook,
724 &[],
725 ),
726 route(
727 "PATCH",
728 "/repos/:owner/:name/hooks/:id",
729 Op::UpdateWebhook,
730 &[],
731 ),
732 route(
733 "DELETE",
734 "/repos/:owner/:name/hooks/:id",
735 Op::DeleteWebhook,
736 &[],
737 ),
738 route(
739 "POST",
740 "/repos/:owner/:name/hooks/:id/pings",
741 Op::PingWebhook,
742 &[],
743 ),
744 route(
745 "GET",
746 "/repos/:owner/:name/hooks/:id/deliveries",
747 Op::ListWebhookDeliveries,
748 &[],
749 ),
750 route(
751 "POST",
752 "/repos/:owner/:name/hooks/:id/deliveries/:delivery/redeliver",
753 Op::RedeliverWebhook,
754 &[],
755 ),
756 route(
757 "GET",
758 "/workspaces/:workspace/hooks",
759 Op::ListWebhooks,
760 &[],
761 ),
762 route(
763 "POST",
764 "/workspaces/:workspace/hooks",
765 Op::CreateWebhook,
766 &[],
767 ),
768 route(
769 "PATCH",
770 "/workspaces/:workspace/hooks/:id",
771 Op::UpdateWebhook,
772 &[],
773 ),
774 route(
775 "DELETE",
776 "/workspaces/:workspace/hooks/:id",
777 Op::DeleteWebhook,
778 &[],
779 ),
780 route(
781 "POST",
782 "/workspaces/:workspace/hooks/:id/pings",
783 Op::PingWebhook,
784 &[],
785 ),
786 route(
787 "GET",
788 "/workspaces/:workspace/hooks/:id/deliveries",
789 Op::ListWebhookDeliveries,
790 &[],
791 ),
792 route(
793 "POST",
794 "/workspaces/:workspace/hooks/:id/deliveries/:delivery/redeliver",
795 Op::RedeliverWebhook,
796 &[],
797 ),
798 route(
799 "PATCH",
800 "/workspaces/:workspace/integrations/:id",
801 Op::UpdateIntegration,
802 &[],
803 ),
804 route(
805 "DELETE",
806 "/workspaces/:workspace/integrations/:id",
807 Op::DisconnectIntegration,
808 &[],
809 ),
810 route(
811 "POST",
812 "/workspaces/:workspace/integrations/:id/test",
813 Op::TestIntegration,
814 &[],
815 ),
816 route(
817 "GET",
818 "/workspaces/:workspace/ai/providers",
819 Op::ListAiProviders,
820 &[],
821 ),
822 route(
823 "POST",
824 "/workspaces/:workspace/ai/providers",
825 Op::AddAiProvider,
826 &[],
827 ),
828 route(
829 "PATCH",
830 "/workspaces/:workspace/ai/providers/:id",
831 Op::UpdateAiProvider,
832 &[],
833 ),
834 route(
835 "DELETE",
836 "/workspaces/:workspace/ai/providers/:id",
837 Op::RemoveAiProvider,
838 &[],
839 ),
840 route(
841 "POST",
842 "/workspaces/:workspace/ai/providers/:id/test",
843 Op::TestAiProvider,
844 &[],
845 ),
846 route(
847 "GET",
848 "/workspaces/:workspace/ai/ask",
849 Op::GetAskSettings,
850 &[],
851 ),
852 route(
853 "PUT",
854 "/workspaces/:workspace/ai/ask",
855 Op::SetAskSettings,
856 &[],
857 ),
858 route(
859 "GET",
860 "/repos/:owner/:name/actions/workflows",
861 Op::ListWorkflows,
862 &[],
863 ),
864 route(
865 "GET",
866 "/repos/:owner/:name/actions/workflows/:workflow",
867 Op::GetWorkflow,
868 &[("ref", "ref")],
869 ),
870 route(
871 "GET",
872 "/repos/:owner/:name/actions/workflows/:workflow/runs",
873 Op::ListWorkflowRuns,
874 &[("branch", "branch"), ("event", "event"), ("status", "status"), ("head_sha", "sha"), ("since", "since"), ("until", "until"), ("per_page", "limit")],
875 ),
876 route(
877 "POST",
878 "/repos/:owner/:name/actions/workflows/:workflow/dispatches",
879 Op::DispatchWorkflow,
880 &[],
881 ),
882 route(
883 "PATCH",
884 "/repos/:owner/:name/actions/workflows/:workflow",
885 Op::UpdateWorkflow,
886 &[],
887 ),
888 route(
889 "PUT",
890 "/repos/:owner/:name/actions/workflows/:workflow/enable",
891 Op::UpdateWorkflow,
892 &[],
893 ),
894 route(
895 "PUT",
896 "/repos/:owner/:name/actions/workflows/:workflow/disable",
897 Op::UpdateWorkflow,
898 &[],
899 ),
900 route(
901 "GET",
902 "/repos/:owner/:name/actions/runs",
903 Op::ListWorkflowRuns,
904 &[("workflow", "workflow"), ("branch", "branch"), ("event", "event"), ("pull", "pull"), ("head_sha", "sha"), ("status", "status"), ("since", "since"), ("until", "until"), ("per_page", "limit")],
905 ),
906 route(
907 "GET",
908 "/repos/:owner/:name/actions/runs/:id",
909 Op::GetWorkflowRun,
910 &[],
911 ),
912 route(
913 "GET",
914 "/repos/:owner/:name/actions/runs/:id/attempts/:attempt",
915 Op::GetWorkflowRun,
916 &[],
917 ),
918 route(
919 "POST",
920 "/repos/:owner/:name/actions/runs/:id/cancel",
921 Op::CancelWorkflowRun,
922 &[],
923 ),
924 route(
925 "POST",
926 "/repos/:owner/:name/actions/runs/:id/force-cancel",
927 Op::CancelWorkflowRun,
928 &[],
929 ),
930 route(
931 "POST",
932 "/repos/:owner/:name/actions/runs/:id/rerun",
933 Op::RerunWorkflowRun,
934 &[],
935 ),
936 route(
937 "POST",
938 "/repos/:owner/:name/actions/runs/:id/rerun-failed-jobs",
939 Op::RerunWorkflowRun,
940 &[],
941 ),
942 route(
943 "POST",
944 "/repos/:owner/:name/actions/jobs/:job/rerun",
945 Op::RerunWorkflowRun,
946 &[],
947 ),
948 route(
949 "GET",
950 "/repos/:owner/:name/actions/jobs/:job/logs",
951 Op::GetJobLogs,
952 &[("after", "after"), ("tail", "tail")],
953 ),
954 // Packages, at GitHub's addresses with the workspace in place of the
955 // organization. A name with a slash is one URL-encoded segment.
956 route("GET", "/workspaces/:workspace/packages", Op::Packages(PackagesOp::ListPackages), &[("package_type", "package_type"), ("q", "q"), ("state", "state")]),
957 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name", Op::Packages(PackagesOp::GetPackage), &[]),
958 route("PATCH", "/workspaces/:workspace/packages/:package_type/:package_name", Op::Packages(PackagesOp::UpdatePackage), &[]),
959 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name", Op::Packages(PackagesOp::DeletePackage), &[]),
960 route("POST", "/workspaces/:workspace/packages/:package_type/:package_name/restore", Op::Packages(PackagesOp::RestorePackage), &[]),
961 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/versions", Op::Packages(PackagesOp::ListVersions), &[("state", "state")]),
962 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/versions/:version_id", Op::Packages(PackagesOp::GetVersion), &[]),
963 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/versions/:version_id", Op::Packages(PackagesOp::DeleteVersion), &[]),
964 route("POST", "/workspaces/:workspace/packages/:package_type/:package_name/versions/:version_id/restore", Op::Packages(PackagesOp::RestoreVersion), &[]),
965 route("PUT", "/workspaces/:workspace/packages/:package_type/:package_name/repository", Op::Packages(PackagesOp::LinkPackage), &[]),
966 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/repository", Op::Packages(PackagesOp::UnlinkPackage), &[]),
967 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/access", Op::Packages(PackagesOp::ListAccess), &[]),
968 route("PUT", "/workspaces/:workspace/packages/:package_type/:package_name/access", Op::Packages(PackagesOp::SetAccess), &[]),
969 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/access", Op::Packages(PackagesOp::RemoveAccess), &[("username", "username"), ("team", "team")]),
970 route("GET", "/workspaces/:workspace/packages/:package_type/:package_name/actions-access", Op::Packages(PackagesOp::ListActionsAccess), &[]),
971 route("PUT", "/workspaces/:workspace/packages/:package_type/:package_name/actions-access", Op::Packages(PackagesOp::SetActionsAccess), &[]),
972 route("DELETE", "/workspaces/:workspace/packages/:package_type/:package_name/actions-access/:repository", Op::Packages(PackagesOp::RemoveActionsAccess), &[]),
973 // Artifacts, at GitHub's addresses. `…/zip` answers with a redirect to
974 // a signed link (lib.rs).
975 route("GET", "/repos/:owner/:name/actions/artifacts", Op::Artifacts(ArtifactsOp::ListArtifacts), &[("name", "name"), ("page", "page"), ("per_page", "per_page")]),
976 route("GET", "/repos/:owner/:name/actions/runs/:id/artifacts", Op::Artifacts(ArtifactsOp::ListRunArtifacts), &[("name", "name")]),
977 route("GET", "/repos/:owner/:name/actions/artifacts/:id", Op::Artifacts(ArtifactsOp::GetArtifact), &[]),
978 route("GET", "/repos/:owner/:name/actions/artifacts/:id/zip", Op::Artifacts(ArtifactsOp::DownloadArtifact), &[]),
979 route("DELETE", "/repos/:owner/:name/actions/artifacts/:id", Op::Artifacts(ArtifactsOp::DeleteArtifact), &[]),
980 route("GET", "/repos/:owner/:name/actions/permissions/artifact-and-log-retention", Op::Artifacts(ArtifactsOp::GetArtifactRetention), &[]),
981 route("PUT", "/repos/:owner/:name/actions/permissions/artifact-and-log-retention", Op::Artifacts(ArtifactsOp::SetArtifactRetention), &[]),
982 route(
983 "GET",
984 "/repos/:owner/:name/actions/caches",
985 Op::Caches(CachesOp::ListCaches),
986 &[("key", "key"), ("ref", "ref"), ("sort", "sort"), ("direction", "direction"), ("page", "page"), ("per_page", "per_page")],
987 ),
988 route("GET", "/repos/:owner/:name/actions/cache/usage", Op::Caches(CachesOp::GetCacheUsage), &[]),
989 route("DELETE", "/repos/:owner/:name/actions/caches", Op::Caches(CachesOp::DeleteCachesByKey), &[("key", "key"), ("ref", "ref")]),
990 route("DELETE", "/repos/:owner/:name/actions/caches/:id", Op::Caches(CachesOp::DeleteCache), &[]),
991 route(
992 "GET",
993 "/repos/:owner/:name/actions/secrets",
994 Op::ListActionsSecrets,
995 &[],
996 ),
997 route(
998 "PUT",
999 "/repos/:owner/:name/actions/secrets/:setting",
1000 Op::SetActionsSecret,
1001 &[],
1002 ),
1003 route(
1004 "DELETE",
1005 "/repos/:owner/:name/actions/secrets/:setting",
1006 Op::DeleteActionsSecret,
1007 &[],
1008 ),
1009 route(
1010 "GET",
1011 "/repos/:owner/:name/actions/variables",
1012 Op::ListActionsVariables,
1013 &[],
1014 ),
1015 route(
1016 "POST",
1017 "/repos/:owner/:name/actions/variables",
1018 Op::SetActionsVariable,
1019 &[],
1020 ),
1021 route(
1022 "PATCH",
1023 "/repos/:owner/:name/actions/variables/:setting",
1024 Op::SetActionsVariable,
1025 &[],
1026 ),
1027 route(
1028 "DELETE",
1029 "/repos/:owner/:name/actions/variables/:setting",
1030 Op::DeleteActionsVariable,
1031 &[],
1032 ),
1033 route(
1034 "GET",
1035 "/workspaces/:workspace/actions/secrets",
1036 Op::ListActionsSecrets,
1037 &[],
1038 ),
1039 route(
1040 "PUT",
1041 "/workspaces/:workspace/actions/secrets/:setting",
1042 Op::SetActionsSecret,
1043 &[],
1044 ),
1045 route(
1046 "DELETE",
1047 "/workspaces/:workspace/actions/secrets/:setting",
1048 Op::DeleteActionsSecret,
1049 &[],
1050 ),
1051 route(
1052 "GET",
1053 "/workspaces/:workspace/actions/variables",
1054 Op::ListActionsVariables,
1055 &[],
1056 ),
1057 route(
1058 "POST",
1059 "/workspaces/:workspace/actions/variables",
1060 Op::SetActionsVariable,
1061 &[],
1062 ),
1063 route(
1064 "PATCH",
1065 "/workspaces/:workspace/actions/variables/:setting",
1066 Op::SetActionsVariable,
1067 &[],
1068 ),
1069 route(
1070 "DELETE",
1071 "/workspaces/:workspace/actions/variables/:setting",
1072 Op::DeleteActionsVariable,
1073 &[],
1074 ),
1075 // Self-hosted runners: a repository's own, or a workspace's.
1076 route("GET", "/repos/:owner/:name/actions/runners", Op::ListRunners, &[]),
1077 route("POST", "/repos/:owner/:name/actions/runners/registration-token", Op::CreateRunnerRegistrationToken, &[]),
1078 route("DELETE", "/repos/:owner/:name/actions/runners/:id", Op::RemoveRunner, &[]),
1079 route("GET", "/repos/:owner/:name/actions/runner-settings", Op::GetRunnerSettings, &[]),
1080 route("PATCH", "/repos/:owner/:name/actions/runner-settings", Op::UpdateRunnerSettings, &[]),
1081 route("GET", "/workspaces/:workspace/actions/runners", Op::ListRunners, &[]),
1082 route("POST", "/workspaces/:workspace/actions/runners/registration-token", Op::CreateRunnerRegistrationToken, &[]),
1083 route("DELETE", "/workspaces/:workspace/actions/runners/:id", Op::RemoveRunner, &[]),
1084 route("GET", "/workspaces/:workspace/actions/runner-settings", Op::GetRunnerSettings, &[]),
1085 route("PATCH", "/workspaces/:workspace/actions/runner-settings", Op::UpdateRunnerSettings, &[]),
1086 route("GET", "/workspaces/:workspace/actions/runner-groups", Op::ListRunnerGroups, &[]),
1087 route("POST", "/workspaces/:workspace/actions/runner-groups", Op::CreateRunnerGroup, &[]),
1088 route("PATCH", "/workspaces/:workspace/actions/runner-groups/:id", Op::UpdateRunnerGroup, &[]),
1089 route("DELETE", "/workspaces/:workspace/actions/runner-groups/:id", Op::DeleteRunnerGroup, &[]),
1090 // Comments on pull requests, and reactions to them.
1091 route("POST", "/repos/:owner/:name/pulls/:number/comments", Op::AddComment, &[]),
1092 route("PATCH", "/repos/:owner/:name/pulls/comments/:comment_id", Op::EditComment, &[]),
1093 route("DELETE", "/repos/:owner/:name/pulls/comments/:comment_id", Op::DeleteComment, &[]),
1094 route("POST", "/repos/:owner/:name/pulls/:number/reactions", Op::React, &[]),
1095 // An image to show in a work item's, a pull request's or a comment's Markdown.
1096 route("POST", "/repos/:owner/:name/attachments", Op::UploadAttachment, &[]),
1097 route(
1098 "GET",
1099 "/repos/:owner/:name/pulls",
1100 Op::ListPullRequests,
1101 &[("state", "state"), ("label", "label"), ("milestone", "milestone"), ("base", "base")],
1102 ),
1103 route(
1104 "POST",
1105 "/repos/:owner/:name/pulls",
1106 Op::CreatePullRequest,
1107 &[],
1108 ),
1109 route(
1110 "GET",
1111 "/repos/:owner/:name/pulls/:number",
1112 Op::GetPullRequest,
1113 &[],
1114 ),
1115 route(
1116 "PATCH",
1117 "/repos/:owner/:name/pulls/:number",
1118 Op::UpdatePullRequest,
1119 &[],
1120 ),
1121 route(
1122 "GET",
1123 "/repos/:owner/:name/pulls/:number/changes",
1124 Op::GetPullRequestChanges,
1125 &[("paths", "paths")],
1126 ),
1127 route(
1128 "POST",
1129 "/repos/:owner/:name/pulls/:number/reviews",
1130 Op::ReviewPullRequest,
1131 &[],
1132 ),
1133 route(
1134 "POST",
1135 "/repos/:owner/:name/pulls/:number/requested_reviewers",
1136 Op::RequestReviewers,
1137 &[],
1138 ),
1139 route(
1140 "DELETE",
1141 "/repos/:owner/:name/pulls/:number/requested_reviewers",
1142 Op::RemoveRequestedReviewers,
1143 &[],
1144 ),
1145 route(
1146 "GET",
1147 "/repos/:owner/:name/pulls/:number/session",
1148 Op::ReadSession,
1149 &[("after", "after")],
1150 ),
1151 route(
1152 "POST",
1153 "/repos/:owner/:name/pulls/:number/session",
1154 Op::RecordSession,
1155 &[],
1156 ),
1157 // Decision records on a pull request (a work item's are with it), and
1158 // why a line is the way it is.
1159 route("GET", "/repos/:owner/:name/pulls/:number/decisions", Op::ListDecisions, &[]),
1160 route("POST", "/repos/:owner/:name/pulls/:number/decisions", Op::RecordDecision, &[]),
1161 route("GET", "/repos/:owner/:name/why", Op::Why, &[("path", "path"), ("line", "line"), ("ref", "ref")]),
1162 route(
1163 "POST",
1164 "/repos/:owner/:name/pulls/:number/ready",
1165 Op::MarkPullRequestReady,
1166 &[],
1167 ),
1168 route("POST", "/repos/:owner/:name/pulls/:number/draft", Op::ConvertPullRequestToDraft, &[]),
1169 route(
1170 "POST",
1171 "/repos/:owner/:name/pulls/:number/close",
1172 Op::ClosePullRequest,
1173 &[],
1174 ),
1175 route("POST", "/repos/:owner/:name/pulls/:number/reopen", Op::ReopenPullRequest, &[]),
1176 route(
1177 "POST",
1178 "/repos/:owner/:name/pulls/:number/merge",
1179 Op::MergePullRequest,
1180 &[],
1181 ),
1182 route("GET", "/repos/:owner/:name/pulls/:number/merge-options", Op::GetPullRequestMergeOptions, &[]),
1183 route("PUT", "/repos/:owner/:name/pulls/:number/update-branch", Op::UpdatePullRequestBranch, &[]),
1184 route("PUT", "/repos/:owner/:name/pulls/:number/auto-merge", Op::EnablePullRequestAutoMerge, &[]),
1185 route("DELETE", "/repos/:owner/:name/pulls/:number/auto-merge", Op::DisablePullRequestAutoMerge, &[]),
1186 route("DELETE", "/repos/:owner/:name/pulls/:number/head-branch", Op::DeletePullRequestHeadBranch, &[]),
1187 route("POST", "/repos/:owner/:name/pulls/:number/head-branch/restore", Op::RestorePullRequestHeadBranch, &[]),
1188 // Commit comments: GitHub's addresses.
1189 route("GET", "/repos/:owner/:name/comments", Op::ListRepoCommitComments, &[("page", "page")]),
1190 route("PATCH", "/repos/:owner/:name/comments/:comment_id", Op::UpdateCommitComment, &[]),
1191 route("DELETE", "/repos/:owner/:name/comments/:comment_id", Op::DeleteCommitComment, &[]),
1192 route("GET", "/repos/:owner/:name/commits/:sha/comments", Op::ListCommitComments, &[]),
1193 route("POST", "/repos/:owner/:name/commits/:sha/comments", Op::CreateCommitComment, &[]),
1194 // Artifacts mode's docs, slides, designs and dashboards. Search comes
1195 // before an artifact by id, which it would otherwise match.
1196 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")]),
1197 route("POST", "/workspaces/:workspace/artifacts", Op::Folios(FoliosOp::Create), &[]),
1198 route("GET", "/workspaces/:workspace/artifacts/search", Op::Folios(FoliosOp::Search), &[("q", "q"), ("kind", "kind"), ("space", "space"), ("project", "project"), ("limit", "limit")]),
1199 route("GET", "/workspaces/:workspace/artifacts/:artifact_id", Op::Folios(FoliosOp::Get), &[]),
1200 route("PATCH", "/workspaces/:workspace/artifacts/:artifact_id", Op::Folios(FoliosOp::Update), &[]),
1201 route("DELETE", "/workspaces/:workspace/artifacts/:artifact_id", Op::Folios(FoliosOp::Trash), &[]),
1202 route("POST", "/workspaces/:workspace/artifacts/:artifact_id/restore", Op::Folios(FoliosOp::Restore), &[]),
1203 route("POST", "/workspaces/:workspace/artifacts/:artifact_id/purge", Op::Folios(FoliosOp::Purge), &[]),
1204 route("GET", "/workspaces/:workspace/artifacts/:artifact_id/content", Op::Folios(FoliosOp::GetContent), &[]),
1205 route("PUT", "/workspaces/:workspace/artifacts/:artifact_id/content", Op::Folios(FoliosOp::Edit), &[]),
1206 route("GET", "/workspaces/:workspace/artifacts/:artifact_id/access", Op::Folios(FoliosOp::GetAccess), &[]),
1207 route("PUT", "/workspaces/:workspace/artifacts/:artifact_id/access", Op::Folios(FoliosOp::SetAccess), &[]),
1208 route("GET", "/workspaces/:workspace/artifacts/:artifact_id/versions", Op::Folios(FoliosOp::ListVersions), &[]),
1209 route("POST", "/workspaces/:workspace/artifacts/:artifact_id/versions/:version_id/restore", Op::Folios(FoliosOp::RestoreVersion), &[]),
1210 route("GET", "/workspaces/:workspace/artifact-templates", Op::Folios(FoliosOp::ListTemplates), &[("kind", "kind")]),
1211 route("GET", "/workspaces/:workspace/artifact-spaces", Op::Folios(FoliosOp::ListSpaces), &[]),
1212 route("POST", "/workspaces/:workspace/datasets/query", Op::Folios(FoliosOp::QueryDataset), &[]),
1213];
1214
1215impl Route {
1216 /// Whether the route answers success with `204` and no body, as
1217 /// GitHub's address for the same does. MCP still answers `true`.
1218 pub fn no_content(&self) -> bool {
1219 matches!(
1220 self.op,
1221 Op::DeleteComment | Op::DeleteWorkItemComment | Op::DeleteCommitComment | Op::Caches(CachesOp::DeleteCache)
1222 )
1223 }
1224
1225 /// The names of the route's path parameters, in order.
1226 pub fn params(&self) -> impl Iterator<Item = &'static str> {
1227 self.path
1228 .split('/')
1229 .filter_map(|segment| segment.strip_prefix(':'))
1230 }
1231
1232 /// The values of the path parameters, if `path` is this route's.
1233 fn matches<'a>(&self, path: &'a str) -> Option<Vec<(&'static str, &'a str)>> {
1234 let mut values = Vec::new();
1235 let mut actual = path.trim_end_matches('/').split('/');
1236 for expected in self.path.split('/') {
1237 let segment = actual.next()?;
1238 match expected.strip_prefix(':') {
1239 Some(name) if !segment.is_empty() => values.push((name, segment)),
1240 Some(_) => return None,
1241 None if expected == segment => {}
1242 None => return None,
1243 }
1244 }
1245 actual.next().is_none().then_some(values)
1246 }
1247}
1248
1249/// A path segment with its `%XX` escapes decoded; as given when that is not
1250/// UTF-8.
1251fn percent_decoded(segment: &str) -> String {
1252 let bytes = segment.as_bytes();
1253 let mut out = Vec::with_capacity(bytes.len());
1254 let mut i = 0;
1255 while i < bytes.len() {
1256 let escaped = (bytes[i] == b'%')
1257 .then(|| segment.get(i + 1..i + 3))
1258 .flatten()
1259 .filter(|hex| hex.bytes().all(|byte| byte.is_ascii_hexdigit()))
1260 .and_then(|hex| u8::from_str_radix(hex, 16).ok());
1261 match escaped {
1262 Some(byte) => {
1263 out.push(byte);
1264 i += 3;
1265 }
1266 None => {
1267 out.push(bytes[i]);
1268 i += 1;
1269 }
1270 }
1271 }
1272 String::from_utf8(out).unwrap_or_else(|_| segment.to_owned())
1273}
1274
1275/// The route for a request, and the operation input it describes.
1276///
1277/// The input is the JSON body, overlaid with the query parameters the route
1278/// reads and then with what the path names: `owner` and `name` become
1279/// `repo`, as does a team's `repo` with its `workspace`, and `number`
1280/// becomes an integer.
1281pub fn resolve(
1282 method: &str,
1283 path: &str,
1284 query: &[(String, String)],
1285 body: Value,
1286) -> Option<(&'static Route, Value)> {
1287 let (route, params) = ROUTES
1288 .iter()
1289 .filter(|route| route.method == method)
1290 .find_map(|route| Some((route, route.matches(path)?)))?;
1291
1292 let mut input = match body {
1293 Value::Object(fields) => fields,
1294 _ => Map::new(),
1295 };
1296 for (name, key) in route.query {
1297 if let Some((_, value)) = query.iter().find(|(query_name, _)| query_name == name) {
1298 input.insert((*key).to_owned(), Value::String(value.clone()));
1299 }
1300 }
1301 let param = |wanted: &str| {
1302 params
1303 .iter()
1304 .find(|(name, _)| *name == wanted)
1305 .map(|(_, value)| *value)
1306 };
1307 if let (Some(owner), Some(name)) = (param("owner"), param("name")) {
1308 input.insert("repo".to_owned(), Value::String(format!("{owner}/{name}")));
1309 }
1310 // Every other name the path gives, under that name; the ones below that
1311 // need more (a repository, a number, an encoded name) are set after.
1312 for (key, value) in &params {
1313 if !matches!(*key, "owner" | "name") {
1314 input.insert((*key).to_owned(), Value::String(percent_decoded(value)));
1315 }
1316 }
1317 // A repository of a team's workspace, named by itself.
1318 if let (Some(workspace), Some(name)) = (param("workspace"), param("repo")) {
1319 input.insert("repo".to_owned(), Value::String(format!("{workspace}/{name}")));
1320 }
1321 // A branch name may hold slashes, sent URL-encoded as one segment, and
1322 // a label's name spaces.
1323 if let Some(branch) = param("branch") {
1324 input.insert("branch".to_owned(), Value::String(percent_decoded(branch)));
1325 }
1326 // An environment's name may hold slashes and spaces, URL-encoded.
1327 if let Some(environment) = param("environment") {
1328 input.insert("environment".to_owned(), Value::String(percent_decoded(environment)));
1329 }
1330 if let Some(label) = param("label") {
1331 input.insert("label".to_owned(), Value::String(percent_decoded(label)));
1332 }
1333 if let Some(milestone) = param("milestone") {
1334 // Not a number: zero, which no milestone has.
1335 input.insert("milestone".to_owned(), milestone.parse::<u32>().unwrap_or(0).into());
1336 }
1337 // GitHub says some things with the path alone.
1338 if route.path.ends_with("/enable") || route.path.ends_with("/disable") {
1339 input.insert("enabled".to_owned(), Value::Bool(route.path.ends_with("/enable")));
1340 }
1341 if route.path.ends_with("/rerun-failed-jobs") {
1342 input.insert("failed_only".to_owned(), Value::Bool(true));
1343 }
1344 if route.path.ends_with("/force-cancel") {
1345 input.insert("force".to_owned(), Value::Bool(true));
1346 }
1347 // Unsaving and waking a thread are a DELETE of what PUT made.
1348 if route.method == "DELETE" && route.path.ends_with("/saved") {
1349 input.insert("saved".to_owned(), Value::Bool(false));
1350 }
1351 if route.method == "DELETE" && route.path.ends_with("/snooze") {
1352 input.remove("until");
1353 }
1354 if let Some(number) = param("number") {
1355 // Not a number: zero, which no work item or pull request has.
1356 input.insert(
1357 "number".to_owned(),
1358 number.parse::<u32>().unwrap_or(0).into(),
1359 );
1360 }
1361 Some((route, Value::Object(input)))
1362}
1363
1364#[cfg(test)]
1365mod tests {
1366 use serde_json::json;
1367
1368 use super::*;
1369
1370 /// Every name a route's path gives reaches the operation: a name left
1371 /// off the lists above is dropped, and the operation answers that it
1372 /// was not given (the project routes were, until this test).
1373 #[test]
1374 fn every_path_parameter_reaches_the_input() {
1375 for route in ROUTES.iter() {
1376 let names: Vec<&str> = route.path.split('/').filter_map(|part| part.strip_prefix(':')).collect();
1377 if names.is_empty() {
1378 continue;
1379 }
1380 let path: String = route
1381 .path
1382 .split('/')
1383 .map(|part| match part.strip_prefix(':') {
1384 Some("number" | "milestone") => "7".to_owned(),
1385 Some(name) => format!("{name}-x"),
1386 None => part.to_owned(),
1387 })
1388 .collect::<Vec<_>>()
1389 .join("/");
1390 let (found, input) = resolve(route.method, &path, &[], json!({})).unwrap();
1391 // A path two routes could take is checked under the first.
1392 if found.path != route.path {
1393 continue;
1394 }
1395 for name in names {
1396 let key = match name {
1397 "owner" | "name" => "repo",
1398 "repo" if names_has_workspace(route.path) => "repo",
1399 other => other,
1400 };
1401 assert!(
1402 input.get(key).is_some_and(|value| !value.is_null()),
1403 "{} {}: :{name} does not reach the input",
1404 route.method,
1405 route.path
1406 );
1407 }
1408 }
1409 }
1410
1411 fn names_has_workspace(path: &str) -> bool {
1412 path.split('/').any(|part| part == ":workspace")
1413 }
1414
1415 #[test]
1416 fn a_path_resolves_to_its_operation_and_input() {
1417 let (route, input) = resolve(
1418 "POST",
1419 "/repos/flagon-io/hello/pulls/14/merge",
1420 &[],
1421 json!({ "keep_item_open": true, "number": 99, "repo": "someone/else" }),
1422 )
1423 .unwrap();
1424 assert_eq!(route.op, Op::MergePullRequest);
1425 // What the path names wins over the body.
1426 assert_eq!(
1427 input,
1428 json!({ "keep_item_open": true, "number": 14, "repo": "flagon-io/hello" })
1429 );
1430 }
1431
1432 #[test]
1433 fn a_branch_with_slashes_is_one_encoded_segment() {
1434 let (route, input) = resolve(
1435 "POST",
1436 "/repos/flagon-io/hello/branches/feature%2Flogin/rename",
1437 &[],
1438 json!({ "new_name": "feature/sign-in" }),
1439 )
1440 .unwrap();
1441 assert_eq!(route.op, Op::RenameBranch);
1442 assert_eq!(
1443 input,
1444 json!({ "new_name": "feature/sign-in", "branch": "feature/login", "repo": "flagon-io/hello" })
1445 );
1446 assert_eq!(percent_decoded("100%"), "100%");
1447 assert_eq!(percent_decoded("a%2bb%zz"), "a+b%zz");
1448 }
1449
1450 #[test]
1451 fn a_collaborator_is_named_by_username() {
1452 let (route, input) = resolve(
1453 "PATCH",
1454 "/repos/flagon-io/hello/collaborators/ada",
1455 &[],
1456 json!({ "role": "maintain" }),
1457 )
1458 .unwrap();
1459 assert_eq!(route.op, Op::UpdateCollaborator);
1460 assert_eq!(input, json!({ "role": "maintain", "username": "ada", "repo": "flagon-io/hello" }));
1461 let (route, input) = resolve("DELETE", "/user/repository_invitations/rin_1", &[], Value::Null).unwrap();
1462 assert_eq!(route.op, Op::DeclineRepoInvitation);
1463 assert_eq!(input, json!({ "id": "rin_1" }));
1464 }
1465
1466 #[test]
1467 fn teams_are_addressed_by_workspace_and_slug() {
1468 let query = [("q".to_owned(), "back".to_owned())];
1469 let (route, input) = resolve("GET", "/workspaces/acme/teams", &query, Value::Null).unwrap();
1470 assert_eq!(route.op, Op::ListTeams);
1471 assert_eq!(input, json!({ "query": "back", "workspace": "acme" }));
1472 let (route, input) = resolve("PATCH", "/workspaces/acme/teams/backend", &[], json!({ "name": "Back end" })).unwrap();
1473 assert_eq!(route.op, Op::UpdateTeam);
1474 assert_eq!(input, json!({ "name": "Back end", "workspace": "acme", "team": "backend" }));
1475 let (route, input) =
1476 resolve("PUT", "/workspaces/acme/teams/backend/members/ana", &[], json!({ "role": "maintainer" })).unwrap();
1477 assert_eq!(route.op, Op::SetTeamMember);
1478 assert_eq!(input, json!({ "role": "maintainer", "workspace": "acme", "team": "backend", "username": "ana" }));
1479 let query = [("include_child_teams".to_owned(), "true".to_owned())];
1480 let (route, input) = resolve("GET", "/workspaces/acme/teams/backend/members", &query, Value::Null).unwrap();
1481 assert_eq!(route.op, Op::ListTeamMembers);
1482 assert_eq!(input, json!({ "include_child_teams": "true", "workspace": "acme", "team": "backend" }));
1483 // A repository is named by itself, in the team's workspace.
1484 let (route, input) =
1485 resolve("PUT", "/workspaces/acme/teams/backend/repos/rocket", &[], json!({ "role": "write" })).unwrap();
1486 assert_eq!(route.op, Op::SetTeamRepo);
1487 assert_eq!(input, json!({ "role": "write", "workspace": "acme", "team": "backend", "repo": "acme/rocket" }));
1488 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1489 assert_eq!(op("DELETE", "/workspaces/acme/teams/backend/repos/rocket"), Op::RemoveTeamRepo);
1490 assert_eq!(op("GET", "/workspaces/acme/teams/backend/teams"), Op::ListChildTeams);
1491 assert_eq!(op("GET", "/workspaces/acme/teams/backend/repos"), Op::ListTeamRepos);
1492 assert_eq!(op("PUT", "/workspaces/acme/teams/backend/review_assignment"), Op::SetTeamReviewAssignment);
1493 assert_eq!(op("DELETE", "/workspaces/acme/teams/backend"), Op::DeleteTeam);
1494 assert_eq!(op("POST", "/workspaces/acme/teams"), Op::CreateTeam);
1495 assert_eq!(op("GET", "/workspaces/acme/teams/backend"), Op::GetTeam);
1496 assert_eq!(op("DELETE", "/workspaces/acme/teams/backend/members/ana"), Op::RemoveTeamMember);
1497 let (route, input) = resolve("GET", "/workspaces/acme/members/ana/teams", &[], Value::Null).unwrap();
1498 assert_eq!(route.op, Op::ListUserTeams);
1499 assert_eq!(input, json!({ "workspace": "acme", "username": "ana" }));
1500 }
1501
1502 #[test]
1503 fn reviewers_are_requested_and_code_owners_checked_on_a_repository() {
1504 let body = json!({ "reviewers": ["ana"], "team_reviewers": ["backend"] });
1505 let (route, input) = resolve("POST", "/repos/acme/rocket/pulls/7/requested_reviewers", &[], body.clone()).unwrap();
1506 assert_eq!(route.op, Op::RequestReviewers);
1507 assert_eq!(
1508 input,
1509 json!({ "reviewers": ["ana"], "team_reviewers": ["backend"], "repo": "acme/rocket", "number": 7 })
1510 );
1511 let (route, _) = resolve("DELETE", "/repos/acme/rocket/pulls/7/requested_reviewers", &[], body).unwrap();
1512 assert_eq!(route.op, Op::RemoveRequestedReviewers);
1513 let query = [("ref".to_owned(), "main".to_owned())];
1514 let (route, input) = resolve("GET", "/repos/acme/rocket/codeowners/errors", &query, Value::Null).unwrap();
1515 assert_eq!(route.op, Op::GetCodeownersErrors);
1516 assert_eq!(input, json!({ "ref": "main", "repo": "acme/rocket" }));
1517 }
1518
1519 #[test]
1520 fn events_are_followed_with_a_cursor_filters_and_a_wait() {
1521 let query = [
1522 ("after".to_owned(), "evt_1".to_owned()),
1523 ("types".to_owned(), "work.claimed,integration.failed".to_owned()),
1524 ("numbers".to_owned(), "12,14".to_owned()),
1525 ("wait".to_owned(), "25".to_owned()),
1526 ("limit".to_owned(), "20".to_owned()),
1527 ("since".to_owned(), "2026-10-12T00:00:00Z".to_owned()),
1528 ];
1529 let (route, input) = resolve("GET", "/repos/acme/rocket/events", &query, Value::Null).unwrap();
1530 assert_eq!(route.op, Op::ListEvents);
1531 let asked = crate::follow::asked(&input).unwrap();
1532 assert_eq!(asked.after.as_deref(), Some("evt_1"));
1533 assert_eq!(asked.types, vec!["integration.failed", "work.claimed"]);
1534 assert_eq!(asked.numbers, vec![12, 14]);
1535 assert_eq!(asked.wait_ms, 25_000);
1536 assert_eq!(asked.limit, Some(20));
1537 assert_eq!(asked.since.as_deref(), Some("2026-10-12T00:00:00Z"));
1538 }
1539
1540 #[test]
1541 fn notifications_are_addressed_as_threads_and_by_number() {
1542 let (route, input) = resolve("DELETE", "/notifications/threads/ntf_1", &[], Value::Null).unwrap();
1543 assert_eq!(route.op, Op::MarkThreadDone);
1544 assert_eq!(input, json!({ "id": "ntf_1" }));
1545 let (route, input) = resolve("DELETE", "/notifications/threads/ntf_1/saved", &[], Value::Null).unwrap();
1546 assert_eq!(route.op, Op::SaveThread);
1547 assert_eq!(input, json!({ "id": "ntf_1", "saved": false }));
1548 let (route, input) = resolve("DELETE", "/notifications/threads/ntf_1/snooze", &[], json!({ "until": "x" })).unwrap();
1549 assert_eq!(route.op, Op::SnoozeThread);
1550 assert_eq!(input, json!({ "id": "ntf_1" }));
1551 let query = [("all".to_owned(), "true".to_owned()), ("per_page".to_owned(), "50".to_owned())];
1552 let (route, input) = resolve("GET", "/repos/acme/rocket/notifications", &query, Value::Null).unwrap();
1553 assert_eq!(route.op, Op::ListNotifications);
1554 assert_eq!(input, json!({ "all": "true", "per_page": "50", "repo": "acme/rocket" }));
1555 let (route, input) = resolve("PUT", "/workspaces/acme/work/7/subscription", &[], json!({ "ignored": true })).unwrap();
1556 assert_eq!(route.op, Op::SetThreadSubscription);
1557 assert_eq!(input, json!({ "ignored": true, "number": 7, "workspace": "acme" }));
1558 let (route, input) = resolve("PUT", "/repos/acme/rocket/pulls/7/subscription", &[], json!({ "ignored": true })).unwrap();
1559 assert_eq!(route.op, Op::SetThreadSubscription);
1560 assert_eq!(input, json!({ "ignored": true, "number": 7, "repo": "acme/rocket" }));
1561 assert_eq!(resolve("GET", "/user/subscriptions", &[], Value::Null).unwrap().0.op, Op::ListWatchedRepos);
1562 }
1563
1564 #[test]
1565 fn labels_and_milestones_are_named_in_the_path() {
1566 let (route, input) = resolve("PATCH", "/workspaces/acme/labels/good%20first%20issue", &[], json!({ "color": "7057ff" })).unwrap();
1567 assert_eq!(route.op, Op::UpdateLabel);
1568 assert_eq!(input, json!({ "color": "7057ff", "label": "good first issue", "workspace": "acme" }));
1569 let (route, input) = resolve("DELETE", "/workspaces/acme/work/7/labels/bug", &[], Value::Null).unwrap();
1570 assert_eq!(route.op, Op::RemoveWorkItemLabels);
1571 assert_eq!(input, json!({ "label": "bug", "number": 7, "workspace": "acme" }));
1572 let (route, input) = resolve("DELETE", "/workspaces/acme/work/7/labels", &[], Value::Null).unwrap();
1573 assert_eq!(route.op, Op::RemoveWorkItemLabels);
1574 assert_eq!(input, json!({ "number": 7, "workspace": "acme" }));
1575 let (route, _) = resolve("POST", "/workspaces/acme/labels/defaults", &[], Value::Null).unwrap();
1576 assert_eq!(route.op, Op::AddDefaultLabels);
1577 let (route, input) = resolve("PATCH", "/workspaces/acme/milestones/3", &[], json!({ "state": "closed" })).unwrap();
1578 assert_eq!(route.op, Op::UpdateMilestone);
1579 assert_eq!(input, json!({ "state": "closed", "milestone": 3, "workspace": "acme" }));
1580 // A repository's labels and milestones are its workspace's now.
1581 assert!(resolve("GET", "/repos/acme/web/labels", &[], Value::Null).is_none());
1582 assert!(resolve("GET", "/repos/acme/web/milestones", &[], Value::Null).is_none());
1583 let (route, input) = resolve("PATCH", "/repos/acme/web/pulls/9", &[], json!({ "base": "release" })).unwrap();
1584 assert_eq!(route.op, Op::UpdatePullRequest);
1585 assert_eq!(input, json!({ "base": "release", "number": 9, "repo": "acme/web" }));
1586 }
1587
1588 #[test]
1589 fn merging_settings_and_commit_comments_have_their_addresses() {
1590 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1591 assert_eq!(op("GET", "/repos/acme/web/pulls/9/merge-options"), Op::GetPullRequestMergeOptions);
1592 assert_eq!(op("PUT", "/repos/acme/web/pulls/9/update-branch"), Op::UpdatePullRequestBranch);
1593 assert_eq!(op("PUT", "/repos/acme/web/pulls/9/auto-merge"), Op::EnablePullRequestAutoMerge);
1594 assert_eq!(op("DELETE", "/repos/acme/web/pulls/9/auto-merge"), Op::DisablePullRequestAutoMerge);
1595 assert_eq!(op("DELETE", "/repos/acme/web/pulls/9/head-branch"), Op::DeletePullRequestHeadBranch);
1596 assert_eq!(op("POST", "/repos/acme/web/pulls/9/head-branch/restore"), Op::RestorePullRequestHeadBranch);
1597 let (route, input) = resolve("GET", "/repos/acme/web/comments", &[("page".to_owned(), "2".to_owned())], Value::Null).unwrap();
1598 assert_eq!(route.op, Op::ListRepoCommitComments);
1599 assert_eq!(input, json!({ "page": "2", "repo": "acme/web" }));
1600 let (route, input) =
1601 resolve("POST", "/repos/acme/web/commits/9f2c4e1/comments", &[], json!({ "body": "Why?", "path": "a.rs", "line": 3 })).unwrap();
1602 assert_eq!(route.op, Op::CreateCommitComment);
1603 assert_eq!(input, json!({ "body": "Why?", "path": "a.rs", "line": 3, "sha": "9f2c4e1", "repo": "acme/web" }));
1604 assert_eq!(op("GET", "/repos/acme/web/commits/9f2c4e1/comments"), Op::ListCommitComments);
1605 // Still a commit's statuses, beside its comments.
1606 assert_eq!(op("GET", "/repos/acme/web/commits/main/statuses"), Op::Checks(ChecksOp::ListCommitStatuses));
1607 let (route, input) = resolve("PATCH", "/repos/acme/web/comments/cc_1", &[], json!({ "body": "Better" })).unwrap();
1608 assert_eq!(route.op, Op::UpdateCommitComment);
1609 assert_eq!(input, json!({ "body": "Better", "comment_id": "cc_1", "repo": "acme/web" }));
1610 let (route, _) = resolve("DELETE", "/repos/acme/web/comments/cc_1", &[], Value::Null).unwrap();
1611 assert!(route.op == Op::DeleteCommitComment && route.no_content());
1612 // A pull request's comments keep theirs.
1613 assert_eq!(op("PATCH", "/repos/acme/web/pulls/comments/cmt_1"), Op::EditComment);
1614 }
1615
1616 #[test]
1617 fn pull_requests_reopen_and_turn_draft_and_comments_are_named_by_id() {
1618 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1619 assert_eq!(op("POST", "/repos/acme/web/pulls/9/reopen"), Op::ReopenPullRequest);
1620 assert_eq!(op("POST", "/repos/acme/web/pulls/9/draft"), Op::ConvertPullRequestToDraft);
1621 assert_eq!(op("POST", "/repos/acme/web/pulls/9/close"), Op::ClosePullRequest);
1622 // Reopening and closing with a PATCH, as `state`.
1623 let (route, input) = resolve("PATCH", "/repos/acme/web/pulls/9", &[], json!({ "state": "open" })).unwrap();
1624 assert_eq!(route.op, Op::UpdatePullRequest);
1625 assert_eq!(input, json!({ "state": "open", "number": 9, "repo": "acme/web" }));
1626 let (route, input) =
1627 resolve("PATCH", "/repos/acme/web/pulls/comments/cmt_1", &[], json!({ "body": "Better" })).unwrap();
1628 assert_eq!(route.op, Op::EditComment);
1629 assert_eq!(input, json!({ "body": "Better", "comment_id": "cmt_1", "repo": "acme/web" }));
1630 let (route, input) = resolve("DELETE", "/repos/acme/web/pulls/comments/cmt_1", &[], Value::Null).unwrap();
1631 assert_eq!(route.op, Op::DeleteComment);
1632 assert_eq!(input, json!({ "comment_id": "cmt_1", "repo": "acme/web" }));
1633 assert_eq!(op("POST", "/repos/acme/web/pulls/7/comments"), Op::AddComment);
1634 assert_eq!(op("POST", "/repos/acme/web/pulls/7/reactions"), Op::React);
1635 assert_eq!(op("POST", "/repos/acme/web/attachments"), Op::UploadAttachment);
1636 assert_eq!(op("DELETE", "/repos/acme/web/pulls/7/subscription"), Op::DeleteThreadSubscription);
1637 // A work item's are in its workspace.
1638 let (route, input) =
1639 resolve("PATCH", "/workspaces/acme/work/comments/cmt_1", &[], json!({ "body": "Better" })).unwrap();
1640 assert_eq!(route.op, Op::EditWorkItemComment);
1641 assert_eq!(input, json!({ "body": "Better", "comment_id": "cmt_1", "workspace": "acme" }));
1642 assert_eq!(op("DELETE", "/workspaces/acme/work/comments/cmt_1"), Op::DeleteWorkItemComment);
1643 assert_eq!(op("POST", "/workspaces/acme/work/7/comments"), Op::AddWorkItemComment);
1644 assert_eq!(op("POST", "/workspaces/acme/work/7/reactions"), Op::ReactToWorkItem);
1645 assert_eq!(op("DELETE", "/workspaces/acme/work/7/subscription"), Op::DeleteThreadSubscription);
1646 }
1647
1648 #[test]
1649 fn work_items_are_addressed_by_workspace_and_number() {
1650 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1651 let query = [("state".to_owned(), "open".to_owned()), ("repo".to_owned(), "acme/web".to_owned()), ("role".to_owned(), "target".to_owned())];
1652 let (route, input) = resolve("GET", "/workspaces/acme/work", &query, Value::Null).unwrap();
1653 assert_eq!(route.op, Op::ListWorkItems);
1654 assert_eq!(input, json!({ "state": "open", "repo": "acme/web", "role": "target", "workspace": "acme" }));
1655 assert_eq!(op("POST", "/workspaces/acme/work"), Op::OpenWorkItem);
1656 assert_eq!(op("POST", "/workspaces/acme/work/import"), Op::ImportWorkItems);
1657 let (route, input) = resolve("GET", "/workspaces/acme/work/12", &[], Value::Null).unwrap();
1658 assert_eq!(route.op, Op::GetWorkItem);
1659 assert_eq!(input, json!({ "number": 12, "workspace": "acme" }));
1660 assert_eq!(op("PATCH", "/workspaces/acme/work/12"), Op::UpdateWorkItem);
1661 assert_eq!(op("POST", "/workspaces/acme/work/12/close"), Op::CloseWorkItem);
1662 assert_eq!(op("POST", "/workspaces/acme/work/12/reopen"), Op::ReopenWorkItem);
1663 assert_eq!(op("POST", "/workspaces/acme/work/12/plan"), Op::PlanWorkItem);
1664 assert_eq!(op("GET", "/workspaces/acme/plan"), Op::GetPlan);
1665 assert_eq!(op("PATCH", "/workspaces/acme/plan"), Op::ConfigurePlan);
1666 assert_eq!(op("GET", "/workspaces/acme/plan/next"), Op::NextWorkItem);
1667 assert_eq!(op("GET", "/workspaces/acme/work/12/links"), Op::ListWorkItemLinks);
1668 assert_eq!(op("POST", "/workspaces/acme/work/12/links"), Op::LinkWorkItem);
1669 let (route, input) = resolve("DELETE", "/workspaces/acme/work/12/links", &[("repo".to_owned(), "acme/api".to_owned())], Value::Null).unwrap();
1670 assert_eq!(route.op, Op::UnlinkWorkItem);
1671 assert_eq!(input, json!({ "repo": "acme/api", "number": 12, "workspace": "acme" }));
1672 assert_eq!(op("GET", "/workspaces/acme/work/12/decisions"), Op::ListWorkItemDecisions);
1673 assert_eq!(op("GET", "/repos/acme/web/work"), Op::ListRepoWorkItems);
1674 let (route, input) = resolve("GET", "/repos/acme/web/refs/7", &[], Value::Null).unwrap();
1675 assert_eq!(route.op, Op::ResolveRef);
1676 assert_eq!(input, json!({ "number": 7, "repo": "acme/web" }));
1677 assert_eq!(op("GET", "/workspaces/acme/refs/7"), Op::ResolveRef);
1678 // The repository's issues are gone, with no aliases.
1679 for path in ["/repos/acme/web/issues", "/repos/acme/web/issues/7", "/repos/acme/web/issues/7/comments"] {
1680 assert!(resolve("GET", path, &[], Value::Null).is_none(), "{path}");
1681 }
1682 }
1683
1684 #[test]
1685 fn observability_is_addressed_by_workspace_and_project() {
1686 let query = [("level".to_owned(), "error,warn".to_owned()), ("q".to_owned(), "timeout".to_owned())];
1687 let (route, input) = resolve("GET", "/workspaces/acme/projects/web/observability/logs", &query, Value::Null).unwrap();
1688 assert_eq!(route.op, Op::Telemetry(TelemetryOp::ListLogs));
1689 assert_eq!(input, json!({ "level": "error,warn", "q": "timeout", "workspace": "acme", "project": "web" }));
1690 let (route, input) =
1691 resolve("GET", "/workspaces/acme/projects/web/observability/metrics/http.server.request.duration", &[], Value::Null).unwrap();
1692 assert_eq!(route.op, Op::Telemetry(TelemetryOp::GetMetric));
1693 assert_eq!(input["metric"], json!("http.server.request.duration"));
1694 let (route, input) =
1695 resolve("PATCH", "/workspaces/acme/projects/web/observability/errors/f00d", &[], json!({ "state": "resolved" })).unwrap();
1696 assert_eq!(route.op, Op::Telemetry(TelemetryOp::UpdateError));
1697 assert_eq!(input, json!({ "state": "resolved", "workspace": "acme", "project": "web", "fingerprint": "f00d" }));
1698 }
1699
1700 #[test]
1701 fn billing_is_addressed_by_workspace() {
1702 let query = [("from".to_owned(), "2026-10-01".to_owned()), ("products".to_owned(), "agent,sandboxes".to_owned())];
1703 let (route, input) = resolve("GET", "/workspaces/acme/usage", &query, Value::Null).unwrap();
1704 assert_eq!(route.op, Op::GetUsage);
1705 assert_eq!(input, json!({ "from": "2026-10-01", "products": "agent,sandboxes", "workspace": "acme" }));
1706 let (route, input) = resolve("PUT", "/workspaces/acme/budget", &[], json!({ "alerts": [50] })).unwrap();
1707 assert_eq!(route.op, Op::SetBudget);
1708 assert_eq!(input, json!({ "alerts": [50], "workspace": "acme" }));
1709 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1710 assert_eq!(op("GET", "/workspaces/acme/budget"), Op::GetBudget);
1711 assert_eq!(op("GET", "/workspaces/acme/invoices"), Op::ListInvoices);
1712 assert_eq!(op("GET", "/workspaces/acme/billing_details"), Op::GetBillingDetails);
1713 }
1714
1715 #[test]
1716 fn checks_are_at_githubs_addresses() {
1717 let sha = "a".repeat(40);
1718 let body = json!({ "state": "success", "context": "ci/build" });
1719 let (route, input) = resolve("POST", &format!("/repos/acme/web/statuses/{sha}"), &[], body).unwrap();
1720 assert_eq!(route.op, Op::Checks(ChecksOp::CreateCommitStatus));
1721 assert_eq!(input, json!({ "state": "success", "context": "ci/build", "sha": sha, "repo": "acme/web" }));
1722 let (route, input) = resolve("GET", "/repos/acme/web/commits/release%2F1.x/status", &[], Value::Null).unwrap();
1723 assert_eq!(route.op, Op::Checks(ChecksOp::GetCombinedStatus));
1724 assert_eq!(input, json!({ "ref": "release/1.x", "repo": "acme/web" }));
1725 let query = [("check_name".to_owned(), "lint".to_owned())];
1726 let (route, input) = resolve("GET", "/repos/acme/web/commits/main/check-runs", &query, Value::Null).unwrap();
1727 assert_eq!(route.op, Op::Checks(ChecksOp::ListCheckRunsForRef));
1728 assert_eq!(input, json!({ "check_name": "lint", "ref": "main", "repo": "acme/web" }));
1729 let (route, input) = resolve("PATCH", "/repos/acme/web/check-runs/cr_1", &[], json!({ "conclusion": "success" })).unwrap();
1730 assert_eq!(route.op, Op::Checks(ChecksOp::UpdateCheckRun));
1731 assert_eq!(input, json!({ "conclusion": "success", "id": "cr_1", "repo": "acme/web" }));
1732 let op = |method: &str, path: &str| resolve(method, path, &[], Value::Null).unwrap().0.op;
1733 assert_eq!(op("POST", "/repos/acme/web/check-runs"), Op::Checks(ChecksOp::CreateCheckRun));
1734 assert_eq!(op("GET", "/repos/acme/web/check-runs/cr_1/annotations"), Op::Checks(ChecksOp::ListCheckRunAnnotations));
1735 assert_eq!(op("POST", "/repos/acme/web/check-suites/cs_1/rerequest"), Op::Checks(ChecksOp::RerequestCheckSuite));
1736 assert_eq!(op("GET", "/repos/acme/web/commits/main/check-suites"), Op::Checks(ChecksOp::ListCheckSuitesForRef));
1737 }
1738
1739 #[test]
1740 fn archives_are_at_githubs_addresses_and_redirect() {
1741 let sha = "4807077b296e6edbf410d55e72749d3e1170c291";
1742 let (route, input) = resolve("GET", &format!("/repos/acme/web/tarball/{sha}"), &[], Value::Null).unwrap();
1743 assert_eq!(route.op, Op::Archives(ArchiveOp::DownloadTarball));
1744 assert_eq!(input, json!({ "ref": sha, "repo": "acme/web" }));
1745 // A branch with slashes, URL-encoded as octokit sends it.
1746 let (route, input) = resolve("GET", "/repos/acme/web/zipball/release%2F1.x", &[], Value::Null).unwrap();
1747 assert_eq!(route.op, Op::Archives(ArchiveOp::DownloadZipball));
1748 assert_eq!(input, json!({ "ref": "release/1.x", "repo": "acme/web" }));
1749 // Both answer with a redirect to their link, as the artifact download does.
1750 assert!(route.op.redirects());
1751 assert!(Op::Archives(ArchiveOp::DownloadTarball).redirects());
1752 assert!(Op::Artifacts(ArtifactsOp::DownloadArtifact).redirects());
1753 assert!(!Op::GetRepo.redirects());
1754 // Anyone may ask for a public repository's.
1755 assert!(!route.op.needs_user());
1756 }
1757
1758 #[test]
1759 fn caches_are_at_githubs_addresses() {
1760 let query = [("key".to_owned(), "cargo-".to_owned()), ("ref".to_owned(), "refs/heads/main".to_owned()), ("sort".to_owned(), "size_in_bytes".to_owned())];
1761 let (route, input) = resolve("GET", "/repos/acme/web/actions/caches", &query, Value::Null).unwrap();
1762 assert_eq!(route.op, Op::Caches(CachesOp::ListCaches));
1763 assert_eq!(input, json!({ "key": "cargo-", "ref": "refs/heads/main", "sort": "size_in_bytes", "repo": "acme/web" }));
1764 let (route, _) = resolve("GET", "/repos/acme/web/actions/cache/usage", &[], Value::Null).unwrap();
1765 assert_eq!(route.op, Op::Caches(CachesOp::GetCacheUsage));
1766 // Deleting by key takes it from the query, as GitHub's does.
1767 let query = [("key".to_owned(), "npm-full-Linux-abc".to_owned())];
1768 let (route, input) = resolve("DELETE", "/repos/acme/web/actions/caches", &query, Value::Null).unwrap();
1769 assert_eq!(route.op, Op::Caches(CachesOp::DeleteCachesByKey));
1770 assert_eq!(input, json!({ "key": "npm-full-Linux-abc", "repo": "acme/web" }));
1771 assert!(!route.no_content());
1772 let (route, input) = resolve("DELETE", "/repos/acme/web/actions/caches/42", &[], Value::Null).unwrap();
1773 assert_eq!(route.op, Op::Caches(CachesOp::DeleteCache));
1774 assert_eq!(input, json!({ "id": "42", "repo": "acme/web" }));
1775 assert!(route.no_content());
1776 // Only someone signed in sees a repository's cache keys.
1777 assert!(Op::Caches(CachesOp::ListCaches).needs_user());
1778 }
1779
1780 #[test]
1781 fn query_parameters_are_renamed() {
1782 let query = [
1783 ("q".to_owned(), "parser".to_owned()),
1784 ("x".to_owned(), "y".to_owned()),
1785 ];
1786 let (route, input) = resolve("GET", "/repos", &query, Value::Null).unwrap();
1787 assert_eq!(route.op, Op::ListRepos);
1788 assert_eq!(input, json!({ "query": "parser" }));
1789 }
1790
1791 #[test]
1792 fn method_and_shape_must_match() {
1793 assert!(resolve("GET", "/workspaces/a/work/1/close", &[], Value::Null).is_none());
1794 assert!(resolve("GET", "/repos/a", &[], Value::Null).is_none());
1795 assert!(resolve("GET", "/workspaces/a/work/1/extra", &[], Value::Null).is_none());
1796 assert!(resolve("GET", "/repos/a/b/", &[], Value::Null).is_some());
1797 }
1798
1799 #[test]
1800 fn every_parameter_and_query_name_is_an_input() {
1801 for route in ROUTES {
1802 let properties = route.op.properties();
1803 for (_, key) in route.query {
1804 assert!(properties.contains_key(*key), "{}: {key}", route.path);
1805 }
1806 for name in route.params() {
1807 let covered = matches!(name, "owner" | "name") && properties.contains_key("repo")
1808 || properties.contains_key(name);
1809 assert!(covered, "{}: {name}", route.path);
1810 }
1811 }
1812 }
1813
1814 #[test]
1815 fn every_operation_has_a_route() {
1816 for op in Op::ALL {
1817 assert!(ROUTES.iter().any(|route| route.op == op), "{}", op.name());
1818 }
1819 }
1820}