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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
//! The Organization API.
pub mod artifact_metadata;
pub mod attestations;
mod code_scanning;
pub mod code_security_configurations;
pub mod codespaces;
pub mod copilot;
pub mod copilot_seat_manager;
mod custom_properties;
pub mod dependabot;
mod events;
pub mod external_properties;
mod hooks;
pub mod immutable_releases;
pub mod insights;
mod invitations;
pub mod issue_fields_and_types;
mod issues;
mod list_members;
mod list_repos;
pub mod migrations;
pub mod network_configurations;
mod personal_access_tokens;
pub mod private_registries;
mod roles;
mod rulesets;
mod secret_scanning_alerts;
mod secrets;
mod variables;
pub use self::artifact_metadata::OrgArtifactMetadataHandler;
pub use self::attestations::OrgAttestationsHandler;
pub use self::code_security_configurations::{
ListOrgCodeSecurityConfigRepositoriesBuilder, ListOrgCodeSecurityConfigsBuilder,
OrgCodeSecurityHandler,
};
pub use self::external_properties::OrgExternalPropertiesHandler;
pub use self::immutable_releases::OrgImmutableReleasesHandler;
pub use self::insights::OrgInsightsHandler;
pub use self::issue_fields_and_types::{OrgIssueFieldsHandler, OrgIssueTypesHandler};
pub use self::network_configurations::OrgNetworkConfigurationsHandler;
pub use self::private_registries::{ListOrgPrivateRegistriesBuilder, OrgPrivateRegistriesHandler};
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::actions::OrgActionsHandler;
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: [GitHub API Documentation](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: [GitHub API Documentation](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 GitHub Actions for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions?apiVersion=2022-11-28)
pub fn actions(&self) -> OrgActionsHandler<'octo> {
OrgActionsHandler::new(self.crab, self.owner.clone())
}
/// Handle migrations for the organization.
///
/// See: [GitHub API Documentation](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: [GitHub API Documentation](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: [GitHub API Documentation](https://docs.github.com/en/rest/security-advisories/repository-advisories?apiVersion=2022-11-28#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: [GitHub API Documentation](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: [GitHub API Documentation](https://docs.github.com/en/rest/code-scanning/code-scanning?apiVersion=2022-11-28#list-code-scanning-alerts-for-an-organization)
/// Handle security campaigns for the organization.
pub fn campaigns(&self) -> crate::api::campaigns::CampaignsHandler<'octo> {
crate::api::campaigns::CampaignsHandler::new(self.crab, self.owner.clone())
}
pub fn code_scanning(&self) -> OrgCodeScanningHandler<'octo, '_> {
OrgCodeScanningHandler::new(self)
}
/// Handle code security configurations for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/code-security/configurations?apiVersion=2022-11-28)
pub fn code_security(&self) -> OrgCodeSecurityHandler<'octo, '_> {
OrgCodeSecurityHandler::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: [GitHub API Documentation](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: [GitHub API Documentation](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: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/custom-properties?apiVersion=2022-11-28)
pub fn custom_properties(&self) -> OrgCustomPropertiesHandler<'octo, '_> {
OrgCustomPropertiesHandler::new(self)
}
/// Handle private registries for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/private-registries/organization-configurations?apiVersion=2022-11-28)
pub fn private_registries(&self) -> OrgPrivateRegistriesHandler<'octo, '_> {
OrgPrivateRegistriesHandler::new(self)
}
/// Handle Projects (v2) for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/projects/projects?apiVersion=2022-11-28)
pub fn projects_v2(&self) -> crate::api::projects_v2::OrgProjectsV2Handler<'octo> {
crate::api::projects_v2::OrgProjectsV2Handler::new(self.crab, &self.owner)
}
/// Handle Agents for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/agents?apiVersion=2022-11-28)
pub fn agents(&self) -> crate::api::agents::OrgAgentsHandler<'octo, '_> {
crate::api::agents::OrgAgentsHandler::new(self.crab, &self.owner)
}
/// Handle Copilot Spaces for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/copilot-spaces?apiVersion=2022-11-28)
pub fn copilot_spaces(&self) -> crate::api::copilot_spaces::OrgCopilotSpacesHandler<'octo> {
crate::api::copilot_spaces::OrgCopilotSpacesHandler::new(self.crab, &self.owner)
}
/// Handle organization roles.
///
/// See: [GitHub API Documentation](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: [GitHub API Documentation](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: [GitHub API Documentation](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)
}
/// Handle API insights for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/api-insights?apiVersion=2022-11-28)
pub fn insights(&self) -> OrgInsightsHandler<'octo, '_> {
OrgInsightsHandler::new(self)
}
/// Handle artifact metadata and deployment records for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/artifact-metadata?apiVersion=2022-11-28)
pub fn artifact_metadata(&self) -> OrgArtifactMetadataHandler<'octo, '_> {
OrgArtifactMetadataHandler::new(self)
}
/// Handle attestations for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/attestations?apiVersion=2022-11-28)
pub fn attestations(&self) -> OrgAttestationsHandler<'octo, '_> {
OrgAttestationsHandler::new(self)
}
/// Handle external custom properties for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/external-properties?apiVersion=2022-11-28)
pub fn external_properties(&self) -> OrgExternalPropertiesHandler<'octo, '_> {
OrgExternalPropertiesHandler::new(self)
}
/// Handle issue fields for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/issue-fields?apiVersion=2022-11-28)
pub fn issue_fields(&self) -> OrgIssueFieldsHandler<'octo, '_> {
OrgIssueFieldsHandler::new(self)
}
/// Handle issue types for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/issue-types?apiVersion=2022-11-28)
pub fn issue_types(&self) -> OrgIssueTypesHandler<'octo, '_> {
OrgIssueTypesHandler::new(self)
}
/// Handle hosted compute network configurations for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/network-configurations?apiVersion=2022-11-28)
pub fn network_configurations(&self) -> OrgNetworkConfigurationsHandler<'octo, '_> {
OrgNetworkConfigurationsHandler::new(self)
}
/// Handle immutable releases settings for the organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/organization-settings?apiVersion=2022-11-28)
pub fn immutable_releases(&self) -> OrgImmutableReleasesHandler<'octo, '_> {
OrgImmutableReleasesHandler::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.put(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()),
}
}
/// Remove an organization member.
///
/// In order to remove a member of an organization, the authenticated user must be an organization owner.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#remove-an-organization-member)
pub async fn remove_member(&self, username: impl AsRef<str>) -> crate::Result<()> {
let route = format!(
"/orgs/{org}/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(())
}
/// Get organization membership for a user.
///
/// In order to get a user's membership with an organization, the authenticated user must be an organization owner.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#get-organization-membership-for-a-user)
pub async fn get_membership(
&self,
username: impl AsRef<str>,
) -> crate::Result<crate::models::orgs::MembershipInvitation> {
let route = format!(
"/orgs/{org}/memberships/{username}",
org = self.owner,
username = username.as_ref(),
);
self.crab.get(route, None::<&()>).await
}
/// Remove organization membership for a user.
///
/// In order to remove a user's membership with an organization, the authenticated user must be an organization owner.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#remove-organization-membership-for-a-user)
pub async fn remove_membership(&self, username: impl AsRef<str>) -> crate::Result<()> {
let route = format!(
"/orgs/{org}/memberships/{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(())
}
/// 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
}
/// Update an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#update-an-organization)
pub async fn update(
&self,
body: &impl serde::Serialize,
) -> crate::Result<crate::models::orgs::Organization> {
let route = format!("/orgs/{org}", org = self.owner);
self.crab.patch(route, Some(body)).await
}
/// Delete an organization.
///
/// Deletes an organization and all its repositories.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#delete-an-organization)
pub async fn delete(&self) -> crate::Result<()> {
let route = format!("/orgs/{org}", org = self.owner);
let response = self.crab._delete(route, None::<&()>).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// 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: [GitHub API Documentation](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)
}
/// Get pull request creation cap for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/interactions/org-restrictions?apiVersion=2022-11-28#get-pull-request-creation-cap-for-an-organization)
pub async fn pull_request_creation_cap(
&self,
) -> crate::Result<crate::models::interaction_limits::PullRequestCreationCap> {
let route = format!("/orgs/{}/interaction-limits/pulls/creation-cap", self.owner);
self.crab.get(route, None::<&()>).await
}
/// Update pull request creation cap for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/interactions/org-restrictions?apiVersion=2022-11-28#update-pull-request-creation-cap-for-an-organization)
pub async fn update_pull_request_creation_cap(
&self,
cap: &crate::models::interaction_limits::PullRequestCreationCap,
) -> crate::Result<crate::models::interaction_limits::PullRequestCreationCap> {
let route = format!("/orgs/{}/interaction-limits/pulls/creation-cap", self.owner);
self.crab.patch(route, Some(cap)).await
}
/// Create an organization repository.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#create-an-organization-repository)
pub fn create_repo(&self, name: impl Into<String>) -> CreateOrgRepoBuilder<'octo, '_> {
CreateOrgRepoBuilder::new(self, name.into())
}
/// 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._post(route, None::<&()>).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// Alias for [`set_security_product_enablement`][OrgHandler::set_security_product_enablement].
pub async fn enable_or_disable_security_product(
&self,
product: crate::models::orgs::security::SecurityProduct,
enablement: crate::models::orgs::security::SecurityEnablement,
) -> crate::Result<()> {
self.set_security_product_enablement(product, enablement)
.await
}
/// 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
}
}
/// Builder for creating an organization repository.
#[derive(serde::Serialize)]
pub struct CreateOrgRepoBuilder<'octo, 'b> {
#[serde(skip)]
handler: &'b OrgHandler<'octo>,
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
private: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
visibility: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
has_issues: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
has_projects: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
has_wiki: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
is_template: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
auto_init: Option<bool>,
}
impl<'octo, 'b> CreateOrgRepoBuilder<'octo, 'b> {
pub(crate) fn new(handler: &'b OrgHandler<'octo>, name: String) -> Self {
Self {
handler,
name,
description: None,
homepage: None,
private: None,
visibility: None,
has_issues: None,
has_projects: None,
has_wiki: None,
is_template: None,
auto_init: None,
}
}
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn homepage(mut self, homepage: impl Into<String>) -> Self {
self.homepage = Some(homepage.into());
self
}
pub fn private(mut self, private: bool) -> Self {
self.private = Some(private);
self
}
pub fn visibility(mut self, visibility: impl Into<String>) -> Self {
self.visibility = Some(visibility.into());
self
}
pub fn has_issues(mut self, has_issues: bool) -> Self {
self.has_issues = Some(has_issues);
self
}
pub fn has_projects(mut self, has_projects: bool) -> Self {
self.has_projects = Some(has_projects);
self
}
pub fn has_wiki(mut self, has_wiki: bool) -> Self {
self.has_wiki = Some(has_wiki);
self
}
pub fn is_template(mut self, is_template: bool) -> Self {
self.is_template = Some(is_template);
self
}
pub fn auto_init(mut self, auto_init: bool) -> Self {
self.auto_init = Some(auto_init);
self
}
pub async fn send(self) -> crate::Result<crate::models::Repository> {
let route = format!("/orgs/{}/repos", self.handler.owner);
self.handler.crab.post(route, Some(&self)).await
}
}