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