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