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