Skip to main content

ephemeris_forge_github/api/model/actions/
routes.rs

1use ephemeris_forge::encode;
2use facet::Facet;
3
4use super::{
5    AccessResponse, AllowListResponse, ContributorApprovalResponse, ForkWorkflowsResponse,
6    OidcSubjectResponse, PermissionsResponse, RetentionResponse, WorkflowResponse,
7};
8use crate::api::request::PermissionsBody;
9use crate::config::actions::{
10    Access, AllowList, ArtifactAndLogRetention, ForkPrContributorApproval,
11    ForkPrWorkflowsPrivateRepos, OidcSubject, Permissions, Workflow,
12};
13use crate::operation::actions::GroupType;
14
15/// An Actions settings group that has its own route.
16///
17/// The group is read as its wire type and written as itself.
18pub trait ActionsGroup: GroupType + for<'a> Facet<'a> + Send + Sync {
19    /// The route below the repository.
20    const ROUTE: &'static str;
21
22    /// The status that reads as an unavailable group.
23    const UNAVAILABLE_STATUS: Option<u16> = None;
24
25    /// What GitHub answers with.
26    type Wire: for<'a> Facet<'a> + Into<Self>;
27
28    /// The body of a write.
29    fn body(&self) -> String {
30        encode(self)
31    }
32}
33
34impl ActionsGroup for Permissions {
35    const ROUTE: &'static str = "actions/permissions";
36
37    type Wire = PermissionsResponse;
38
39    fn body(&self) -> String {
40        encode(&PermissionsBody {
41            enabled: self.enabled,
42            allowed_actions: self.enabled.then_some(self.allowed_actions),
43            sha_pinning_required: self.sha_pinning_required,
44        })
45    }
46}
47
48impl ActionsGroup for AllowList {
49    const ROUTE: &'static str = "actions/permissions/selected-actions";
50    // Actions is disabled or the allowed-actions policy is not "selected".
51    const UNAVAILABLE_STATUS: Option<u16> = Some(409);
52
53    type Wire = AllowListResponse;
54}
55
56impl ActionsGroup for Workflow {
57    const ROUTE: &'static str = "actions/permissions/workflow";
58
59    type Wire = WorkflowResponse;
60}
61
62impl ActionsGroup for Access {
63    const ROUTE: &'static str = "actions/permissions/access";
64
65    type Wire = AccessResponse;
66}
67
68impl ActionsGroup for ArtifactAndLogRetention {
69    const ROUTE: &'static str = "actions/permissions/artifact-and-log-retention";
70
71    type Wire = RetentionResponse;
72}
73
74impl ActionsGroup for ForkPrContributorApproval {
75    const ROUTE: &'static str = "actions/permissions/fork-pr-contributor-approval";
76
77    type Wire = ContributorApprovalResponse;
78}
79
80impl ActionsGroup for ForkPrWorkflowsPrivateRepos {
81    const ROUTE: &'static str = "actions/permissions/fork-pr-workflows-private-repos";
82    // The setting exists only for private repositories.
83    const UNAVAILABLE_STATUS: Option<u16> = Some(422);
84
85    type Wire = ForkWorkflowsResponse;
86}
87
88impl ActionsGroup for OidcSubject {
89    const ROUTE: &'static str = "actions/oidc/customization/sub";
90
91    type Wire = OidcSubjectResponse;
92}