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