Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

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