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 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
|
############################ Copyrights and license ############################
# #
# Copyright 2012 Steve English <steve.english@navetas.com> #
# Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2012 Zearin <zearin@gonk.net> #
# Copyright 2013 AKFish <akfish@gmail.com> #
# Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2013 martinqt <m.ki2@laposte.net> #
# Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2015 Sebastien Besson <seb.besson@gmail.com> #
# Copyright 2016 Jannis Gebauer <ja.geb@me.com> #
# Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> #
# Copyright 2016 Michael Pereira <pereira.m@gmail.com> #
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
# Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> #
# Copyright 2018 Anton Nguyen <afnguyen85@gmail.com> #
# Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> #
# Copyright 2018 Jasper van Wanrooy <jasper@vanwanrooy.net> #
# Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> #
# Copyright 2018 Tim Boring <tboring@hearst.com> #
# Copyright 2018 sfdye <tsfdye@gmail.com> #
# Copyright 2018 Steve Kowalik <steven@wedontsleep.org> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
# #
# PyGithub is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Lesser General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
import datetime
import github.Event
import github.GithubObject
import github.NamedUser
import github.PaginatedList
import github.Plan
import github.Project
import github.Repository
import github.Team
from . import Consts
class Organization(github.GithubObject.CompletableGithubObject):
"""
This class represents Organizations. The reference can be found here http://docs.github.com/en/rest/reference/orgs
"""
def __repr__(self):
return self.get__repr__({"login": self._login.value})
@property
def avatar_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._avatar_url)
return self._avatar_url.value
@property
def billing_email(self):
"""
:type: string
"""
self._completeIfNotSet(self._billing_email)
return self._billing_email.value
@property
def blog(self):
"""
:type: string
"""
self._completeIfNotSet(self._blog)
return self._blog.value
@property
def collaborators(self):
"""
:type: integer
"""
self._completeIfNotSet(self._collaborators)
return self._collaborators.value
@property
def company(self):
"""
:type: string
"""
self._completeIfNotSet(self._company)
return self._company.value
@property
def created_at(self):
"""
:type: datetime.datetime
"""
self._completeIfNotSet(self._created_at)
return self._created_at.value
@property
def default_repository_permission(self):
"""
:type: string
"""
self._completeIfNotSet(self._default_repository_permission)
return self._default_repository_permission.value
@property
def description(self):
"""
:type: string
"""
self._completeIfNotSet(self._description)
return self._description.value
@property
def disk_usage(self):
"""
:type: integer
"""
self._completeIfNotSet(self._disk_usage)
return self._disk_usage.value
@property
def email(self):
"""
:type: string
"""
self._completeIfNotSet(self._email)
return self._email.value
@property
def events_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._events_url)
return self._events_url.value
@property
def followers(self):
"""
:type: integer
"""
self._completeIfNotSet(self._followers)
return self._followers.value
@property
def following(self):
"""
:type: integer
"""
self._completeIfNotSet(self._following)
return self._following.value
@property
def gravatar_id(self):
"""
:type: string
"""
self._completeIfNotSet(self._gravatar_id)
return self._gravatar_id.value
@property
def has_organization_projects(self):
"""
:type: bool
"""
self._completeIfNotSet(self._has_organization_projects)
return self._has_organization_projects.value
@property
def has_repository_projects(self):
"""
:type: bool
"""
self._completeIfNotSet(self._has_repository_projects)
return self._has_repository_projects.value
@property
def hooks_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._hooks_url)
return self._hooks_url.value
@property
def html_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._html_url)
return self._html_url.value
@property
def id(self):
"""
:type: integer
"""
self._completeIfNotSet(self._id)
return self._id.value
@property
def issues_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._issues_url)
return self._issues_url.value
@property
def location(self):
"""
:type: string
"""
self._completeIfNotSet(self._location)
return self._location.value
@property
def login(self):
"""
:type: string
"""
self._completeIfNotSet(self._login)
return self._login.value
@property
def members_can_create_repositories(self):
"""
:type: bool
"""
self._completeIfNotSet(self._members_can_create_repositories)
return self._members_can_create_repositories.value
@property
def members_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._members_url)
return self._members_url.value
@property
def name(self):
"""
:type: string
"""
self._completeIfNotSet(self._name)
return self._name.value
@property
def owned_private_repos(self):
"""
:type: integer
"""
self._completeIfNotSet(self._owned_private_repos)
return self._owned_private_repos.value
@property
def plan(self):
"""
:type: :class:`github.Plan.Plan`
"""
self._completeIfNotSet(self._plan)
return self._plan.value
@property
def private_gists(self):
"""
:type: integer
"""
self._completeIfNotSet(self._private_gists)
return self._private_gists.value
@property
def public_gists(self):
"""
:type: integer
"""
self._completeIfNotSet(self._public_gists)
return self._public_gists.value
@property
def public_members_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._public_members_url)
return self._public_members_url.value
@property
def public_repos(self):
"""
:type: integer
"""
self._completeIfNotSet(self._public_repos)
return self._public_repos.value
@property
def repos_url(self):
"""
:type: string
"""
self._completeIfNotSet(self._repos_url)
return self._repos_url.value
@property
def total_private_repos(self):
"""
:type: integer
"""
self._completeIfNotSet(self._total_private_repos)
return self._total_private_repos.value
@property
def two_factor_requirement_enabled(self):
"""
:type: bool
"""
self._completeIfNotSet(self._two_factor_requirement_enabled)
return self._two_factor_requirement_enabled.value
@property
def type(self):
"""
:type: string
"""
self._completeIfNotSet(self._type)
return self._type.value
@property
def updated_at(self):
"""
:type: datetime.datetime
"""
self._completeIfNotSet(self._updated_at)
return self._updated_at.value
@property
def url(self):
"""
:type: string
"""
self._completeIfNotSet(self._url)
return self._url.value
def add_to_members(self, member, role=github.GithubObject.NotSet):
"""
:calls: `PUT /orgs/{org}/memberships/{user} <https://docs.github.com/en/rest/reference/orgs/members#add-or-update-organization-membership>`_
:param member: :class:`github.NamedUser.NamedUser`
:param role: string
:rtype: None
"""
assert role is github.GithubObject.NotSet or isinstance(role, str), role
assert isinstance(member, github.NamedUser.NamedUser), member
put_parameters = {}
if role is not github.GithubObject.NotSet:
put_parameters["role"] = role
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/memberships/{member._identity}", input=put_parameters
)
def add_to_public_members(self, public_member):
"""
:calls: `PUT /orgs/{org}/public_members/{user} <http://docs.github.com/en/rest/reference/orgs#members>`_
:param public_member: :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(public_member, github.NamedUser.NamedUser), public_member
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/public_members/{public_member._identity}"
)
def create_fork(self, repo):
"""
:calls: `POST /repos/{owner}/{repo}/forks <http://docs.github.com/en/rest/reference/repos#forks>`_
:param repo: :class:`github.Repository.Repository`
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(repo, github.Repository.Repository), repo
url_parameters = {
"org": self.login,
}
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"/repos/{repo.owner.login}/{repo.name}/forks",
parameters=url_parameters,
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
def create_hook(
self,
name,
config,
events=github.GithubObject.NotSet,
active=github.GithubObject.NotSet,
):
"""
:calls: `POST /orgs/{owner}/hooks <http://docs.github.com/en/rest/reference/orgs#hooks>`_
:param name: string
:param config: dict
:param events: list of string
:param active: bool
:rtype: :class:`github.Hook.Hook`
"""
assert isinstance(name, str), name
assert isinstance(config, dict), config
assert events is github.GithubObject.NotSet or all(
isinstance(element, str) for element in events
), events
assert active is github.GithubObject.NotSet or isinstance(active, bool), active
post_parameters = {
"name": name,
"config": config,
}
if events is not github.GithubObject.NotSet:
post_parameters["events"] = events
if active is not github.GithubObject.NotSet:
post_parameters["active"] = active
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/hooks", input=post_parameters
)
return github.Hook.Hook(self._requester, headers, data, completed=True)
def create_project(self, name, body=github.GithubObject.NotSet):
"""
:calls: `POST /orgs/{org}/projects <https://docs.github.com/en/rest/reference/projects#create-an-organization-project>`_
:param name: string
:param body: string
:rtype: :class:`github.Project.Project`
"""
assert isinstance(name, str), name
assert body is github.GithubObject.NotSet or isinstance(body, str), body
post_parameters = {"name": name}
if body is not github.GithubObject.NotSet:
post_parameters["body"] = body
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"{self.url}/projects",
input=post_parameters,
headers={"Accept": Consts.mediaTypeProjectsPreview},
)
return github.Project.Project(self._requester, headers, data, completed=True)
def create_repo(
self,
name,
description=github.GithubObject.NotSet,
homepage=github.GithubObject.NotSet,
private=github.GithubObject.NotSet,
has_issues=github.GithubObject.NotSet,
has_wiki=github.GithubObject.NotSet,
has_downloads=github.GithubObject.NotSet,
has_projects=github.GithubObject.NotSet,
team_id=github.GithubObject.NotSet,
auto_init=github.GithubObject.NotSet,
license_template=github.GithubObject.NotSet,
gitignore_template=github.GithubObject.NotSet,
allow_squash_merge=github.GithubObject.NotSet,
allow_merge_commit=github.GithubObject.NotSet,
allow_rebase_merge=github.GithubObject.NotSet,
delete_branch_on_merge=github.GithubObject.NotSet,
):
"""
:calls: `POST /orgs/{org}/repos <http://docs.github.com/en/rest/reference/repos>`_
:param name: string
:param description: string
:param homepage: string
:param private: bool
:param has_issues: bool
:param has_wiki: bool
:param has_downloads: bool
:param has_projects: bool
:param team_id: : int
:param auto_init: bool
:param license_template: string
:param gitignore_template: string
:param allow_squash_merge: bool
:param allow_merge_commit: bool
:param allow_rebase_merge: bool
:param delete_branch_on_merge: bool
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert homepage is github.GithubObject.NotSet or isinstance(
homepage, str
), homepage
assert private is github.GithubObject.NotSet or isinstance(
private, bool
), private
assert has_issues is github.GithubObject.NotSet or isinstance(
has_issues, bool
), has_issues
assert has_wiki is github.GithubObject.NotSet or isinstance(
has_wiki, bool
), has_wiki
assert has_downloads is github.GithubObject.NotSet or isinstance(
has_downloads, bool
), has_downloads
assert has_projects is github.GithubObject.NotSet or isinstance(
has_projects, bool
), has_projects
assert team_id is github.GithubObject.NotSet or isinstance(
team_id, int
), team_id
assert auto_init is github.GithubObject.NotSet or isinstance(
auto_init, bool
), auto_init
assert license_template is github.GithubObject.NotSet or isinstance(
license_template, str
), license_template
assert gitignore_template is github.GithubObject.NotSet or isinstance(
gitignore_template, str
), gitignore_template
assert allow_squash_merge is github.GithubObject.NotSet or isinstance(
allow_squash_merge, bool
), allow_squash_merge
assert allow_merge_commit is github.GithubObject.NotSet or isinstance(
allow_merge_commit, bool
), allow_merge_commit
assert allow_rebase_merge is github.GithubObject.NotSet or isinstance(
allow_rebase_merge, bool
), allow_rebase_merge
assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance(
delete_branch_on_merge, bool
), delete_branch_on_merge
post_parameters = {
"name": name,
}
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if homepage is not github.GithubObject.NotSet:
post_parameters["homepage"] = homepage
if private is not github.GithubObject.NotSet:
post_parameters["private"] = private
if has_issues is not github.GithubObject.NotSet:
post_parameters["has_issues"] = has_issues
if has_wiki is not github.GithubObject.NotSet:
post_parameters["has_wiki"] = has_wiki
if has_downloads is not github.GithubObject.NotSet:
post_parameters["has_downloads"] = has_downloads
if has_projects is not github.GithubObject.NotSet:
post_parameters["has_projects"] = has_projects
if team_id is not github.GithubObject.NotSet:
post_parameters["team_id"] = team_id
if auto_init is not github.GithubObject.NotSet:
post_parameters["auto_init"] = auto_init
if license_template is not github.GithubObject.NotSet:
post_parameters["license_template"] = license_template
if gitignore_template is not github.GithubObject.NotSet:
post_parameters["gitignore_template"] = gitignore_template
if allow_squash_merge is not github.GithubObject.NotSet:
post_parameters["allow_squash_merge"] = allow_squash_merge
if allow_merge_commit is not github.GithubObject.NotSet:
post_parameters["allow_merge_commit"] = allow_merge_commit
if allow_rebase_merge is not github.GithubObject.NotSet:
post_parameters["allow_rebase_merge"] = allow_rebase_merge
if delete_branch_on_merge is not github.GithubObject.NotSet:
post_parameters["delete_branch_on_merge"] = delete_branch_on_merge
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/repos", input=post_parameters
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
def create_team(
self,
name,
repo_names=github.GithubObject.NotSet,
permission=github.GithubObject.NotSet,
privacy=github.GithubObject.NotSet,
description=github.GithubObject.NotSet,
):
"""
:calls: `POST /orgs/{org}/teams <http://docs.github.com/en/rest/reference/orgs#teams>`_
:param name: string
:param repo_names: list of :class:`github.Repository.Repository`
:param permission: string
:param privacy: string
:param description: string
:rtype: :class:`github.Team.Team`
"""
assert isinstance(name, str), name
assert repo_names is github.GithubObject.NotSet or all(
isinstance(element, github.Repository.Repository) for element in repo_names
), repo_names
assert permission is github.GithubObject.NotSet or isinstance(
permission, str
), permission
assert privacy is github.GithubObject.NotSet or isinstance(
privacy, str
), privacy
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
post_parameters = {
"name": name,
}
if repo_names is not github.GithubObject.NotSet:
post_parameters["repo_names"] = [
element._identity for element in repo_names
]
if permission is not github.GithubObject.NotSet:
post_parameters["permission"] = permission
if privacy is not github.GithubObject.NotSet:
post_parameters["privacy"] = privacy
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/teams", input=post_parameters
)
return github.Team.Team(self._requester, headers, data, completed=True)
def delete_hook(self, id):
"""
:calls: `DELETE /orgs/{owner}/hooks/{id} <http://docs.github.com/en/rest/reference/orgs#hooks>`_
:param id: integer
:rtype: None`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/hooks/{id}"
)
def edit(
self,
billing_email=github.GithubObject.NotSet,
blog=github.GithubObject.NotSet,
company=github.GithubObject.NotSet,
description=github.GithubObject.NotSet,
email=github.GithubObject.NotSet,
location=github.GithubObject.NotSet,
name=github.GithubObject.NotSet,
):
"""
:calls: `PATCH /orgs/{org} <http://docs.github.com/en/rest/reference/orgs>`_
:param billing_email: string
:param blog: string
:param company: string
:param description: string
:param email: string
:param location: string
:param name: string
:rtype: None
"""
assert billing_email is github.GithubObject.NotSet or isinstance(
billing_email, str
), billing_email
assert blog is github.GithubObject.NotSet or isinstance(blog, str), blog
assert company is github.GithubObject.NotSet or isinstance(
company, str
), company
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert email is github.GithubObject.NotSet or isinstance(email, str), email
assert location is github.GithubObject.NotSet or isinstance(
location, str
), location
assert name is github.GithubObject.NotSet or isinstance(name, str), name
post_parameters = dict()
if billing_email is not github.GithubObject.NotSet:
post_parameters["billing_email"] = billing_email
if blog is not github.GithubObject.NotSet:
post_parameters["blog"] = blog
if company is not github.GithubObject.NotSet:
post_parameters["company"] = company
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if email is not github.GithubObject.NotSet:
post_parameters["email"] = email
if location is not github.GithubObject.NotSet:
post_parameters["location"] = location
if name is not github.GithubObject.NotSet:
post_parameters["name"] = name
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
self._useAttributes(data)
def edit_hook(
self,
id,
name,
config,
events=github.GithubObject.NotSet,
active=github.GithubObject.NotSet,
):
"""
:calls: `PATCH /orgs/{owner}/hooks/{id} <http://docs.github.com/en/rest/reference/orgs#hooks>`_
:param id: integer
:param name: string
:param config: dict
:param events: list of string
:param active: bool
:rtype: :class:`github.Hook.Hook`
"""
assert isinstance(id, int), id
assert isinstance(name, str), name
assert isinstance(config, dict), config
assert events is github.GithubObject.NotSet or all(
isinstance(element, str) for element in events
), events
assert active is github.GithubObject.NotSet or isinstance(active, bool), active
post_parameters = {
"name": name,
"config": config,
}
if events is not github.GithubObject.NotSet:
post_parameters["events"] = events
if active is not github.GithubObject.NotSet:
post_parameters["active"] = active
headers, data = self._requester.requestJsonAndCheck(
"PATCH", f"{self.url}/hooks/{id}", input=post_parameters
)
return github.Hook.Hook(self._requester, headers, data, completed=True)
def get_events(self):
"""
:calls: `GET /orgs/{org}/events <http://docs.github.com/en/rest/reference/activity#events>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
"""
return github.PaginatedList.PaginatedList(
github.Event.Event, self._requester, f"{self.url}/events", None
)
def get_hook(self, id):
"""
:calls: `GET /orgs/{owner}/hooks/{id} <http://docs.github.com/en/rest/reference/orgs#hooks>`_
:param id: integer
:rtype: :class:`github.Hook.Hook`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/hooks/{id}"
)
return github.Hook.Hook(self._requester, headers, data, completed=True)
def get_hooks(self):
"""
:calls: `GET /orgs/{owner}/hooks <http://docs.github.com/en/rest/reference/orgs#hooks>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook`
"""
return github.PaginatedList.PaginatedList(
github.Hook.Hook, self._requester, f"{self.url}/hooks", None
)
def get_issues(
self,
filter=github.GithubObject.NotSet,
state=github.GithubObject.NotSet,
labels=github.GithubObject.NotSet,
sort=github.GithubObject.NotSet,
direction=github.GithubObject.NotSet,
since=github.GithubObject.NotSet,
):
"""
:calls: `GET /orgs/{org}/issues <http://docs.github.com/en/rest/reference/issues>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
:param filter: string
:param state: string
:param labels: list of :class:`github.Label.Label`
:param sort: string
:param direction: string
:param since: datetime.datetime
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
"""
assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter
assert state is github.GithubObject.NotSet or isinstance(state, str), state
assert labels is github.GithubObject.NotSet or all(
isinstance(element, github.Label.Label) for element in labels
), labels
assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort
assert direction is github.GithubObject.NotSet or isinstance(
direction, str
), direction
assert since is github.GithubObject.NotSet or isinstance(
since, datetime.datetime
), since
url_parameters = dict()
if filter is not github.GithubObject.NotSet:
url_parameters["filter"] = filter
if state is not github.GithubObject.NotSet:
url_parameters["state"] = state
if labels is not github.GithubObject.NotSet:
url_parameters["labels"] = ",".join(label.name for label in labels)
if sort is not github.GithubObject.NotSet:
url_parameters["sort"] = sort
if direction is not github.GithubObject.NotSet:
url_parameters["direction"] = direction
if since is not github.GithubObject.NotSet:
url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
return github.PaginatedList.PaginatedList(
github.Issue.Issue, self._requester, f"{self.url}/issues", url_parameters
)
def get_members(
self, filter_=github.GithubObject.NotSet, role=github.GithubObject.NotSet
):
"""
:calls: `GET /orgs/{org}/members <http://docs.github.com/en/rest/reference/orgs#members>`_
:param filter_: string
:param role: string
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
assert filter_ is github.GithubObject.NotSet or isinstance(
filter_, str
), filter_
assert role is github.GithubObject.NotSet or isinstance(role, str), role
url_parameters = {}
if filter_ is not github.GithubObject.NotSet:
url_parameters["filter"] = filter_
if role is not github.GithubObject.NotSet:
url_parameters["role"] = role
return github.PaginatedList.PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/members",
url_parameters,
)
def get_projects(self, state=github.GithubObject.NotSet):
"""
:calls: `GET /orgs/{org}/projects <https://docs.github.com/en/rest/reference/projects#list-organization-projects>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project`
:param state: string
"""
url_parameters = dict()
if state is not github.GithubObject.NotSet:
url_parameters["state"] = state
return github.PaginatedList.PaginatedList(
github.Project.Project,
self._requester,
f"{self.url}/projects",
url_parameters,
{"Accept": Consts.mediaTypeProjectsPreview},
)
def get_public_members(self):
"""
:calls: `GET /orgs/{org}/public_members <http://docs.github.com/en/rest/reference/orgs#members>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
return github.PaginatedList.PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/public_members",
None,
)
def get_outside_collaborators(self, filter_=github.GithubObject.NotSet):
"""
:calls: `GET /orgs/{org}/outside_collaborators <http://docs.github.com/en/rest/reference/orgs#outside_collaborators>`_
:param filter_: string
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
assert filter_ is github.GithubObject.NotSet or isinstance(
filter_, str
), filter_
url_parameters = {}
if filter_ is not github.GithubObject.NotSet:
url_parameters["filter"] = filter_
return github.PaginatedList.PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/outside_collaborators",
url_parameters,
)
def remove_outside_collaborator(self, collaborator):
"""
:calls: `DELETE /orgs/{org}/outside_collaborators/{username} <https://docs.github.com/en/rest/reference/orgs#outside_collaborators>`_
:param collaborator: :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(collaborator, github.NamedUser.NamedUser), collaborator
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/outside_collaborators/{collaborator._identity}"
)
def convert_to_outside_collaborator(self, member):
"""
:calls: `PUT /orgs/{org}/outside_collaborators/{username} <https://docs.github.com/en/rest/reference/orgs#outside_collaborators>`_
:param member: :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/outside_collaborators/{member._identity}"
)
def get_repo(self, name):
"""
:calls: `GET /repos/{owner}/{repo} <http://docs.github.com/en/rest/reference/repos>`_
:param name: string
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
headers, data = self._requester.requestJsonAndCheck(
"GET", f"/repos/{self.login}/{name}"
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
def get_repos(
self,
type=github.GithubObject.NotSet,
sort=github.GithubObject.NotSet,
direction=github.GithubObject.NotSet,
):
"""
:calls: `GET /orgs/{org}/repos <http://docs.github.com/en/rest/reference/repos>`_
:param type: string ('all', 'public', 'private', 'forks', 'sources', 'member')
:param sort: string ('created', 'updated', 'pushed', 'full_name')
:param direction: string ('asc', desc')
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
"""
assert type is github.GithubObject.NotSet or isinstance(type, str), type
assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort
assert direction is github.GithubObject.NotSet or isinstance(
direction, str
), direction
url_parameters = dict()
if type is not github.GithubObject.NotSet:
url_parameters["type"] = type
if sort is not github.GithubObject.NotSet:
url_parameters["sort"] = sort
if direction is not github.GithubObject.NotSet:
url_parameters["direction"] = direction
return github.PaginatedList.PaginatedList(
github.Repository.Repository,
self._requester,
f"{self.url}/repos",
url_parameters,
)
def get_team(self, id):
"""
:calls: `GET /teams/{id} <http://docs.github.com/en/rest/reference/orgs#teams>`_
:param id: integer
:rtype: :class:`github.Team.Team`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck("GET", f"/teams/{id}")
return github.Team.Team(self._requester, headers, data, completed=True)
def get_team_by_slug(self, slug):
"""
:calls: `GET /orgs/{org}/teams/{team_slug} <https://docs.github.com/en/rest/reference/teams>`_
:param slug: string
:rtype: :class:`github.Team.Team`
"""
assert isinstance(slug, str), slug
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/teams/{slug}"
)
return github.Team.Team(self._requester, headers, data, completed=True)
def get_teams(self):
"""
:calls: `GET /orgs/{org}/teams <http://docs.github.com/en/rest/reference/orgs#teams>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team`
"""
return github.PaginatedList.PaginatedList(
github.Team.Team, self._requester, f"{self.url}/teams", None
)
def invitations(self):
"""
:calls: `GET /orgs/{org}/invitations <https://docs.github.com/en/rest/reference/orgs#members>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
return github.PaginatedList.PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/invitations",
None,
headers={"Accept": Consts.mediaTypeOrganizationInvitationPreview},
)
def invite_user(
self,
user=github.GithubObject.NotSet,
email=github.GithubObject.NotSet,
role=github.GithubObject.NotSet,
teams=github.GithubObject.NotSet,
):
"""
:calls: `POST /orgs/{org}/invitations <http://docs.github.com/en/rest/reference/orgs#members>`_
:param user: :class:`github.NamedUser.NamedUser`
:param email: string
:param role: string
:param teams: array of :class:`github.Team.Team`
:rtype: None
"""
assert user is github.GithubObject.NotSet or isinstance(
user, github.NamedUser.NamedUser
), user
assert email is github.GithubObject.NotSet or isinstance(email, str), email
assert (email is github.GithubObject.NotSet) ^ (
user is github.GithubObject.NotSet
), "specify only one of email or user"
parameters = {}
if user is not github.GithubObject.NotSet:
parameters["invitee_id"] = user.id
elif email is not github.GithubObject.NotSet:
parameters["email"] = email
if role is not github.GithubObject.NotSet:
assert isinstance(role, str), role
assert role in ["admin", "direct_member", "billing_manager"]
parameters["role"] = role
if teams is not github.GithubObject.NotSet:
assert all(isinstance(team, github.Team.Team) for team in teams)
parameters["team_ids"] = [t.id for t in teams]
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"{self.url}/invitations",
headers={"Accept": Consts.mediaTypeOrganizationInvitationPreview},
input=parameters,
)
def has_in_members(self, member):
"""
:calls: `GET /orgs/{org}/members/{user} <http://docs.github.com/en/rest/reference/orgs#members>`_
:param member: :class:`github.NamedUser.NamedUser`
:rtype: bool
"""
assert isinstance(member, github.NamedUser.NamedUser), member
status, headers, data = self._requester.requestJson(
"GET", f"{self.url}/members/{member._identity}"
)
if status == 302:
status, headers, data = self._requester.requestJson(
"GET", headers["location"]
)
return status == 204
def has_in_public_members(self, public_member):
"""
:calls: `GET /orgs/{org}/public_members/{user} <http://docs.github.com/en/rest/reference/orgs#members>`_
:param public_member: :class:`github.NamedUser.NamedUser`
:rtype: bool
"""
assert isinstance(public_member, github.NamedUser.NamedUser), public_member
status, headers, data = self._requester.requestJson(
"GET", f"{self.url}/public_members/{public_member._identity}"
)
return status == 204
def remove_from_membership(self, member):
"""
:calls: `DELETE /orgs/{org}/memberships/{user} <https://docs.github.com/en/rest/reference/orgs/members#remove-organization-membership>`_
:param member: :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/memberships/{member._identity}"
)
def remove_from_members(self, member):
"""
:calls: `DELETE /orgs/{org}/members/{user} <http://docs.github.com/en/rest/reference/orgs#members>`_
:param member: :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/members/{member._identity}"
)
def remove_from_public_members(self, public_member):
"""
:calls: `DELETE /orgs/{org}/public_members/{user} <http://docs.github.com/en/rest/reference/orgs#members>`_
:param public_member: :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(public_member, github.NamedUser.NamedUser), public_member
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/public_members/{public_member._identity}"
)
def create_migration(
self,
repos,
lock_repositories=github.GithubObject.NotSet,
exclude_attachments=github.GithubObject.NotSet,
):
"""
:calls: `POST /orgs/{org}/migrations <https://docs.github.com/en/rest/reference/migrations#users>`_
:param repos: list or tuple of str
:param lock_repositories: bool
:param exclude_attachments: bool
:rtype: :class:`github.Migration.Migration`
"""
assert isinstance(repos, (list, tuple)), repos
assert all(isinstance(repo, str) for repo in repos), repos
assert lock_repositories is github.GithubObject.NotSet or isinstance(
lock_repositories, bool
), lock_repositories
assert exclude_attachments is github.GithubObject.NotSet or isinstance(
exclude_attachments, bool
), exclude_attachments
post_parameters = {"repositories": repos}
if lock_repositories is not github.GithubObject.NotSet:
post_parameters["lock_repositories"] = lock_repositories
if exclude_attachments is not github.GithubObject.NotSet:
post_parameters["exclude_attachments"] = exclude_attachments
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"/orgs/{self.login}/migrations",
input=post_parameters,
headers={"Accept": Consts.mediaTypeMigrationPreview},
)
return github.Migration.Migration(
self._requester, headers, data, completed=True
)
def get_migrations(self):
"""
:calls: `GET /orgs/{org}/migrations <https://docs.github.com/en/rest/reference/migrations#users>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Migration.Migration`
"""
return github.PaginatedList.PaginatedList(
github.Migration.Migration,
self._requester,
f"/orgs/{self.login}/migrations",
None,
headers={"Accept": Consts.mediaTypeMigrationPreview},
)
def get_installations(self):
"""
:calls: `GET /orgs/{org}/installations <https://docs.github.com/en/rest/reference/orgs#list-app-installations-for-an-organization>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Installation.Installation`
"""
return github.PaginatedList.PaginatedList(
github.Installation.Installation,
self._requester,
f"{self.url}/installations",
None,
None,
list_item="installations",
)
def _initAttributes(self):
self._default_repository_permission = github.GithubObject.NotSet
self._has_organization_projects = github.GithubObject.NotSet
self._has_repository_projects = github.GithubObject.NotSet
self._hooks_url = github.GithubObject.NotSet
self._issues_url = github.GithubObject.NotSet
self._members_can_create_repositories = github.GithubObject.NotSet
self._two_factor_requirement_enabled = github.GithubObject.NotSet
self._avatar_url = github.GithubObject.NotSet
self._billing_email = github.GithubObject.NotSet
self._blog = github.GithubObject.NotSet
self._collaborators = github.GithubObject.NotSet
self._company = github.GithubObject.NotSet
self._created_at = github.GithubObject.NotSet
self._description = github.GithubObject.NotSet
self._disk_usage = github.GithubObject.NotSet
self._email = github.GithubObject.NotSet
self._events_url = github.GithubObject.NotSet
self._followers = github.GithubObject.NotSet
self._following = github.GithubObject.NotSet
self._gravatar_id = github.GithubObject.NotSet
self._html_url = github.GithubObject.NotSet
self._id = github.GithubObject.NotSet
self._location = github.GithubObject.NotSet
self._login = github.GithubObject.NotSet
self._members_url = github.GithubObject.NotSet
self._name = github.GithubObject.NotSet
self._owned_private_repos = github.GithubObject.NotSet
self._plan = github.GithubObject.NotSet
self._private_gists = github.GithubObject.NotSet
self._public_gists = github.GithubObject.NotSet
self._public_members_url = github.GithubObject.NotSet
self._public_repos = github.GithubObject.NotSet
self._repos_url = github.GithubObject.NotSet
self._total_private_repos = github.GithubObject.NotSet
self._type = github.GithubObject.NotSet
self._updated_at = github.GithubObject.NotSet
self._url = github.GithubObject.NotSet
def _useAttributes(self, attributes):
if "avatar_url" in attributes: # pragma no branch
self._avatar_url = self._makeStringAttribute(attributes["avatar_url"])
if "billing_email" in attributes: # pragma no branch
self._billing_email = self._makeStringAttribute(attributes["billing_email"])
if "blog" in attributes: # pragma no branch
self._blog = self._makeStringAttribute(attributes["blog"])
if "collaborators" in attributes: # pragma no branch
self._collaborators = self._makeIntAttribute(attributes["collaborators"])
if "company" in attributes: # pragma no branch
self._company = self._makeStringAttribute(attributes["company"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "default_repository_permission" in attributes: # pragma no branch
self._default_repository_permission = self._makeStringAttribute(
attributes["default_repository_permission"]
)
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "disk_usage" in attributes: # pragma no branch
self._disk_usage = self._makeIntAttribute(attributes["disk_usage"])
if "email" in attributes: # pragma no branch
self._email = self._makeStringAttribute(attributes["email"])
if "events_url" in attributes: # pragma no branch
self._events_url = self._makeStringAttribute(attributes["events_url"])
if "followers" in attributes: # pragma no branch
self._followers = self._makeIntAttribute(attributes["followers"])
if "following" in attributes: # pragma no branch
self._following = self._makeIntAttribute(attributes["following"])
if "gravatar_id" in attributes: # pragma no branch
self._gravatar_id = self._makeStringAttribute(attributes["gravatar_id"])
if "has_organization_projects" in attributes: # pragma no branch
self._has_organization_projects = self._makeBoolAttribute(
attributes["has_organization_projects"]
)
if "has_repository_projects" in attributes: # pragma no branch
self._has_repository_projects = self._makeBoolAttribute(
attributes["has_repository_projects"]
)
if "hooks_url" in attributes: # pragma no branch
self._hooks_url = self._makeStringAttribute(attributes["hooks_url"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "issues_url" in attributes: # pragma no branch
self._issues_url = self._makeStringAttribute(attributes["issues_url"])
if "location" in attributes: # pragma no branch
self._location = self._makeStringAttribute(attributes["location"])
if "login" in attributes: # pragma no branch
self._login = self._makeStringAttribute(attributes["login"])
if "members_can_create_repositories" in attributes: # pragma no branch
self._members_can_create_repositories = self._makeBoolAttribute(
attributes["members_can_create_repositories"]
)
if "members_url" in attributes: # pragma no branch
self._members_url = self._makeStringAttribute(attributes["members_url"])
if "name" in attributes: # pragma no branch
self._name = self._makeStringAttribute(attributes["name"])
if "owned_private_repos" in attributes: # pragma no branch
self._owned_private_repos = self._makeIntAttribute(
attributes["owned_private_repos"]
)
if "plan" in attributes: # pragma no branch
self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"])
if "private_gists" in attributes: # pragma no branch
self._private_gists = self._makeIntAttribute(attributes["private_gists"])
if "public_gists" in attributes: # pragma no branch
self._public_gists = self._makeIntAttribute(attributes["public_gists"])
if "public_members_url" in attributes: # pragma no branch
self._public_members_url = self._makeStringAttribute(
attributes["public_members_url"]
)
if "public_repos" in attributes: # pragma no branch
self._public_repos = self._makeIntAttribute(attributes["public_repos"])
if "repos_url" in attributes: # pragma no branch
self._repos_url = self._makeStringAttribute(attributes["repos_url"])
if "total_private_repos" in attributes: # pragma no branch
self._total_private_repos = self._makeIntAttribute(
attributes["total_private_repos"]
)
if "two_factor_requirement_enabled" in attributes: # pragma no branch
self._two_factor_requirement_enabled = self._makeBoolAttribute(
attributes["two_factor_requirement_enabled"]
)
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
if "updated_at" in attributes: # pragma no branch
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
|