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