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