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.

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