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