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