octocrab 0.54.2

A modern, extensible GitHub API client.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
//! The Organization API.

mod code_scanning;
pub mod codespaces;
pub mod copilot;
pub mod copilot_seat_manager;
mod custom_properties;
pub mod dependabot;
mod events;
mod hooks;
mod invitations;
mod issues;
mod list_members;
mod list_repos;
pub mod migrations;
mod personal_access_tokens;
mod roles;
mod rulesets;
mod secret_scanning_alerts;
mod secrets;
mod variables;

pub use self::code_scanning::{ListOrgCodeScanningAlertsBuilder, OrgCodeScanningHandler};
pub use self::codespaces::OrgCodespacesHandler;
pub use self::custom_properties::{ListOrgCustomPropertyValuesBuilder, OrgCustomPropertiesHandler};
pub use self::dependabot::OrgDependabotHandler;
pub use self::events::ListOrgEventsBuilder;
pub use self::hooks::{ListOrgHooksBuilder, OrgHooksHandler, UpdateOrgHookBuilder};
pub use self::invitations::{
    CreateOrgInvitationBuilder, ListFailedOrgInvitationsBuilder, ListOrgInvitationTeamsBuilder,
    ListOrgInvitationsBuilder, OrgInvitationsHandler,
};
pub use self::issues::ListOrgIssuesBuilder;
pub use self::list_members::ListOrgMembersBuilder;
pub use self::list_repos::ListReposBuilder;
pub use self::migrations::OrgMigrationsHandler;
pub use self::personal_access_tokens::{
    ListOrgPatRepositoriesBuilder, ListOrgPatRequestRepositoriesBuilder, ListOrgPatRequestsBuilder,
    ListOrgPersonalAccessTokensBuilder, OrgPersonalAccessTokensHandler,
};
pub use self::roles::OrgRolesHandler;
pub use self::rulesets::{
    ListOrgRuleSuitesBuilder, ListOrgRulesetsBuilder, OrgRuleSuitesHandler, OrgRulesetsHandler,
};
pub use self::secret_scanning_alerts::OrgSecretScanningAlertsHandler;
pub use self::secrets::OrgSecretsHandler;
pub use self::variables::OrgVariablesHandler;
pub use crate::api::billing::ScopedBillingHandler as OrgBillingHandler;
pub use crate::api::security_advisories::OrgSecurityAdvisoriesHandler;
use crate::error::HttpSnafu;
use crate::models::interaction_limits;
use crate::models::interaction_limits::InteractionLimit;
use crate::models::{Author, Installation};
use crate::Octocrab;
use crate::Page;
use http::{StatusCode, Uri};
use interaction_limits::{InteractionLimitExpiry, InteractionLimitType};
use snafu::ResultExt;

/// A client to GitHub's organization API.
///
/// Created with [`Octocrab::orgs`].
pub struct OrgHandler<'octo> {
    crab: &'octo Octocrab,
    owner: String,
}

impl<'octo> OrgHandler<'octo> {
    pub(crate) fn new(crab: &'octo Octocrab, owner: String) -> Self {
        Self { crab, owner }
    }

    /// Handle billing for the organization.
    ///
    /// See: <https://docs.github.com/en/rest/billing?apiVersion=2022-11-28>
    pub fn billing(&self) -> crate::api::billing::ScopedBillingHandler<'octo> {
        crate::api::billing::ScopedBillingHandler::new(
            self.crab,
            crate::api::billing::BillingOwner::Org(self.owner.clone()),
        )
    }

    /// Handle packages for the organization.
    ///
    /// See: https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28
    pub fn packages(&self) -> crate::api::packages::PackagesHandler<'octo> {
        crate::api::packages::PackagesHandler::new(
            self.crab,
            crate::api::packages::PackagesOwner::Org(self.owner.clone()),
        )
    }

    /// Handle Codespaces for the organization.
    ///
    /// See: https://docs.github.com/en/rest/codespaces/organizations?apiVersion=2022-11-28
    pub fn codespaces(&self) -> OrgCodespacesHandler<'octo> {
        OrgCodespacesHandler::new(self.crab, self.owner.clone())
    }

    /// Handle migrations for the organization.
    ///
    /// See: https://docs.github.com/en/rest/migrations/orgs?apiVersion=2022-11-28
    pub fn migrations(&self) -> OrgMigrationsHandler<'octo> {
        OrgMigrationsHandler::new(self.crab, self.owner.clone())
    }

    /// Handle Dependabot for the organization.
    ///
    /// See: https://docs.github.com/en/rest/dependabot?apiVersion=2022-11-28
    pub fn dependabot(&self) -> OrgDependabotHandler<'octo> {
        OrgDependabotHandler::new(self.crab, self.owner.clone())
    }

    /// Handle security advisories for the organization.
    ///
    /// See: https://docs.github.com/en/rest/security-advisories/repository-advisories#list-repository-security-advisories-for-an-organization
    pub fn security_advisories(&self) -> OrgSecurityAdvisoriesHandler<'octo> {
        OrgSecurityAdvisoriesHandler::new(self.crab, self.owner.clone())
    }

    /// Handle secret scanning alerts for the organization.
    ///
    /// See: https://docs.github.com/en/rest/secret-scanning?apiVersion=2022-11-28#list-secret-scanning-alerts-for-an-organization
    pub fn secret_scanning(&self) -> OrgSecretScanningAlertsHandler<'_> {
        OrgSecretScanningAlertsHandler::new(self)
    }

    /// Handle secret scanning alerts for the organization (alias for [`secret_scanning`][OrgHandler::secret_scanning]).
    pub fn secrets_scanning(&self) -> OrgSecretScanningAlertsHandler<'_> {
        self.secret_scanning()
    }

    /// Handle code scanning alerts for the organization.
    ///
    /// See: https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-an-organization
    pub fn code_scanning(&self) -> OrgCodeScanningHandler<'octo, '_> {
        OrgCodeScanningHandler::new(self)
    }

    /// Handle code scanning alerts for the organization (alias for [`code_scanning`][OrgHandler::code_scanning]).
    pub fn code_scannings(&self) -> OrgCodeScanningHandler<'octo, '_> {
        self.code_scanning()
    }

    /// Handle rulesets for the organization.
    ///
    /// See: https://docs.github.com/en/rest/orgs/rules?apiVersion=2022-11-28
    pub fn rulesets(&self) -> OrgRulesetsHandler<'octo, '_> {
        OrgRulesetsHandler::new(self)
    }

    /// Handle webhooks for the organization.
    ///
    /// See: https://docs.github.com/en/rest/orgs/webhooks?apiVersion=2022-11-28
    pub fn hooks(&self) -> OrgHooksHandler<'octo, '_> {
        OrgHooksHandler::new(self)
    }

    /// Handle custom properties for the organization.
    ///
    /// See: https://docs.github.com/en/rest/orgs/custom-properties?apiVersion=2022-11-28
    pub fn custom_properties(&self) -> OrgCustomPropertiesHandler<'octo, '_> {
        OrgCustomPropertiesHandler::new(self)
    }

    /// Handle organization roles.
    ///
    /// See: https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28
    pub fn roles(&self) -> OrgRolesHandler<'octo, '_> {
        OrgRolesHandler::new(self)
    }

    /// Handle invitations for the organization.
    ///
    /// See: https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28
    pub fn invitations(&self) -> OrgInvitationsHandler<'octo, '_> {
        OrgInvitationsHandler::new(self)
    }

    /// Handle fine-grained personal access tokens for the organization.
    ///
    /// See: https://docs.github.com/en/rest/orgs/personal-access-tokens?apiVersion=2022-11-28
    pub fn personal_access_tokens(&self) -> OrgPersonalAccessTokensHandler<'octo, '_> {
        OrgPersonalAccessTokensHandler::new(self)
    }

    /// List organization issues assigned to the authenticated user.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-organization-issues-assigned-to-the-authenticated-user)
    pub fn list_issues(&self) -> ListOrgIssuesBuilder<'octo, '_, '_> {
        ListOrgIssuesBuilder::new(self)
    }

    /// Add or update organization membership
    ///
    /// **Note**
    /// - Only authenticated organization owners can add a member to the
    ///   organization or update the member's role.
    /// - If the authenticated user is adding a member to the organization, the
    ///   invited user will receive an email inviting them to the organization.
    ///   The user's membership status will be pending until they accept
    ///   the invitation.
    /// - Authenticated users can update a user's membership by passing the role
    ///   parameter. If the authenticated user changes a member's role to admin,
    ///   the affected user will receive an email notifying them that they've
    ///   been made an organization owner. If the authenticated user changes an
    ///   owner's role to member, no email will be sent.
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let invitation = octocrab.orgs("owner").add_or_update_membership("ferris", None).await?;
    /// # Ok(())
    /// # }
    /// ```
    pub async fn add_or_update_membership(
        &self,
        username: impl AsRef<str>,
        role: Option<crate::params::orgs::Role>,
    ) -> crate::Result<crate::models::orgs::MembershipInvitation> {
        let route = format!(
            "/orgs/{org}/memberships/{username}",
            org = self.owner,
            username = username.as_ref(),
        );

        let body = role.map(|role| serde_json::json!({ "role": role }));

        self.crab.post(route, body.as_ref()).await
    }

    /// Check if a user is, publicly or privately, a member of the organization.
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// assert!(octocrab.orgs("owner").check_membership("ferris").await?);
    /// # Ok(())
    /// # }
    /// ```
    pub async fn check_membership(&self, username: impl AsRef<str>) -> crate::Result<bool> {
        let route = format!(
            "/orgs/{org}/members/{username}",
            org = self.owner,
            username = username.as_ref(),
        );

        let uri = Uri::builder()
            .path_and_query(route)
            .build()
            .context(HttpSnafu)?;

        let response = self.crab._get(uri).await?;

        match response.status() {
            StatusCode::NO_CONTENT => Ok(true),
            StatusCode::NOT_FOUND => Ok(false),
            _ => Err(crate::map_github_error(response).await.unwrap_err()),
        }
    }

    /// Get an organization
    ///
    /// To see many of the organization response values, you need to be an
    /// authenticated organization owner with the `admin:org` scope. When the
    /// value of `two_factor_requirement_enabled` is true, the organization
    /// requires all members, billing managers, and outside collaborators to
    /// enable two-factor authentication.
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let org = octocrab.orgs("owner").get().await?;
    /// # Ok(())
    /// # }
    /// ```
    pub async fn get(&self) -> crate::Result<crate::models::orgs::Organization> {
        let route = format!("/orgs/{org}", org = self.owner);

        self.crab.get(route, None::<&()>).await
    }

    /// List repos for the specified organization.
    ///
    /// ```no_run
    /// # async fn run() -> octocrab::Result<()> {
    /// use octocrab::params;
    ///
    /// // Get the least active repos belonging to `owner`.
    /// let page = octocrab::instance()
    ///     .orgs("owner")
    ///     .list_repos()
    ///     // Optional Parameters
    ///     .repo_type(params::repos::Type::Sources)
    ///     .sort(params::repos::Sort::Pushed)
    ///     .direction(params::Direction::Descending)
    ///     .per_page(25)
    ///     .page(5u32)
    ///     // Send the request.
    ///     .send()
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn list_repos(&self) -> list_repos::ListReposBuilder<'_, '_> {
        list_repos::ListReposBuilder::new(self)
    }

    /// List events on this organization.
    ///
    /// Takes an optional etag which allows for efficient polling. Here is a quick example to poll a
    /// organization's events.
    /// ```no_run
    /// # use std::convert::TryFrom;
    /// # use octocrab::{models::events::Event, etag::{Etagged,EntityTag}, Page};
    /// # async fn run() -> octocrab::Result<()> {
    /// let mut etag = None;
    /// loop {
    ///     let response: Etagged<Page<Event>> = octocrab::instance()
    ///         .orgs("owner")
    ///         .events()
    ///         .etag(etag)
    ///         .send()
    ///         .await?;
    ///     if let Some(page) = response.value {
    ///         // do something with the page ...
    ///     } else {
    ///         println!("No new data received, trying again soon");
    ///     }
    ///     etag = response.etag;
    ///     // add a delay before the next iteration
    /// }
    /// # Ok(())
    /// # }
    /// ```
    pub fn events(&self) -> events::ListOrgEventsBuilder<'_, '_> {
        events::ListOrgEventsBuilder::new(self)
    }

    /// Creates a new webhook for the specified organization.
    ///
    /// # Notes
    /// Only authorized users or apps can modify organization webhooks.
    ///
    /// # Examples
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::hooks::{Hook, Config as HookConfig, ContentType as HookContentType};
    ///
    /// let config = HookConfig {
    ///   url: "https://example.com".to_string(),
    ///   content_type: Some(HookContentType::Json),
    ///   insecure_ssl: None,
    ///   secret: None
    /// };
    ///
    /// let hook = Hook {
    ///   name: "web".to_string(),
    ///   config,
    ///   ..Hook::default()
    /// };
    ///
    /// let hook = octocrab.orgs("owner").create_hook(hook).await?;
    /// # Ok(())
    /// # }
    /// ```
    pub async fn create_hook(
        &self,
        hook: crate::models::hooks::Hook,
    ) -> crate::Result<crate::models::hooks::Hook> {
        let route = format!("/orgs/{org}/hooks", org = self.owner);
        let res = self.crab.post(route, Some(&hook)).await?;

        Ok(res)
    }

    /// Lists members of the specified organization.
    ///
    /// # Notes
    /// Only authorized users who belong to the organization can list its members.
    ///
    /// # Examples
    /// ```no_run
    /// # async fn run() -> octocrab::Result<()> {
    /// let org_members = octocrab::instance().orgs("org").list_members().send().await?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn list_members(&self) -> list_members::ListOrgMembersBuilder<'_, '_> {
        list_members::ListOrgMembersBuilder::new(self)
    }

    /// Handle secrets on the organizaton
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let secrets = octocrab.orgs("org").secrets();
    /// # Ok(())
    /// # }
    /// ```
    pub fn secrets(&self) -> secrets::OrgSecretsHandler<'_> {
        secrets::OrgSecretsHandler::new(self)
    }

    /// Client for GitHub's organization variables API.
    ///
    /// See: https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28
    pub fn variables(&self) -> OrgVariablesHandler<'_> {
        OrgVariablesHandler::new(self)
    }

    /// ### Get interaction restrictions for an organization
    ///
    /// Shows which type of GitHub user can interact with this organization and when the restriction expires. If there is no restrictions, you will see an empty response.
    ///
    /// Fine-grained access tokens for "Get interaction restrictions for an organization"
    ///
    /// This endpoint works with the following fine-grained token types:
    ///
    /// - GitHub App user access tokens
    /// - GitHub App installation access tokens
    /// - Fine-grained personal access tokens
    ///
    /// The fine-grained token must have the following permission set:
    ///
    /// - "Administration" organization permissions (read)
    ///
    pub async fn get_interaction_restrictions(
        &self,
    ) -> crate::Result<interaction_limits::InteractionLimit> {
        let route = format!("/orgs/{}/interaction-limits", self.owner);
        self.crab.get(route, None::<&()>).await
    }

    /// ### Set interaction restrictions for an organization
    ///
    /// Temporarily restricts interactions to a certain type of GitHub user in any public repository in the given organization. You must be an organization owner to set these restrictions. Setting the interaction limit at the organization level will overwrite any interaction limits that are set for individual repositories owned by the organization.
    ///
    /// Fine-grained access tokens for "Set interaction restrictions for an organization"
    ///
    /// This endpoint works with the following fine-grained token types:
    ///
    /// - GitHub App user access tokens
    /// - GitHub App installation access tokens
    /// - Fine-grained personal access tokens
    ///
    /// The fine-grained token must have the following permission set:
    ///
    /// - "Administration" organization permissions (write)
    ///
    pub async fn set_interaction_restrictions(
        &self,
        limit_type: InteractionLimitType,
        expiry: InteractionLimitExpiry,
    ) -> crate::Result<InteractionLimit> {
        let route = format!("/orgs/{}/interaction-limits", self.owner);
        let body = serde_json::json!({
            "limit": limit_type,
            "expiry": expiry,
        });
        self.crab.put(route, Some(&body)).await
    }

    /// Handle copilot-related calls on the organization.
    ///
    /// Note: You can also use the top-level [`Octocrab::copilot().org(...)`][crate::Octocrab::copilot] entry point.
    ///
    /// # Examples
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let copilot_usage = octocrab.orgs("org").copilot().metrics().await.expect("failed to retrieve usage");
    /// # Ok(())
    /// # }
    /// ```
    pub fn copilot(&self) -> copilot::CopilotHandler<'octo, '_> {
        copilot::CopilotHandler::new(self)
    }

    /// ### Remove interaction restrictions for an organization
    ///
    /// Removes all interaction restrictions from public repositories in the given organization. You must be an organization owner to remove restrictions.
    ///
    /// Fine-grained access tokens for "Remove interaction restrictions for an organization"
    ///
    /// This endpoint works with the following fine-grained token types:
    ///
    /// - GitHub App user access tokens
    /// - GitHub App installation access tokens
    /// - Fine-grained personal access tokens
    ///
    /// The fine-grained token must have the following permission set:
    ///
    /// - "Administration" organization permissions (write)
    ///
    /// ```no_run
    ///  async fn run() -> crate::octocrab::Result<()> {
    ///   let org_name = "example-org".to_string();
    ///   let crab = octocrab::instance();
    ///   crab.orgs(org_name).remove_interaction_restrictions().await?;
    ///   Ok(())
    ///  }
    /// ```
    pub async fn remove_interaction_restrictions(&self) -> crate::Result<()> {
        let route = format!("/orgs/{}/interaction-limits", self.owner);
        let response = self.crab._delete(route, None::<&()>).await?;
        crate::map_github_error(response).await.map(drop)
    }

    /// Lists public members of an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#list-public-organization-members)
    pub fn list_public_members(&self) -> ListPublicMembersBuilder<'octo, '_> {
        ListPublicMembersBuilder::new(self)
    }

    /// Checks if a user is a public member of an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-public-organization-membership-for-a-user)
    pub async fn check_public_membership(&self, username: impl AsRef<str>) -> crate::Result<bool> {
        let route = format!(
            "/orgs/{org}/public_members/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let uri = Uri::builder()
            .path_and_query(route)
            .build()
            .context(HttpSnafu)?;
        let response = self.crab._get(uri).await?;
        match response.status() {
            StatusCode::NO_CONTENT => Ok(true),
            StatusCode::NOT_FOUND => Ok(false),
            _ => Err(crate::map_github_error(response).await.unwrap_err()),
        }
    }

    /// Sets public organization membership for the authenticated user.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#set-public-organization-membership-for-the-authenticated-user)
    pub async fn publicize_membership(&self, username: impl AsRef<str>) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/public_members/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let response = self.crab._put(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Removes public organization membership for the authenticated user.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#remove-public-organization-membership-for-the-authenticated-user)
    pub async fn conceal_membership(&self, username: impl AsRef<str>) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/public_members/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let response = self.crab._delete(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Lists outside collaborators for an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/outside-collaborators?apiVersion=2022-11-28#list-outside-collaborators-for-an-organization)
    pub fn list_outside_collaborators(&self) -> ListOutsideCollaboratorsBuilder<'octo, '_> {
        ListOutsideCollaboratorsBuilder::new(self)
    }

    /// Converts an organization member to outside collaborator.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/outside-collaborators?apiVersion=2022-11-28#convert-an-organization-member-to-outside-collaborator)
    pub async fn convert_to_outside_collaborator(
        &self,
        username: impl AsRef<str>,
    ) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/outside_collaborators/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let response = self.crab._put(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Removes an outside collaborator from an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/outside-collaborators?apiVersion=2022-11-28#remove-outside-collaborator-from-an-organization)
    pub async fn remove_outside_collaborator(
        &self,
        username: impl AsRef<str>,
    ) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/outside_collaborators/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let response = self.crab._delete(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Lists users blocked by an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/blocking?apiVersion=2022-11-28#list-users-blocked-by-an-organization)
    pub fn list_blocked_users(&self) -> ListBlockedUsersBuilder<'octo, '_> {
        ListBlockedUsersBuilder::new(self)
    }

    /// Checks if a user is blocked by an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/blocking?apiVersion=2022-11-28#check-if-a-user-is-blocked-by-an-organization)
    pub async fn check_blocked_user(&self, username: impl AsRef<str>) -> crate::Result<bool> {
        let route = format!(
            "/orgs/{org}/blocks/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let uri = Uri::builder()
            .path_and_query(route)
            .build()
            .context(HttpSnafu)?;
        let response = self.crab._get(uri).await?;
        match response.status() {
            StatusCode::NO_CONTENT => Ok(true),
            StatusCode::NOT_FOUND => Ok(false),
            _ => Err(crate::map_github_error(response).await.unwrap_err()),
        }
    }

    /// Blocks a user from an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/blocking?apiVersion=2022-11-28#block-a-user-from-an-organization)
    pub async fn block_user(&self, username: impl AsRef<str>) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/blocks/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let response = self.crab._put(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Unblocks a user from an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/blocking?apiVersion=2022-11-28#unblock-a-user-from-an-organization)
    pub async fn unblock_user(&self, username: impl AsRef<str>) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/blocks/{username}",
            org = self.owner,
            username = username.as_ref()
        );
        let response = self.crab._delete(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Lists teams that are security managers for an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/security-managers?apiVersion=2022-11-28#list-security-manager-teams)
    pub async fn list_security_managers(&self) -> crate::Result<Vec<crate::models::teams::Team>> {
        let route = format!("/orgs/{org}/security-managers", org = self.owner);
        self.crab.get(route, None::<&()>).await
    }

    /// Adds a security manager team to an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/security-managers?apiVersion=2022-11-28#add-a-security-manager-team)
    pub async fn add_security_manager_team(&self, team_slug: impl AsRef<str>) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/security-managers/teams/{team_slug}",
            org = self.owner,
            team_slug = team_slug.as_ref()
        );
        let response = self.crab._put(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Removes a security manager team from an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/security-managers?apiVersion=2022-11-28#remove-a-security-manager-team)
    pub async fn remove_security_manager_team(
        &self,
        team_slug: impl AsRef<str>,
    ) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/security-managers/teams/{team_slug}",
            org = self.owner,
            team_slug = team_slug.as_ref()
        );
        let response = self.crab._delete(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Enables or disables a security feature for an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#enable-or-disable-a-security-feature-for-an-organization)
    pub async fn set_security_product_enablement(
        &self,
        product: crate::models::orgs::security::SecurityProduct,
        enablement: crate::models::orgs::security::SecurityEnablement,
    ) -> crate::Result<()> {
        let route = format!(
            "/orgs/{org}/{product}/{enablement}",
            org = self.owner,
            product = product,
            enablement = enablement
        );
        let response = self.crab._patch(route, None::<&()>).await?;
        if !response.status().is_success() {
            return Err(crate::map_github_error(response).await.unwrap_err());
        }
        Ok(())
    }

    /// Lists app installations for an organization.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#list-app-installations-for-an-organization)
    pub fn list_installations(&self) -> ListOrgInstallationsBuilder<'octo, '_> {
        ListOrgInstallationsBuilder::new(self)
    }

    /// Gets an organization installation for the authenticated app.
    ///
    /// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-organization-installation-for-the-authenticated-app)
    pub async fn installation(&self) -> crate::Result<crate::models::Installation> {
        let route = format!("/orgs/{}/installation", self.owner);
        self.crab.get(route, None::<&()>).await
    }
}

/// Builder for listing public organization members.
#[derive(serde::Serialize)]
pub struct ListPublicMembersBuilder<'octo, 'r> {
    #[serde(skip)]
    handler: &'r OrgHandler<'octo>,
    #[serde(skip_serializing_if = "Option::is_none")]
    per_page: Option<u8>,
    #[serde(skip_serializing_if = "Option::is_none")]
    page: Option<u32>,
}

impl<'octo, 'r> ListPublicMembersBuilder<'octo, 'r> {
    pub(crate) fn new(handler: &'r OrgHandler<'octo>) -> Self {
        Self {
            handler,
            per_page: None,
            page: None,
        }
    }

    pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
        self.per_page = Some(per_page.into());
        self
    }

    pub fn page(mut self, page: impl Into<u32>) -> Self {
        self.page = Some(page.into());
        self
    }

    pub async fn send(self) -> crate::Result<Page<Author>> {
        let route = format!("/orgs/{org}/public_members", org = self.handler.owner);
        self.handler.crab.get(route, Some(&self)).await
    }
}

/// Builder for listing outside collaborators for an organization.
#[derive(serde::Serialize)]
pub struct ListOutsideCollaboratorsBuilder<'octo, 'r> {
    #[serde(skip)]
    handler: &'r OrgHandler<'octo>,
    #[serde(skip_serializing_if = "Option::is_none")]
    filter: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    per_page: Option<u8>,
    #[serde(skip_serializing_if = "Option::is_none")]
    page: Option<u32>,
}

impl<'octo, 'r> ListOutsideCollaboratorsBuilder<'octo, 'r> {
    pub(crate) fn new(handler: &'r OrgHandler<'octo>) -> Self {
        Self {
            handler,
            filter: None,
            per_page: None,
            page: None,
        }
    }

    pub fn filter(mut self, filter: impl Into<String>) -> Self {
        self.filter = Some(filter.into());
        self
    }

    pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
        self.per_page = Some(per_page.into());
        self
    }

    pub fn page(mut self, page: impl Into<u32>) -> Self {
        self.page = Some(page.into());
        self
    }

    pub async fn send(self) -> crate::Result<Page<Author>> {
        let route = format!(
            "/orgs/{org}/outside_collaborators",
            org = self.handler.owner
        );
        self.handler.crab.get(route, Some(&self)).await
    }
}

/// Builder for listing users blocked by an organization.
#[derive(serde::Serialize)]
pub struct ListBlockedUsersBuilder<'octo, 'r> {
    #[serde(skip)]
    handler: &'r OrgHandler<'octo>,
    #[serde(skip_serializing_if = "Option::is_none")]
    per_page: Option<u8>,
    #[serde(skip_serializing_if = "Option::is_none")]
    page: Option<u32>,
}

impl<'octo, 'r> ListBlockedUsersBuilder<'octo, 'r> {
    pub(crate) fn new(handler: &'r OrgHandler<'octo>) -> Self {
        Self {
            handler,
            per_page: None,
            page: None,
        }
    }

    pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
        self.per_page = Some(per_page.into());
        self
    }

    pub fn page(mut self, page: impl Into<u32>) -> Self {
        self.page = Some(page.into());
        self
    }

    pub async fn send(self) -> crate::Result<Page<Author>> {
        let route = format!("/orgs/{org}/blocks", org = self.handler.owner);
        self.handler.crab.get(route, Some(&self)).await
    }
}

/// Builder for listing app installations for an organization.
#[derive(serde::Serialize)]
pub struct ListOrgInstallationsBuilder<'octo, 'r> {
    #[serde(skip)]
    handler: &'r OrgHandler<'octo>,
    #[serde(skip_serializing_if = "Option::is_none")]
    per_page: Option<u8>,
    #[serde(skip_serializing_if = "Option::is_none")]
    page: Option<u32>,
}

impl<'octo, 'r> ListOrgInstallationsBuilder<'octo, 'r> {
    pub(crate) fn new(handler: &'r OrgHandler<'octo>) -> Self {
        Self {
            handler,
            per_page: None,
            page: None,
        }
    }

    pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
        self.per_page = Some(per_page.into());
        self
    }

    pub fn page(mut self, page: impl Into<u32>) -> Self {
        self.page = Some(page.into());
        self
    }

    pub async fn send(self) -> crate::Result<Page<Installation>> {
        let route = format!("/orgs/{org}/installations", org = self.handler.owner);
        self.handler.crab.get(route, Some(&self)).await
    }
}