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