Repository.py
1 ############################ Copyrights and license ############################ 2 # # 3 # Copyright 2012 Christopher Gilbert <christopher.john.gilbert@gmail.com> # 4 # Copyright 2012 Steve English <steve.english@navetas.com> # 5 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # 6 # Copyright 2012 Zearin <zearin@gonk.net> # 7 # Copyright 2013 AKFish <akfish@gmail.com> # 8 # Copyright 2013 Adrian Petrescu <adrian.petrescu@maluuba.com> # 9 # Copyright 2013 Cameron White <cawhite@pdx.edu> # 10 # Copyright 2013 David Farr <david.farr@sap.com> # 11 # Copyright 2013 Mark Roddy <markroddy@gmail.com> # 12 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # 13 # Copyright 2013 martinqt <m.ki2@laposte.net> # 14 # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # 15 # Copyright 2015 Aaron Levine <allevin@sandia.gov> # 16 # Copyright 2015 Christopher Wilcox <git@crwilcox.com> # 17 # Copyright 2015 Dan Vanderkam <danvdk@gmail.com> # 18 # Copyright 2015 Ed Holland <eholland@alertlogic.com> # 19 # Copyright 2015 Enix Yu <enix223@163.com> # 20 # Copyright 2015 Jay <ja.geb@me.com> # 21 # Copyright 2015 Jimmy Zelinskie <jimmyzelinskie@gmail.com> # 22 # Copyright 2015 Jonathan Debonis <jon@ip-172-20-10-5.ec2.internal> # 23 # Copyright 2015 Kevin Lewandowski <kevinsl@gmail.com> # 24 # Copyright 2015 Kyle Hornberg <khornberg@users.noreply.github.com> # 25 # Copyright 2015 edhollandAL <eholland@alertlogic.com> # 26 # Copyright 2016 @tmshn <tmshn@r.recruit.co.jp> # 27 # Copyright 2016 Dustin Spicuzza <dustin@virtualroadside.com> # 28 # Copyright 2016 Enix Yu <enix223@163.com> # 29 # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # 30 # Copyright 2016 Per Øyvind Karlsen <proyvind@moondrake.org> # 31 # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # 32 # Copyright 2016 Sylvus <Sylvus@users.noreply.github.com> # 33 # Copyright 2016 fukatani <nannyakannya@gmail.com> # 34 # Copyright 2016 ghfan <gavintofan@gmail.com> # 35 # Copyright 2017 Andreas Lutro <anlutro@gmail.com> # 36 # Copyright 2017 Ben Firshman <ben@firshman.co.uk> # 37 # Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com> # 38 # Copyright 2017 Hugo <hugovk@users.noreply.github.com> # 39 # Copyright 2017 Jannis Gebauer <ja.geb@me.com> # 40 # Copyright 2017 Jason White <jasonwhite@users.noreply.github.com> # 41 # Copyright 2017 Jimmy Zelinskie <jimmy.zelinskie+git@gmail.com> # 42 # Copyright 2017 Nhomar Hernández [Vauxoo] <nhomar@vauxoo.com> # 43 # Copyright 2017 Simon <spam@esemi.ru> # 44 # Copyright 2018 Aaron L. Levine <allevin@sandia.gov> # 45 # Copyright 2018 AetherDeity <aetherdeity+github@gmail.com> # 46 # Copyright 2018 Alice GIRARD <bouhahah@gmail.com> # 47 # Copyright 2018 Andrew Smith <espadav8@gmail.com> # 48 # Copyright 2018 Benoit Latinier <benoit@latinier.fr> # 49 # Copyright 2018 Brian Torres-Gil <btorres-gil@paloaltonetworks.com> # 50 # Copyright 2018 Hayden Fuss <wifu1234@gmail.com> # 51 # Copyright 2018 Ilya Konstantinov <ilya.konstantinov@gmail.com> # 52 # Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> # 53 # Copyright 2018 John Hui <j-hui@users.noreply.github.com> # 54 # Copyright 2018 Justin Kufro <jkufro@andrew.cmu.edu> # 55 # Copyright 2018 Mateusz Loskot <mateusz@loskot.net> # 56 # Copyright 2018 Michael Behrisch <oss@behrisch.de> # 57 # Copyright 2018 Nicholas Buse <NicholasBuse@users.noreply.github.com> # 58 # Copyright 2018 Philip May <eniak.info@gmail.com> # 59 # Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> # 60 # Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> # 61 # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # 62 # Copyright 2018 Vinay Hegde <hegde.vi@husky.neu.edu> # 63 # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # 64 # Copyright 2018 Will Yardley <wyardley@users.noreply.github.com> # 65 # Copyright 2018 Yossarian King <yggy@blackbirdinteractive.com> # 66 # Copyright 2018 per1234 <accounts@perglass.com> # 67 # Copyright 2018 sechastain <sechastain@gmail.com> # 68 # Copyright 2018 sfdye <tsfdye@gmail.com> # 69 # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # 70 # Copyright 2019 Alex <alexmusa@users.noreply.github.com> # 71 # Copyright 2019 Kevin LaFlamme <k@lamfl.am> # 72 # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # 73 # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # 74 # Copyright 2019 Tim Gates <tim.gates@iress.com> # 75 # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # 76 # Copyright 2019 Will Li <cuichen.li94@gmail.com> # 77 # Copyright 2020 Alice GIRARD <bouhahah@gmail.com> # 78 # Copyright 2020 Anuj Bansal <bansalanuj1996@gmail.com> # 79 # Copyright 2020 Chris de Graaf <chrisadegraaf@gmail.com> # 80 # Copyright 2020 Dhruv Manilawala <dhruvmanila@gmail.com> # 81 # Copyright 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk> # 82 # Copyright 2020 Florent Clarret <florent.clarret@gmail.com> # 83 # Copyright 2020 Glenn McDonald <testworksau@users.noreply.github.com> # 84 # Copyright 2020 Huw Jones <huwcbjones@outlook.com> # 85 # Copyright 2020 Mark Bromell <markbromell.business@gmail.com> # 86 # Copyright 2020 Max Wittig <max.wittig@siemens.com> # 87 # Copyright 2020 Pascal Hofmann <mail@pascalhofmann.de> # 88 # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # 89 # Copyright 2020 Tim Gates <tim.gates@iress.com> # 90 # Copyright 2020 Victor Zeng <zacker150@users.noreply.github.com> # 91 # Copyright 2020 ton-katsu <sakamoto.yoshihisa@gmail.com> # 92 # Copyright 2021 Chris Keating <christopherkeating@gmail.com> # 93 # Copyright 2021 Floyd Hightower <floyd.hightower27@gmail.com> # 94 # Copyright 2021 Mark Walker <mark.walker@realbuzz.com> # 95 # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # 96 # Copyright 2021 Tanner <51724788+lightningboltemoji@users.noreply.github.com> # 97 # Copyright 2021 xmo-odoo <xmo@odoo.com> # 98 # Copyright 2022 Aleksei Fedotov <lexa@cfotr.com> # 99 # Copyright 2022 Eric Nieuwland <eric.nieuwland@gmail.com> # 100 # Copyright 2022 Ibrahim Hussaini <ibrahimhussainialias@outlook.com> # 101 # Copyright 2022 KimSia Sim <245021+simkimsia@users.noreply.github.com> # 102 # Copyright 2022 Marco Köpcke <hello@parakoopa.de> # 103 # Copyright 2022 Alson van der Meulen <alson.vandermeulen@dearhealth.com> # 104 # Copyright 2023 Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com> # 105 # Copyright 2023 Sol Redfern <59831933+Tsuesun@users.noreply.github.com> # 106 # Copyright 2023 Mikhail f. Shiryaev <mr.felixoid@gmail.com> # 107 # Copyright 2023 Mauricio Martinez <mauricio.martinez@premise.com> # 108 # Copyright 2023 Armen Martirosyan <armartirosyan@users.noreply.github.com> # 109 # Copyright 2023 DB Systel GmbH # 110 # # 111 # This file is part of PyGithub. # 112 # http://pygithub.readthedocs.io/ # 113 # # 114 # PyGithub is free software: you can redistribute it and/or modify it under # 115 # the terms of the GNU Lesser General Public License as published by the Free # 116 # Software Foundation, either version 3 of the License, or (at your option) # 117 # any later version. # 118 # # 119 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 120 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 121 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 122 # details. # 123 # # 124 # You should have received a copy of the GNU Lesser General Public License # 125 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 126 # # 127 ################################################################################ 128 from __future__ import annotations 129 130 import collections 131 import urllib.parse 132 from base64 import b64encode 133 from datetime import date, datetime, timezone 134 from typing import TYPE_CHECKING, Any, Iterable 135 136 from deprecated import deprecated 137 138 import github.Artifact 139 import github.Autolink 140 import github.Branch 141 import github.CheckRun 142 import github.CheckSuite 143 import github.Clones 144 import github.CodeScanAlert 145 import github.Commit 146 import github.CommitComment 147 import github.Comparison 148 import github.ContentFile 149 import github.Deployment 150 import github.Download 151 import github.Environment 152 import github.EnvironmentDeploymentBranchPolicy 153 import github.EnvironmentProtectionRule 154 import github.EnvironmentProtectionRuleReviewer 155 import github.Event 156 import github.GitBlob 157 import github.GitCommit 158 import github.GithubObject 159 import github.GitRef 160 import github.GitRelease 161 import github.GitReleaseAsset 162 import github.GitTag 163 import github.GitTree 164 import github.Hook 165 import github.HookDelivery 166 import github.Invitation 167 import github.Issue 168 import github.IssueEvent 169 import github.Label 170 import github.License 171 import github.Milestone 172 import github.NamedUser 173 import github.Organization 174 import github.PaginatedList 175 import github.Path 176 import github.Permissions 177 import github.Project 178 import github.PublicKey 179 import github.PullRequest 180 import github.Referrer 181 import github.RepositoryAdvisory 182 import github.RepositoryAdvisoryCredit 183 import github.RepositoryAdvisoryVulnerability 184 import github.RepositoryKey 185 import github.RepositoryPreferences 186 import github.Secret 187 import github.SelfHostedActionsRunner 188 import github.SourceImport 189 import github.Stargazer 190 import github.StatsCodeFrequency 191 import github.StatsCommitActivity 192 import github.StatsContributor 193 import github.StatsParticipation 194 import github.StatsPunchCard 195 import github.Tag 196 import github.Team 197 import github.Variable 198 import github.View 199 import github.Workflow 200 import github.WorkflowRun 201 from github import Consts 202 from github.GithubObject import ( 203 Attribute, 204 CompletableGithubObject, 205 NotSet, 206 Opt, 207 _NotSetType, 208 is_defined, 209 is_optional, 210 is_optional_list, 211 is_undefined, 212 ) 213 from github.PaginatedList import PaginatedList 214 215 if TYPE_CHECKING: 216 from github.Artifact import Artifact 217 from github.AuthenticatedUser import AuthenticatedUser 218 from github.Autolink import Autolink 219 from github.Branch import Branch 220 from github.CheckRun import CheckRun 221 from github.CheckSuite import CheckSuite 222 from github.Clones import Clones 223 from github.CodeScanAlert import CodeScanAlert 224 from github.Commit import Commit 225 from github.CommitComment import CommitComment 226 from github.Comparison import Comparison 227 from github.ContentFile import ContentFile 228 from github.Deployment import Deployment 229 from github.Download import Download 230 from github.Environment import Environment 231 from github.EnvironmentDeploymentBranchPolicy import EnvironmentDeploymentBranchPolicyParams 232 from github.EnvironmentProtectionRuleReviewer import ReviewerParams 233 from github.Event import Event 234 from github.GitBlob import GitBlob 235 from github.GitCommit import GitCommit 236 from github.GitRef import GitRef 237 from github.GitRelease import GitRelease 238 from github.GitReleaseAsset import GitReleaseAsset 239 from github.GitTag import GitTag 240 from github.GitTree import GitTree 241 from github.Hook import Hook 242 from github.InputGitAuthor import InputGitAuthor 243 from github.InputGitTreeElement import InputGitTreeElement 244 from github.Invitation import Invitation 245 from github.Issue import Issue 246 from github.IssueComment import IssueComment 247 from github.IssueEvent import IssueEvent 248 from github.Label import Label 249 from github.License import License 250 from github.Milestone import Milestone 251 from github.NamedUser import NamedUser 252 from github.Notification import Notification 253 from github.Organization import Organization 254 from github.Path import Path 255 from github.Permissions import Permissions 256 from github.Project import Project 257 from github.PublicKey import PublicKey 258 from github.PullRequest import PullRequest 259 from github.PullRequestComment import PullRequestComment 260 from github.Referrer import Referrer 261 from github.RepositoryKey import RepositoryKey 262 from github.RepositoryPreferences import RepositoryPreferences 263 from github.SelfHostedActionsRunner import SelfHostedActionsRunner 264 from github.SourceImport import SourceImport 265 from github.Stargazer import Stargazer 266 from github.StatsCodeFrequency import StatsCodeFrequency 267 from github.StatsCommitActivity import StatsCommitActivity 268 from github.StatsContributor import StatsContributor 269 from github.StatsParticipation import StatsParticipation 270 from github.StatsPunchCard import StatsPunchCard 271 from github.Tag import Tag 272 from github.Team import Team 273 from github.View import View 274 from github.Workflow import Workflow 275 from github.WorkflowRun import WorkflowRun 276 277 278 class Repository(CompletableGithubObject): 279 """ 280 This class represents Repositories. The reference can be found here https://docs.github.com/en/rest/reference/repos 281 """ 282 283 def __repr__(self) -> str: 284 return self.get__repr__({"full_name": self._full_name.value}) 285 286 @property 287 def allow_auto_merge(self) -> bool: 288 """ 289 :type: bool 290 """ 291 self._completeIfNotSet(self._allow_auto_merge) 292 return self._allow_auto_merge.value 293 294 @property 295 def allow_forking(self) -> bool: 296 """ 297 :type: bool 298 """ 299 self._completeIfNotSet(self._allow_forking) 300 return self._allow_forking.value 301 302 @property 303 def allow_merge_commit(self) -> bool: 304 """ 305 :type: bool 306 """ 307 self._completeIfNotSet(self._allow_merge_commit) 308 return self._allow_merge_commit.value 309 310 @property 311 def allow_rebase_merge(self) -> bool: 312 """ 313 :type: bool 314 """ 315 self._completeIfNotSet(self._allow_rebase_merge) 316 return self._allow_rebase_merge.value 317 318 @property 319 def allow_squash_merge(self) -> bool: 320 """ 321 :type: bool 322 """ 323 self._completeIfNotSet(self._allow_squash_merge) 324 return self._allow_squash_merge.value 325 326 @property 327 def allow_update_branch(self) -> bool: 328 """ 329 :type: bool 330 """ 331 self._completeIfNotSet(self._allow_update_branch) 332 return self._allow_update_branch.value 333 334 @property 335 def archived(self) -> bool: 336 """ 337 :type: bool 338 """ 339 self._completeIfNotSet(self._archived) 340 return self._archived.value 341 342 @property 343 def archive_url(self) -> str: 344 """ 345 :type: string 346 """ 347 self._completeIfNotSet(self._archive_url) 348 return self._archive_url.value 349 350 @property 351 def assignees_url(self) -> str: 352 """ 353 :type: string 354 """ 355 self._completeIfNotSet(self._assignees_url) 356 return self._assignees_url.value 357 358 @property 359 def blobs_url(self) -> str: 360 """ 361 :type: string 362 """ 363 self._completeIfNotSet(self._blobs_url) 364 return self._blobs_url.value 365 366 @property 367 def branches_url(self) -> str: 368 """ 369 :type: string 370 """ 371 self._completeIfNotSet(self._branches_url) 372 return self._branches_url.value 373 374 @property 375 def clone_url(self) -> str: 376 """ 377 :type: string 378 """ 379 self._completeIfNotSet(self._clone_url) 380 return self._clone_url.value 381 382 @property 383 def collaborators_url(self) -> str: 384 """ 385 :type: string 386 """ 387 self._completeIfNotSet(self._collaborators_url) 388 return self._collaborators_url.value 389 390 @property 391 def comments_url(self) -> str: 392 """ 393 :type: string 394 """ 395 self._completeIfNotSet(self._comments_url) 396 return self._comments_url.value 397 398 @property 399 def commits_url(self) -> str: 400 """ 401 :type: string 402 """ 403 self._completeIfNotSet(self._commits_url) 404 return self._commits_url.value 405 406 @property 407 def compare_url(self) -> str: 408 """ 409 :type: string 410 """ 411 self._completeIfNotSet(self._compare_url) 412 return self._compare_url.value 413 414 @property 415 def contents_url(self) -> str: 416 """ 417 :type: string 418 """ 419 self._completeIfNotSet(self._contents_url) 420 return self._contents_url.value 421 422 @property 423 def contributors_url(self) -> str: 424 """ 425 :type: string 426 """ 427 self._completeIfNotSet(self._contributors_url) 428 return self._contributors_url.value 429 430 @property 431 def created_at(self) -> datetime: 432 """ 433 :type: datetime 434 """ 435 self._completeIfNotSet(self._created_at) 436 return self._created_at.value 437 438 @property 439 def default_branch(self) -> str: 440 """ 441 :type: string 442 """ 443 self._completeIfNotSet(self._default_branch) 444 return self._default_branch.value 445 446 @property 447 def delete_branch_on_merge(self) -> bool: 448 """ 449 :type: bool 450 """ 451 self._completeIfNotSet(self._delete_branch_on_merge) 452 return self._delete_branch_on_merge.value 453 454 @property 455 def deployments_url(self) -> str: 456 """ 457 :type: string 458 """ 459 self._completeIfNotSet(self._deployments_url) 460 return self._deployments_url.value 461 462 @property 463 def description(self) -> str: 464 """ 465 :type: string 466 """ 467 self._completeIfNotSet(self._description) 468 return self._description.value 469 470 @property 471 def downloads_url(self) -> str: 472 """ 473 :type: string 474 """ 475 self._completeIfNotSet(self._downloads_url) 476 return self._downloads_url.value 477 478 @property 479 def events_url(self) -> str: 480 """ 481 :type: string 482 """ 483 self._completeIfNotSet(self._events_url) 484 return self._events_url.value 485 486 @property 487 def fork(self) -> bool: 488 """ 489 :type: bool 490 """ 491 self._completeIfNotSet(self._fork) 492 return self._fork.value 493 494 @property 495 def forks(self) -> int: 496 """ 497 :type: integer 498 """ 499 self._completeIfNotSet(self._forks) 500 return self._forks.value 501 502 @property 503 def forks_count(self) -> int: 504 """ 505 :type: integer 506 """ 507 self._completeIfNotSet(self._forks_count) 508 return self._forks_count.value 509 510 @property 511 def forks_url(self) -> str: 512 """ 513 :type: string 514 """ 515 self._completeIfNotSet(self._forks_url) 516 return self._forks_url.value 517 518 @property 519 def full_name(self) -> str: 520 """ 521 :type: string 522 """ 523 self._completeIfNotSet(self._full_name) 524 return self._full_name.value 525 526 @property 527 def git_commits_url(self) -> str: 528 """ 529 :type: string 530 """ 531 self._completeIfNotSet(self._git_commits_url) 532 return self._git_commits_url.value 533 534 @property 535 def git_refs_url(self) -> str: 536 """ 537 :type: string 538 """ 539 self._completeIfNotSet(self._git_refs_url) 540 return self._git_refs_url.value 541 542 @property 543 def git_tags_url(self) -> str: 544 """ 545 :type: string 546 """ 547 self._completeIfNotSet(self._git_tags_url) 548 return self._git_tags_url.value 549 550 @property 551 def git_url(self) -> str: 552 """ 553 :type: string 554 """ 555 self._completeIfNotSet(self._git_url) 556 return self._git_url.value 557 558 @property 559 def has_downloads(self) -> bool: 560 """ 561 :type: bool 562 """ 563 self._completeIfNotSet(self._has_downloads) 564 return self._has_downloads.value 565 566 @property 567 def has_issues(self) -> bool: 568 """ 569 :type: bool 570 """ 571 self._completeIfNotSet(self._has_issues) 572 return self._has_issues.value 573 574 @property 575 def has_pages(self) -> bool: 576 """ 577 :type: bool 578 """ 579 self._completeIfNotSet(self._has_pages) 580 return self._has_pages.value 581 582 @property 583 def has_projects(self) -> bool: 584 """ 585 :type: bool 586 """ 587 self._completeIfNotSet(self._has_projects) 588 return self._has_projects.value 589 590 @property 591 def has_wiki(self) -> bool: 592 """ 593 :type: bool 594 """ 595 self._completeIfNotSet(self._has_wiki) 596 return self._has_wiki.value 597 598 @property 599 def homepage(self) -> str: 600 """ 601 :type: string 602 """ 603 self._completeIfNotSet(self._homepage) 604 return self._homepage.value 605 606 @property 607 def hooks_url(self) -> str: 608 """ 609 :type: string 610 """ 611 self._completeIfNotSet(self._hooks_url) 612 return self._hooks_url.value 613 614 @property 615 def html_url(self) -> str: 616 """ 617 :type: string 618 """ 619 self._completeIfNotSet(self._html_url) 620 return self._html_url.value 621 622 @property 623 def id(self) -> int: 624 """ 625 :type: integer 626 """ 627 self._completeIfNotSet(self._id) 628 return self._id.value 629 630 @property 631 def is_template(self) -> bool: 632 """ 633 :type: bool 634 """ 635 self._completeIfNotSet(self._is_template) 636 return self._is_template.value 637 638 @property 639 def issue_comment_url(self) -> str: 640 """ 641 :type: string 642 """ 643 self._completeIfNotSet(self._issue_comment_url) 644 return self._issue_comment_url.value 645 646 @property 647 def issue_events_url(self) -> str: 648 """ 649 :type: string 650 """ 651 self._completeIfNotSet(self._issue_events_url) 652 return self._issue_events_url.value 653 654 @property 655 def issues_url(self) -> str: 656 """ 657 :type: string 658 """ 659 self._completeIfNotSet(self._issues_url) 660 return self._issues_url.value 661 662 @property 663 def keys_url(self) -> str: 664 """ 665 :type: string 666 """ 667 self._completeIfNotSet(self._keys_url) 668 return self._keys_url.value 669 670 @property 671 def labels_url(self) -> str: 672 """ 673 :type: string 674 """ 675 self._completeIfNotSet(self._labels_url) 676 return self._labels_url.value 677 678 @property 679 def language(self) -> str: 680 """ 681 :type: string 682 """ 683 self._completeIfNotSet(self._language) 684 return self._language.value 685 686 @property 687 def languages_url(self) -> str: 688 """ 689 :type: string 690 """ 691 self._completeIfNotSet(self._languages_url) 692 return self._languages_url.value 693 694 @property 695 def license(self) -> License: 696 self._completeIfNotSet(self._license) 697 return self._license.value 698 699 @property 700 def master_branch(self) -> str: 701 self._completeIfNotSet(self._master_branch) 702 return self._master_branch.value 703 704 @property 705 def merge_commit_message(self) -> str: 706 """ 707 :type: string 708 """ 709 self._completeIfNotSet(self._merge_commit_message) 710 return self._merge_commit_message.value 711 712 @property 713 def merge_commit_title(self) -> str: 714 """ 715 :type: string 716 """ 717 self._completeIfNotSet(self._merge_commit_title) 718 return self._merge_commit_title.value 719 720 @property 721 def merges_url(self) -> str: 722 """ 723 :type: string 724 """ 725 self._completeIfNotSet(self._merges_url) 726 return self._merges_url.value 727 728 @property 729 def milestones_url(self) -> str: 730 """ 731 :type: string 732 """ 733 self._completeIfNotSet(self._milestones_url) 734 return self._milestones_url.value 735 736 @property 737 def mirror_url(self) -> str: 738 """ 739 :type: string 740 """ 741 self._completeIfNotSet(self._mirror_url) 742 return self._mirror_url.value 743 744 @property 745 def name(self) -> str: 746 """ 747 :type: string 748 """ 749 self._completeIfNotSet(self._name) 750 return self._name.value 751 752 @property 753 def network_count(self) -> int: 754 """ 755 :type: integer 756 """ 757 self._completeIfNotSet(self._network_count) 758 return self._network_count.value 759 760 @property 761 def notifications_url(self) -> str: 762 """ 763 :type: string 764 """ 765 self._completeIfNotSet(self._notifications_url) 766 return self._notifications_url.value 767 768 @property 769 def open_issues(self) -> int: 770 """ 771 :type: integer 772 """ 773 self._completeIfNotSet(self._open_issues) 774 return self._open_issues.value 775 776 @property 777 def open_issues_count(self) -> int: 778 """ 779 :type: integer 780 """ 781 self._completeIfNotSet(self._open_issues_count) 782 return self._open_issues_count.value 783 784 @property 785 def organization(self) -> Organization: 786 """ 787 :type: :class:`github.Organization.Organization` 788 """ 789 self._completeIfNotSet(self._organization) 790 return self._organization.value 791 792 @property 793 def owner(self) -> NamedUser: 794 """ 795 :type: :class:`github.NamedUser.NamedUser` 796 """ 797 self._completeIfNotSet(self._owner) 798 return self._owner.value 799 800 @property 801 def parent(self) -> Repository: 802 """ 803 :type: :class:`github.Repository.Repository` 804 """ 805 self._completeIfNotSet(self._parent) 806 return self._parent.value 807 808 @property 809 def permissions(self) -> Permissions: 810 """ 811 :type: :class:`github.Permissions.Permissions` 812 """ 813 self._completeIfNotSet(self._permissions) 814 return self._permissions.value 815 816 @property 817 def private(self) -> bool: 818 """ 819 :type: bool 820 """ 821 self._completeIfNotSet(self._private) 822 return self._private.value 823 824 @property 825 def pulls_url(self) -> str: 826 """ 827 :type: string 828 """ 829 self._completeIfNotSet(self._pulls_url) 830 return self._pulls_url.value 831 832 @property 833 def pushed_at(self) -> datetime: 834 """ 835 :type: datetime 836 """ 837 self._completeIfNotSet(self._pushed_at) 838 return self._pushed_at.value 839 840 @property 841 def releases_url(self) -> str: 842 """ 843 :type: string 844 """ 845 self._completeIfNotSet(self._releases_url) 846 return self._releases_url.value 847 848 @property 849 def size(self) -> int: 850 """ 851 :type: integer 852 """ 853 self._completeIfNotSet(self._size) 854 return self._size.value 855 856 @property 857 def source(self) -> Repository | None: 858 """ 859 :type: :class:`github.Repository.Repository` 860 """ 861 self._completeIfNotSet(self._source) 862 return self._source.value 863 864 @property 865 def squash_merge_commit_message(self) -> str: 866 """ 867 :type: string 868 """ 869 self._completeIfNotSet(self._squash_merge_commit_message) 870 return self._squash_merge_commit_message.value 871 872 @property 873 def squash_merge_commit_title(self) -> str: 874 """ 875 :type: string 876 """ 877 self._completeIfNotSet(self._squash_merge_commit_title) 878 return self._squash_merge_commit_title.value 879 880 @property 881 def ssh_url(self) -> str: 882 """ 883 :type: string 884 """ 885 self._completeIfNotSet(self._ssh_url) 886 return self._ssh_url.value 887 888 @property 889 def stargazers_count(self) -> int: 890 """ 891 :type: integer 892 """ 893 self._completeIfNotSet(self._stargazers_count) # pragma no cover (Should be covered) 894 return self._stargazers_count.value # pragma no cover (Should be covered) 895 896 @property 897 def stargazers_url(self) -> str: 898 """ 899 :type: string 900 """ 901 self._completeIfNotSet(self._stargazers_url) 902 return self._stargazers_url.value 903 904 @property 905 def statuses_url(self) -> str: 906 """ 907 :type: string 908 """ 909 self._completeIfNotSet(self._statuses_url) 910 return self._statuses_url.value 911 912 @property 913 def subscribers_url(self) -> str: 914 """ 915 :type: string 916 """ 917 self._completeIfNotSet(self._subscribers_url) 918 return self._subscribers_url.value 919 920 @property 921 def subscribers_count(self) -> int: 922 """ 923 :type: integer 924 """ 925 self._completeIfNotSet(self._subscribers_count) 926 return self._subscribers_count.value 927 928 @property 929 def subscription_url(self) -> str: 930 """ 931 :type: string 932 """ 933 self._completeIfNotSet(self._subscription_url) 934 return self._subscription_url.value 935 936 @property 937 def svn_url(self) -> str: 938 """ 939 :type: string 940 """ 941 self._completeIfNotSet(self._svn_url) 942 return self._svn_url.value 943 944 @property 945 def tags_url(self) -> str: 946 """ 947 :type: string 948 """ 949 self._completeIfNotSet(self._tags_url) 950 return self._tags_url.value 951 952 @property 953 def teams_url(self) -> str: 954 """ 955 :type: string 956 """ 957 self._completeIfNotSet(self._teams_url) 958 return self._teams_url.value 959 960 @property 961 def topics(self) -> list[str]: 962 """ 963 :type: list of strings 964 """ 965 self._completeIfNotSet(self._topics) 966 return self._topics.value 967 968 @property 969 def trees_url(self) -> str: 970 """ 971 :type: string 972 """ 973 self._completeIfNotSet(self._trees_url) 974 return self._trees_url.value 975 976 @property 977 def updated_at(self) -> datetime: 978 """ 979 :type: datetime 980 """ 981 self._completeIfNotSet(self._updated_at) 982 return self._updated_at.value 983 984 @property 985 def url(self) -> str: 986 self._completeIfNotSet(self._url) 987 return self._url.value 988 989 @property 990 def use_squash_pr_title_as_default(self) -> bool: 991 self._completeIfNotSet(self._use_squash_pr_title_as_default) 992 return self._use_squash_pr_title_as_default.value 993 994 @property 995 def visibility(self) -> str: 996 self._completeIfNotSet(self._visibility) 997 return self._visibility.value 998 999 @property 1000 def watchers(self) -> int: 1001 self._completeIfNotSet(self._watchers) 1002 return self._watchers.value 1003 1004 @property 1005 def watchers_count(self) -> int: 1006 self._completeIfNotSet(self._watchers_count) 1007 return self._watchers_count.value 1008 1009 @property 1010 def web_commit_signoff_required(self) -> bool: 1011 """ 1012 :type: bool 1013 """ 1014 self._completeIfNotSet(self._web_commit_signoff_required) 1015 return self._web_commit_signoff_required.value 1016 1017 def add_to_collaborators(self, collaborator: str | NamedUser, permission: Opt[str] = NotSet) -> Invitation | None: 1018 """ 1019 :calls: `PUT /repos/{owner}/{repo}/collaborators/{user} <https://docs.github.com/en/rest/reference/repos#collaborators>`_ 1020 :param permission: string 'pull', 'push' or 'admin' 1021 """ 1022 assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, str), collaborator 1023 assert is_undefined(permission) or isinstance(permission, str), permission 1024 1025 if isinstance(collaborator, github.NamedUser.NamedUser): 1026 collaborator = collaborator._identity 1027 1028 if is_defined(permission): 1029 put_parameters = {"permission": permission} 1030 else: 1031 put_parameters = None 1032 1033 headers, data = self._requester.requestJsonAndCheck( 1034 "PUT", f"{self.url}/collaborators/{collaborator}", input=put_parameters 1035 ) 1036 # return an invitation object if there's data returned by the API. If data is empty 1037 # there's a pending invitation for the given user. 1038 return ( 1039 github.Invitation.Invitation(self._requester, headers, data, completed=True) if data is not None else None 1040 ) 1041 1042 def get_collaborator_permission(self, collaborator: str | NamedUser) -> str: 1043 """ 1044 :calls: `GET /repos/{owner}/{repo}/collaborators/{username}/permission <https://docs.github.com/en/rest/reference/repos#collaborators>`_ 1045 :param collaborator: string or :class:`github.NamedUser.NamedUser` 1046 :rtype: string 1047 """ 1048 assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, str), collaborator 1049 if isinstance(collaborator, github.NamedUser.NamedUser): 1050 collaborator = collaborator._identity 1051 headers, data = self._requester.requestJsonAndCheck( 1052 "GET", 1053 f"{self.url}/collaborators/{collaborator}/permission", 1054 ) 1055 return data["permission"] 1056 1057 def get_pending_invitations(self) -> PaginatedList[Invitation]: 1058 """ 1059 :calls: `GET /repos/{owner}/{repo}/invitations <https://docs.github.com/en/rest/reference/repos#invitations>`_ 1060 :rtype: :class:`PaginatedList` of :class:`github.Invitation.Invitation` 1061 """ 1062 return PaginatedList( 1063 github.Invitation.Invitation, 1064 self._requester, 1065 f"{self.url}/invitations", 1066 None, 1067 ) 1068 1069 def remove_invitation(self, invite_id: int) -> None: 1070 """ 1071 :calls: `DELETE /repos/{owner}/{repo}/invitations/{invitation_id} <https://docs.github.com/en/rest/reference/repos#invitations>`_ 1072 :rtype: None 1073 """ 1074 assert isinstance(invite_id, int), invite_id 1075 1076 headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/invitations/{invite_id}") 1077 1078 def compare(self, base: str, head: str) -> Comparison: 1079 """ 1080 :calls: `GET /repos/{owner}/{repo}/compare/{base...:head} <https://docs.github.com/en/rest/reference/repos#commits>`_ 1081 :param base: string 1082 :param head: string 1083 :rtype: :class:`github.Comparison.Comparison` 1084 """ 1085 assert isinstance(base, str), base 1086 assert isinstance(head, str), head 1087 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/compare/{base}...{head}") 1088 return github.Comparison.Comparison(self._requester, headers, data, completed=True) 1089 1090 def create_autolink( 1091 self, key_prefix: str, url_template: str, is_alphanumeric: Opt[bool] = NotSet 1092 ) -> github.Autolink.Autolink: 1093 """ 1094 :calls: `POST /repos/{owner}/{repo}/autolinks <http://docs.github.com/en/rest/reference/repos>`_ 1095 :param key_prefix: string 1096 :param url_template: string 1097 :param is_alphanumeric: bool 1098 :rtype: :class:`github.Autolink.Autolink` 1099 """ 1100 assert isinstance(key_prefix, str), key_prefix 1101 assert isinstance(url_template, str), url_template 1102 assert is_undefined(is_alphanumeric) or isinstance(is_alphanumeric, bool), is_alphanumeric 1103 1104 post_parameters = NotSet.remove_unset_items( 1105 {"key_prefix": key_prefix, "url_template": url_template, "is_alphanumeric": is_alphanumeric} 1106 ) 1107 1108 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/autolinks", input=post_parameters) 1109 1110 return github.Autolink.Autolink(self._requester, headers, data, completed=True) 1111 1112 def create_git_blob(self, content: str, encoding: str) -> GitBlob: 1113 """ 1114 :calls: `POST /repos/{owner}/{repo}/git/blobs <https://docs.github.com/en/rest/reference/git#blobs>`_ 1115 :param content: string 1116 :param encoding: string 1117 :rtype: :class:`github.GitBlob.GitBlob` 1118 """ 1119 assert isinstance(content, str), content 1120 assert isinstance(encoding, str), encoding 1121 post_parameters = { 1122 "content": content, 1123 "encoding": encoding, 1124 } 1125 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/git/blobs", input=post_parameters) 1126 return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) 1127 1128 def create_git_commit( 1129 self, 1130 message: str, 1131 tree: GitTree, 1132 parents: list[GitCommit], 1133 author: Opt[InputGitAuthor] = NotSet, 1134 committer: Opt[InputGitAuthor] = NotSet, 1135 ) -> GitCommit: 1136 """ 1137 :calls: `POST /repos/{owner}/{repo}/git/commits <https://docs.github.com/en/rest/reference/git#commits>`_ 1138 :param message: string 1139 :param tree: :class:`github.GitTree.GitTree` 1140 :param parents: list of :class:`github.GitCommit.GitCommit` 1141 :param author: :class:`github.InputGitAuthor.InputGitAuthor` 1142 :param committer: :class:`github.InputGitAuthor.InputGitAuthor` 1143 :rtype: :class:`github.GitCommit.GitCommit` 1144 """ 1145 assert isinstance(message, str), message 1146 assert isinstance(tree, github.GitTree.GitTree), tree 1147 assert all(isinstance(element, github.GitCommit.GitCommit) for element in parents), parents 1148 assert is_undefined(author) or isinstance(author, github.InputGitAuthor), author 1149 assert is_undefined(committer) or isinstance(committer, github.InputGitAuthor), committer 1150 post_parameters: dict[str, Any] = { 1151 "message": message, 1152 "tree": tree._identity, 1153 "parents": [element._identity for element in parents], 1154 } 1155 if is_defined(author): 1156 post_parameters["author"] = author._identity 1157 if is_defined(committer): 1158 post_parameters["committer"] = committer._identity 1159 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/git/commits", input=post_parameters) 1160 return github.GitCommit.GitCommit(self._requester, headers, data, completed=True) 1161 1162 def create_git_ref(self, ref: str, sha: str) -> GitRef: 1163 """ 1164 :calls: `POST /repos/{owner}/{repo}/git/refs <https://docs.github.com/en/rest/reference/git#references>`_ 1165 :param ref: string 1166 :param sha: string 1167 :rtype: :class:`github.GitRef.GitRef` 1168 """ 1169 assert isinstance(ref, str), ref 1170 assert isinstance(sha, str), sha 1171 post_parameters = { 1172 "ref": ref, 1173 "sha": sha, 1174 } 1175 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/git/refs", input=post_parameters) 1176 return github.GitRef.GitRef(self._requester, headers, data, completed=True) 1177 1178 def create_git_tag_and_release( 1179 self, 1180 tag: str, 1181 tag_message: str, 1182 release_name: str, 1183 release_message: str, 1184 object: str, 1185 type: str, 1186 tagger: Opt[InputGitAuthor] = NotSet, 1187 draft: bool = False, 1188 prerelease: bool = False, 1189 generate_release_notes: bool = False, 1190 ) -> GitRelease: 1191 """ 1192 Convenience function that calls :meth:`Repository.create_git_tag` and 1193 :meth:`Repository.create_git_release`. 1194 :param tag: string 1195 :param tag_message: string 1196 :param release_name: string 1197 :param release_message: string 1198 :param object: string 1199 :param type: string 1200 :param tagger: :class:github.InputGitAuthor.InputGitAuthor 1201 :param draft: bool 1202 :param prerelease: bool 1203 :param generate_release_notes: bool 1204 :rtype: :class:`github.GitRelease.GitRelease` 1205 """ 1206 self.create_git_tag(tag, tag_message, object, type, tagger) 1207 return self.create_git_release( 1208 tag, 1209 release_name, 1210 release_message, 1211 draft, 1212 prerelease, 1213 generate_release_notes, 1214 target_commitish=object, 1215 ) 1216 1217 def create_git_release( 1218 self, 1219 tag: str, 1220 name: str, 1221 message: str, 1222 draft: bool = False, 1223 prerelease: bool = False, 1224 generate_release_notes: bool = False, 1225 target_commitish: Opt[str] = NotSet, 1226 ) -> GitRelease: 1227 """ 1228 :calls: `POST /repos/{owner}/{repo}/releases <https://docs.github.com/en/rest/reference/repos#releases>`_ 1229 :param tag: string 1230 :param name: string 1231 :param message: string 1232 :param draft: bool 1233 :param prerelease: bool 1234 :param generate_release_notes: bool 1235 :param target_commitish: string or :class:`github.Branch.Branch` or :class:`github.Commit.Commit` or :class:`github.GitCommit.GitCommit` 1236 :rtype: :class:`github.GitRelease.GitRelease` 1237 """ 1238 assert isinstance(tag, str), tag 1239 assert isinstance(name, str), name 1240 assert isinstance(message, str), message 1241 assert isinstance(draft, bool), draft 1242 assert isinstance(prerelease, bool), prerelease 1243 assert isinstance(generate_release_notes, bool), generate_release_notes 1244 assert is_undefined(target_commitish) or isinstance( 1245 target_commitish, 1246 ( 1247 str, 1248 github.Branch.Branch, 1249 github.Commit.Commit, 1250 github.GitCommit.GitCommit, 1251 ), 1252 ), target_commitish 1253 post_parameters = { 1254 "tag_name": tag, 1255 "name": name, 1256 "body": message, 1257 "draft": draft, 1258 "prerelease": prerelease, 1259 "generate_release_notes": generate_release_notes, 1260 } 1261 if isinstance(target_commitish, str): 1262 post_parameters["target_commitish"] = target_commitish 1263 elif isinstance(target_commitish, github.Branch.Branch): 1264 post_parameters["target_commitish"] = target_commitish.name 1265 elif isinstance(target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit)): 1266 post_parameters["target_commitish"] = target_commitish.sha 1267 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/releases", input=post_parameters) 1268 return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) 1269 1270 def create_git_tag( 1271 self, 1272 tag: str, 1273 message: str, 1274 object: str, 1275 type: str, 1276 tagger: Opt[InputGitAuthor] = NotSet, 1277 ) -> GitTag: 1278 """ 1279 :calls: `POST /repos/{owner}/{repo}/git/tags <https://docs.github.com/en/rest/reference/git#tags>`_ 1280 """ 1281 assert isinstance(tag, str), tag 1282 assert isinstance(message, str), message 1283 assert isinstance(object, str), object 1284 assert isinstance(type, str), type 1285 assert is_undefined(tagger) or isinstance(tagger, github.InputGitAuthor), tagger 1286 post_parameters: dict[str, Any] = { 1287 "tag": tag, 1288 "message": message, 1289 "object": object, 1290 "type": type, 1291 } 1292 if is_defined(tagger): 1293 post_parameters["tagger"] = tagger._identity 1294 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/git/tags", input=post_parameters) 1295 return github.GitTag.GitTag(self._requester, headers, data, completed=True) 1296 1297 def create_git_tree(self, tree: list[InputGitTreeElement], base_tree: Opt[GitTree] = NotSet) -> GitTree: 1298 """ 1299 :calls: `POST /repos/{owner}/{repo}/git/trees <https://docs.github.com/en/rest/reference/git#trees>`_ 1300 :param tree: list of :class:`github.InputGitTreeElement.InputGitTreeElement` 1301 :param base_tree: :class:`github.GitTree.GitTree` 1302 :rtype: :class:`github.GitTree.GitTree` 1303 """ 1304 assert all(isinstance(element, github.InputGitTreeElement) for element in tree), tree 1305 assert is_undefined(base_tree) or isinstance(base_tree, github.GitTree.GitTree), base_tree 1306 post_parameters: dict[str, Any] = { 1307 "tree": [element._identity for element in tree], 1308 } 1309 if is_defined(base_tree): 1310 post_parameters["base_tree"] = base_tree._identity 1311 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/git/trees", input=post_parameters) 1312 return github.GitTree.GitTree(self._requester, headers, data, completed=True) 1313 1314 def create_hook( 1315 self, 1316 name: str, 1317 config: dict[str, str], 1318 events: Opt[list[str]] = NotSet, 1319 active: Opt[bool] = NotSet, 1320 ) -> Hook: 1321 """ 1322 :calls: `POST /repos/{owner}/{repo}/hooks <https://docs.github.com/en/rest/reference/repos#webhooks>`_ 1323 :param name: string 1324 :param config: dict 1325 :param events: list of string 1326 :param active: bool 1327 :rtype: :class:`github.Hook.Hook` 1328 """ 1329 assert isinstance(name, str), name 1330 assert isinstance(config, dict), config 1331 assert is_optional_list(events, str), events 1332 assert is_undefined(active) or isinstance(active, bool), active 1333 post_parameters = NotSet.remove_unset_items( 1334 {"name": name, "config": config, "events": events, "active": active} 1335 ) 1336 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/hooks", input=post_parameters) 1337 return github.Hook.Hook(self._requester, headers, data, completed=True) 1338 1339 def create_issue( 1340 self, 1341 title: str, 1342 body: Opt[str] = NotSet, 1343 assignee: NamedUser | Opt[str] = NotSet, 1344 milestone: Opt[Milestone] = NotSet, 1345 labels: list[Label] | Opt[list[str]] = NotSet, 1346 assignees: Opt[list[str]] | list[NamedUser] = NotSet, 1347 ) -> Issue: 1348 """ 1349 :calls: `POST /repos/{owner}/{repo}/issues <https://docs.github.com/en/rest/reference/issues>`_ 1350 :param title: string 1351 :param body: string 1352 :param assignee: string or :class:`github.NamedUser.NamedUser` 1353 :param assignees: list of string or :class:`github.NamedUser.NamedUser` 1354 :param milestone: :class:`github.Milestone.Milestone` 1355 :param labels: list of :class:`github.Label.Label` 1356 :rtype: :class:`github.Issue.Issue` 1357 """ 1358 assert isinstance(title, str), title 1359 assert is_undefined(body) or isinstance(body, str), body 1360 assert ( 1361 is_undefined(assignee) or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, str) 1362 ), assignee 1363 assert is_optional_list(assignees, (github.NamedUser.NamedUser, str)), assignees 1364 assert is_optional(milestone, github.Milestone.Milestone), milestone 1365 assert is_optional_list(labels, (github.Label.Label, str)), labels 1366 1367 post_parameters: dict[str, Any] = { 1368 "title": title, 1369 } 1370 if is_defined(body): 1371 post_parameters["body"] = body 1372 if is_defined(assignee): 1373 if isinstance(assignee, github.NamedUser.NamedUser): 1374 post_parameters["assignee"] = assignee._identity 1375 else: 1376 post_parameters["assignee"] = assignee 1377 if is_defined(assignees): 1378 post_parameters["assignees"] = [ 1379 element._identity if isinstance(element, github.NamedUser.NamedUser) else element 1380 for element in assignees # type: ignore 1381 ] 1382 if is_defined(milestone): 1383 post_parameters["milestone"] = milestone._identity 1384 if is_defined(labels): 1385 post_parameters["labels"] = [ 1386 element.name if isinstance(element, github.Label.Label) else element 1387 for element in labels # type: ignore 1388 ] 1389 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/issues", input=post_parameters) 1390 return github.Issue.Issue(self._requester, headers, data, completed=True) 1391 1392 def create_key(self, title: str, key: str, read_only: bool = False) -> RepositoryKey: 1393 """ 1394 :calls: `POST /repos/{owner}/{repo}/keys <https://docs.github.com/en/rest/reference/repos#deploy-keys>`_ 1395 :param title: string 1396 :param key: string 1397 :param read_only: bool 1398 :rtype: :class:`github.RepositoryKey.RepositoryKey` 1399 """ 1400 assert isinstance(title, str), title 1401 assert isinstance(key, str), key 1402 assert isinstance(read_only, bool), read_only 1403 post_parameters = { 1404 "title": title, 1405 "key": key, 1406 "read_only": read_only, 1407 } 1408 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/keys", input=post_parameters) 1409 return github.RepositoryKey.RepositoryKey(self._requester, headers, data, completed=True) 1410 1411 def create_label(self, name: str, color: str, description: Opt[str] = NotSet) -> Label: 1412 """ 1413 :calls: `POST /repos/{owner}/{repo}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_ 1414 :param name: string 1415 :param color: string 1416 :param description: string 1417 :rtype: :class:`github.Label.Label` 1418 """ 1419 assert isinstance(name, str), name 1420 assert isinstance(color, str), color 1421 assert is_undefined(description) or isinstance(description, str), description 1422 post_parameters = { 1423 "name": name, 1424 "color": color, 1425 } 1426 if is_defined(description): 1427 post_parameters["description"] = description 1428 headers, data = self._requester.requestJsonAndCheck( 1429 "POST", 1430 f"{self.url}/labels", 1431 input=post_parameters, 1432 headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, 1433 ) 1434 return github.Label.Label(self._requester, headers, data, completed=True) 1435 1436 def create_milestone( 1437 self, 1438 title: str, 1439 state: Opt[str] = NotSet, 1440 description: Opt[str] = NotSet, 1441 due_on: Opt[date] = NotSet, 1442 ) -> Milestone: 1443 """ 1444 :calls: `POST /repos/{owner}/{repo}/milestones <https://docs.github.com/en/rest/reference/issues#milestones>`_ 1445 :param title: string 1446 :param state: string 1447 :param description: string 1448 :param due_on: datetime 1449 :rtype: :class:`github.Milestone.Milestone` 1450 """ 1451 assert isinstance(title, str), title 1452 assert is_undefined(state) or isinstance(state, str), state 1453 assert is_undefined(description) or isinstance(description, str), description 1454 assert is_undefined(due_on) or isinstance(due_on, (datetime, date)), due_on 1455 post_parameters = { 1456 "title": title, 1457 } 1458 if is_defined(state): 1459 post_parameters["state"] = state 1460 if is_defined(description): 1461 post_parameters["description"] = description 1462 if is_defined(due_on): 1463 if isinstance(due_on, date): 1464 post_parameters["due_on"] = due_on.strftime("%Y-%m-%dT%H:%M:%SZ") 1465 else: 1466 post_parameters["due_on"] = due_on.isoformat() 1467 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/milestones", input=post_parameters) 1468 return github.Milestone.Milestone(self._requester, headers, data, completed=True) 1469 1470 def create_project(self, name: str, body: Opt[str] = NotSet) -> Project: 1471 """ 1472 :calls: `POST /repos/{owner}/{repo}/projects <https://docs.github.com/en/rest/reference/projects#create-a-repository-project>`_ 1473 :param name: string 1474 :param body: string 1475 :rtype: :class:`github.Project.Project` 1476 """ 1477 assert isinstance(name, str), name 1478 assert is_undefined(body) or isinstance(body, str), body 1479 post_parameters = { 1480 "name": name, 1481 } 1482 import_header = {"Accept": Consts.mediaTypeProjectsPreview} 1483 if is_defined(body): 1484 post_parameters["body"] = body 1485 headers, data = self._requester.requestJsonAndCheck( 1486 "POST", f"{self.url}/projects", headers=import_header, input=post_parameters 1487 ) 1488 return github.Project.Project(self._requester, headers, data, completed=True) 1489 1490 def create_pull( 1491 self, 1492 base: str, 1493 head: str, 1494 *, 1495 title: Opt[str] = NotSet, 1496 body: Opt[str] = NotSet, 1497 maintainer_can_modify: Opt[bool] = NotSet, 1498 draft: Opt[bool] = NotSet, 1499 issue: Opt[github.Issue.Issue] = NotSet, 1500 ) -> github.PullRequest.PullRequest: 1501 """ 1502 :calls: `POST /repos/{owner}/{repo}/pulls <https://docs.github.com/en/free-pro-team@latest/rest/pulls/pulls?apiVersion=2022-11-28#create-a-pull-request>`_ 1503 """ 1504 assert isinstance(base, str), base 1505 assert isinstance(head, str), head 1506 assert is_optional(title, str), title 1507 assert is_optional(body, str), body 1508 assert is_optional(maintainer_can_modify, bool), maintainer_can_modify 1509 assert is_optional(draft, bool), draft 1510 assert is_optional(issue, github.Issue.Issue), issue 1511 1512 post_parameters = NotSet.remove_unset_items( 1513 { 1514 "base": base, 1515 "head": head, 1516 "title": title, 1517 "body": body, 1518 "maintainer_can_modify": maintainer_can_modify, 1519 "draft": draft, 1520 } 1521 ) 1522 1523 if is_defined(issue): 1524 post_parameters["issue"] = issue._identity 1525 1526 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/pulls", input=post_parameters) 1527 return github.PullRequest.PullRequest(self._requester, headers, data, completed=True) 1528 1529 def create_repository_advisory( 1530 self, 1531 summary: str, 1532 description: str, 1533 severity_or_cvss_vector_string: str, 1534 cve_id: str | None = None, 1535 vulnerabilities: Iterable[github.RepositoryAdvisoryVulnerability.AdvisoryVulnerability] | None = None, 1536 cwe_ids: Iterable[str] | None = None, 1537 credits: Iterable[github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit] | None = None, 1538 ) -> github.RepositoryAdvisory.RepositoryAdvisory: 1539 """ 1540 :calls: `POST /repos/{owner}/{repo}/security-advisories <https://docs.github.com/en/rest/security-advisories/repository-advisories>`_ 1541 :param summary: string 1542 :param description: string 1543 :param severity_or_cvss_vector_string: string 1544 :param cve_id: string 1545 :param vulnerabilities: iterable of :class:`github.RepositoryAdvisoryVulnerability.AdvisoryVulnerability` 1546 :param cwe_ids: iterable of string 1547 :param credits: iterable of :class:`github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit` 1548 :rtype: :class:`github.RepositoryAdvisory.RepositoryAdvisory` 1549 """ 1550 return self.__create_repository_advisory( 1551 summary=summary, 1552 description=description, 1553 severity_or_cvss_vector_string=severity_or_cvss_vector_string, 1554 cve_id=cve_id, 1555 vulnerabilities=vulnerabilities, 1556 cwe_ids=cwe_ids, 1557 credits=credits, 1558 private_vulnerability_reporting=False, 1559 ) 1560 1561 def report_security_vulnerability( 1562 self, 1563 summary: str, 1564 description: str, 1565 severity_or_cvss_vector_string: str, 1566 cve_id: str | None = None, 1567 vulnerabilities: Iterable[github.RepositoryAdvisoryVulnerability.AdvisoryVulnerability] | None = None, 1568 cwe_ids: Iterable[str] | None = None, 1569 credits: Iterable[github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit] | None = None, 1570 ) -> github.RepositoryAdvisory.RepositoryAdvisory: 1571 """ 1572 :calls: `POST /repos/{owner}/{repo}/security-advisories/reports <https://docs.github.com/en/rest/security-advisories/repository-advisories#privately-report-a-security-vulnerability>`_ 1573 :param summary: string 1574 :param description: string 1575 :param severity_or_cvss_vector_string: string 1576 :param cve_id: string 1577 :param vulnerabilities: iterable of :class:`github.RepositoryAdvisoryVulnerability.AdvisoryVulnerability` 1578 :param cwe_ids: iterable of string 1579 :param credits: iterable of :class:`github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit` 1580 :rtype: :class:`github.RepositoryAdvisory.RepositoryAdvisory` 1581 """ 1582 return self.__create_repository_advisory( 1583 summary=summary, 1584 description=description, 1585 severity_or_cvss_vector_string=severity_or_cvss_vector_string, 1586 cve_id=cve_id, 1587 vulnerabilities=vulnerabilities, 1588 cwe_ids=cwe_ids, 1589 credits=credits, 1590 private_vulnerability_reporting=True, 1591 ) 1592 1593 def __create_repository_advisory( 1594 self, 1595 summary: str, 1596 description: str, 1597 severity_or_cvss_vector_string: str, 1598 cve_id: str | None, 1599 vulnerabilities: Iterable[github.RepositoryAdvisoryVulnerability.AdvisoryVulnerability] | None, 1600 cwe_ids: Iterable[str] | None, 1601 credits: Iterable[github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit] | None, 1602 private_vulnerability_reporting: bool, 1603 ) -> github.RepositoryAdvisory.RepositoryAdvisory: 1604 if vulnerabilities is None: 1605 vulnerabilities = [] 1606 if cwe_ids is None: 1607 cwe_ids = [] 1608 assert isinstance(summary, str), summary 1609 assert isinstance(description, str), description 1610 assert isinstance(severity_or_cvss_vector_string, str), severity_or_cvss_vector_string 1611 assert isinstance(cve_id, (str, type(None))), cve_id 1612 assert isinstance(vulnerabilities, Iterable), vulnerabilities 1613 for vulnerability in vulnerabilities: 1614 github.RepositoryAdvisoryVulnerability.RepositoryAdvisoryVulnerability._validate_vulnerability( 1615 vulnerability 1616 ) 1617 assert isinstance(cwe_ids, Iterable), cwe_ids 1618 assert all(isinstance(element, str) for element in cwe_ids), cwe_ids 1619 assert isinstance(credits, (Iterable, type(None))), credits 1620 if credits is not None: 1621 for credit in credits: 1622 github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit._validate_credit(credit) 1623 post_parameters = { 1624 "summary": summary, 1625 "description": description, 1626 "vulnerabilities": [ 1627 github.RepositoryAdvisoryVulnerability.RepositoryAdvisoryVulnerability._to_github_dict(vulnerability) 1628 for vulnerability in vulnerabilities 1629 ], 1630 "cwe_ids": list(cwe_ids), 1631 } 1632 if cve_id is not None: 1633 post_parameters["cve_id"] = cve_id 1634 if credits is not None: 1635 post_parameters["credits"] = [ 1636 github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit._to_github_dict(credit) for credit in credits 1637 ] 1638 if severity_or_cvss_vector_string.startswith("CVSS:"): 1639 post_parameters["cvss_vector_string"] = severity_or_cvss_vector_string 1640 else: 1641 post_parameters["severity"] = severity_or_cvss_vector_string 1642 if private_vulnerability_reporting: 1643 headers, data = self._requester.requestJsonAndCheck( 1644 "POST", f"{self.url}/security-advisories/reports", input=post_parameters 1645 ) 1646 else: 1647 headers, data = self._requester.requestJsonAndCheck( 1648 "POST", f"{self.url}/security-advisories", input=post_parameters 1649 ) 1650 return github.RepositoryAdvisory.RepositoryAdvisory(self._requester, headers, data, completed=True) 1651 1652 def create_repository_dispatch(self, event_type: str, client_payload: Opt[dict[str, Any]] = NotSet) -> bool: 1653 """ 1654 :calls: POST /repos/{owner}/{repo}/dispatches <https://docs.github.com/en/rest/repos#create-a-repository-dispatch-event> 1655 :param event_type: string 1656 :param client_payload: dict 1657 :rtype: bool 1658 """ 1659 assert isinstance(event_type, str), event_type 1660 assert is_undefined(client_payload) or isinstance(client_payload, dict), client_payload 1661 post_parameters = NotSet.remove_unset_items({"event_type": event_type, "client_payload": client_payload}) 1662 status, headers, data = self._requester.requestJson("POST", f"{self.url}/dispatches", input=post_parameters) 1663 return status == 204 1664 1665 def create_secret(self, secret_name: str, unencrypted_value: str) -> github.Secret.Secret: 1666 """ 1667 :calls: `PUT /repos/{owner}/{repo}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#get-a-repository-secret>`_ 1668 """ 1669 assert isinstance(secret_name, str), secret_name 1670 assert isinstance(unencrypted_value, str), unencrypted_value 1671 public_key = self.get_public_key() 1672 payload = public_key.encrypt(unencrypted_value) 1673 put_parameters = { 1674 "key_id": public_key.key_id, 1675 "encrypted_value": payload, 1676 } 1677 self._requester.requestJsonAndCheck("PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters) 1678 return github.Secret.Secret( 1679 requester=self._requester, 1680 headers={}, 1681 attributes={ 1682 "name": secret_name, 1683 "url": f"{self.url}/actions/secrets/{secret_name}", 1684 }, 1685 completed=False, 1686 ) 1687 1688 def get_secrets(self) -> PaginatedList[github.Secret.Secret]: 1689 """ 1690 Gets all repository secrets 1691 """ 1692 return PaginatedList( 1693 github.Secret.Secret, 1694 self._requester, 1695 f"{self.url}/actions/secrets", 1696 None, 1697 list_item="secrets", 1698 ) 1699 1700 def get_secret(self, secret_name: str) -> github.Secret.Secret: 1701 """ 1702 :calls: 'GET /repos/{owner}/{repo}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#get-an-organization-secret>`_ 1703 """ 1704 assert isinstance(secret_name, str), secret_name 1705 return github.Secret.Secret( 1706 requester=self._requester, 1707 headers={}, 1708 attributes={"url": f"{self.url}/actions/secrets/{secret_name}"}, 1709 completed=False, 1710 ) 1711 1712 def create_variable(self, variable_name: str, value: str) -> github.Variable.Variable: 1713 """ 1714 :calls: `POST /repos/{owner}/{repo}/actions/variables/{variable_name} <https://docs.github.com/en/rest/actions/variables#create-a-repository-variable>`_ 1715 """ 1716 assert isinstance(variable_name, str), variable_name 1717 assert isinstance(value, str), value 1718 post_parameters = { 1719 "name": variable_name, 1720 "value": value, 1721 } 1722 self._requester.requestJsonAndCheck("POST", f"{self.url}/actions/variables", input=post_parameters) 1723 return github.Variable.Variable( 1724 self._requester, 1725 headers={}, 1726 attributes={ 1727 "name": variable_name, 1728 "value": value, 1729 "url": self.url, 1730 }, 1731 completed=False, 1732 ) 1733 1734 def get_variables(self) -> PaginatedList[github.Variable.Variable]: 1735 """ 1736 Gets all repository variables 1737 :rtype: :class:`PaginatedList` of :class:`github.Variable.Variable` 1738 """ 1739 return PaginatedList( 1740 github.Variable.Variable, 1741 self._requester, 1742 f"{self.url}/actions/variables", 1743 None, 1744 list_item="variables", 1745 ) 1746 1747 def get_variable(self, variable_name: str) -> github.Variable.Variable: 1748 """ 1749 :calls: 'GET /orgs/{org}/actions/variables/{variable_name} <https://docs.github.com/en/rest/actions/variables#get-an-organization-variable>`_ 1750 :param variable_name: string 1751 :rtype: github.Variable.Variable 1752 """ 1753 assert isinstance(variable_name, str), variable_name 1754 return github.Variable.Variable( 1755 requester=self._requester, 1756 headers={}, 1757 attributes={"url": f"{self.url}/actions/variables/{variable_name}"}, 1758 completed=False, 1759 ) 1760 1761 def delete_secret(self, secret_name: str) -> bool: 1762 """ 1763 :calls: `DELETE /repos/{owner}/{repo}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/reference/actions#delete-a-repository-secret>`_ 1764 :param secret_name: string 1765 :rtype: bool 1766 """ 1767 assert isinstance(secret_name, str), secret_name 1768 status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/secrets/{secret_name}") 1769 return status == 204 1770 1771 def delete_variable(self, variable_name: str) -> bool: 1772 """ 1773 :calls: `DELETE /repos/{owner}/{repo}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions#delete-a-repository-variable>`_ 1774 :param variable_name: string 1775 :rtype: bool 1776 """ 1777 assert isinstance(variable_name, str), variable_name 1778 status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/variables/{variable_name}") 1779 return status == 204 1780 1781 def create_source_import( 1782 self, 1783 vcs: str, 1784 vcs_url: str, 1785 vcs_username: Opt[str] = NotSet, 1786 vcs_password: Opt[str] = NotSet, 1787 ) -> SourceImport: 1788 """ 1789 :calls: `PUT /repos/{owner}/{repo}/import <https://docs.github.com/en/rest/reference/migrations#start-an-import>`_ 1790 :param vcs: string 1791 :param vcs_url: string 1792 :param vcs_username: string 1793 :param vcs_password: string 1794 :rtype: :class:`github.SourceImport.SourceImport` 1795 """ 1796 assert isinstance(vcs, str), vcs 1797 assert isinstance(vcs_url, str), vcs_url 1798 assert is_undefined(vcs_username) or isinstance(vcs_username, str), vcs_username 1799 assert is_undefined(vcs_password) or isinstance(vcs_password, str), vcs_password 1800 put_parameters = {"vcs": vcs, "vcs_url": vcs_url} 1801 1802 if is_defined(vcs_username): 1803 put_parameters["vcs_username"] = vcs_username 1804 1805 if is_defined(vcs_password): 1806 put_parameters["vcs_password"] = vcs_password 1807 1808 import_header = {"Accept": Consts.mediaTypeImportPreview} 1809 1810 headers, data = self._requester.requestJsonAndCheck( 1811 "PUT", f"{self.url}/import", headers=import_header, input=put_parameters 1812 ) 1813 1814 return github.SourceImport.SourceImport(self._requester, headers, data, completed=False) 1815 1816 def delete(self) -> None: 1817 """ 1818 :calls: `DELETE /repos/{owner}/{repo} <https://docs.github.com/en/rest/reference/repos>`_ 1819 :rtype: None 1820 """ 1821 headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) 1822 1823 def edit( 1824 self, 1825 name: str | None = None, 1826 description: Opt[str] = NotSet, 1827 homepage: Opt[str] = NotSet, 1828 private: Opt[bool] = NotSet, 1829 visibility: Opt[str] = NotSet, 1830 has_issues: Opt[bool] = NotSet, 1831 has_projects: Opt[bool] = NotSet, 1832 has_wiki: Opt[bool] = NotSet, 1833 is_template: Opt[bool] = NotSet, 1834 default_branch: Opt[str] = NotSet, 1835 allow_squash_merge: Opt[bool] = NotSet, 1836 allow_merge_commit: Opt[bool] = NotSet, 1837 allow_rebase_merge: Opt[bool] = NotSet, 1838 allow_auto_merge: Opt[bool] = NotSet, 1839 delete_branch_on_merge: Opt[bool] = NotSet, 1840 allow_update_branch: Opt[bool] = NotSet, 1841 use_squash_pr_title_as_default: Opt[bool] = NotSet, 1842 squash_merge_commit_title: Opt[str] = NotSet, 1843 squash_merge_commit_message: Opt[str] = NotSet, 1844 merge_commit_title: Opt[str] = NotSet, 1845 merge_commit_message: Opt[str] = NotSet, 1846 archived: Opt[bool] = NotSet, 1847 allow_forking: Opt[bool] = NotSet, 1848 web_commit_signoff_required: Opt[bool] = NotSet, 1849 ) -> None: 1850 """ 1851 :calls: `PATCH /repos/{owner}/{repo} <https://docs.github.com/en/rest/reference/repos>`_ 1852 :param name: string 1853 :param description: string 1854 :param homepage: string 1855 :param private: bool 1856 :param visibility: string 1857 :param has_issues: bool 1858 :param has_projects: bool 1859 :param has_wiki: bool 1860 :param is_template: bool 1861 :param default_branch: string 1862 :param allow_squash_merge: bool 1863 :param allow_merge_commit: bool 1864 :param allow_rebase_merge: bool 1865 :param allow_auto_merge: bool 1866 :param delete_branch_on_merge: bool 1867 :param allow_update_branch: bool 1868 :param use_squash_pr_title_as_default: bool 1869 :param squash_merge_commit_title : string 1870 :param squash_merge_commit_message : string 1871 :param merge_commit_title : string 1872 :param merge_commit_message : string 1873 :param archived: bool 1874 :param allow_forking: bool 1875 :param web_commit_signoff_required: bool 1876 :rtype: None 1877 """ 1878 if name is None: 1879 name = self.name 1880 assert isinstance(name, str), name 1881 assert is_undefined(description) or isinstance(description, str), description 1882 assert is_undefined(homepage) or isinstance(homepage, str), homepage 1883 assert is_undefined(private) or isinstance(private, bool), private 1884 assert is_undefined(visibility) or ( 1885 isinstance(visibility, str) and visibility in ["public", "private"] 1886 ), visibility 1887 assert is_undefined(has_issues) or isinstance(has_issues, bool), has_issues 1888 assert is_undefined(has_projects) or isinstance(has_projects, bool), has_projects 1889 assert is_undefined(has_wiki) or isinstance(has_wiki, bool), has_wiki 1890 assert is_undefined(is_template) or isinstance(is_template, bool), is_template 1891 assert is_undefined(default_branch) or isinstance(default_branch, str), default_branch 1892 assert is_undefined(allow_squash_merge) or isinstance(allow_squash_merge, bool), allow_squash_merge 1893 assert is_undefined(allow_merge_commit) or isinstance(allow_merge_commit, bool), allow_merge_commit 1894 assert is_undefined(allow_rebase_merge) or isinstance(allow_rebase_merge, bool), allow_rebase_merge 1895 assert is_undefined(allow_auto_merge) or isinstance(allow_auto_merge, bool), allow_auto_merge 1896 assert is_undefined(delete_branch_on_merge) or isinstance(delete_branch_on_merge, bool), delete_branch_on_merge 1897 assert is_undefined(allow_update_branch) or isinstance(allow_update_branch, bool), allow_update_branch 1898 assert is_undefined(use_squash_pr_title_as_default) or isinstance( 1899 use_squash_pr_title_as_default, bool 1900 ), use_squash_pr_title_as_default 1901 assert is_undefined(squash_merge_commit_title) or ( 1902 isinstance(squash_merge_commit_title, str) 1903 and squash_merge_commit_title in ["PR_TITLE", "COMMIT_OR_PR_TITLE"] 1904 ), squash_merge_commit_title 1905 assert is_undefined(squash_merge_commit_message) or ( 1906 isinstance(squash_merge_commit_message, str) 1907 and squash_merge_commit_message in ["PR_BODY", "COMMIT_MESSAGES", "BLANK"] 1908 ), squash_merge_commit_message 1909 assert is_undefined(merge_commit_title) or ( 1910 isinstance(merge_commit_title, str) and merge_commit_title in ["PR_TITLE", "MERGE_MESSAGE"] 1911 ), merge_commit_title 1912 assert is_undefined(merge_commit_message) or ( 1913 isinstance(merge_commit_message, str) and merge_commit_message in ["PR_TITLE", "PR_BODY", "BLANK"] 1914 ), merge_commit_message 1915 assert is_undefined(archived) or isinstance(archived, bool), archived 1916 assert is_undefined(allow_forking) or isinstance(allow_forking, bool), allow_forking 1917 assert is_undefined(web_commit_signoff_required) or isinstance( 1918 web_commit_signoff_required, bool 1919 ), web_commit_signoff_required 1920 1921 post_parameters: dict[str, Any] = { 1922 "name": name, 1923 } 1924 1925 if is_defined(description): 1926 post_parameters["description"] = description 1927 if is_defined(homepage): 1928 post_parameters["homepage"] = homepage 1929 if is_defined(private): 1930 post_parameters["private"] = private 1931 if is_defined(visibility): 1932 post_parameters["visibility"] = visibility 1933 if is_defined(has_issues): 1934 post_parameters["has_issues"] = has_issues 1935 if is_defined(has_projects): 1936 post_parameters["has_projects"] = has_projects 1937 if is_defined(has_wiki): 1938 post_parameters["has_wiki"] = has_wiki 1939 if is_defined(is_template): 1940 post_parameters["is_template"] = is_template 1941 if is_defined(default_branch): 1942 post_parameters["default_branch"] = default_branch 1943 if is_defined(allow_squash_merge): 1944 post_parameters["allow_squash_merge"] = allow_squash_merge 1945 if is_defined(allow_merge_commit): 1946 post_parameters["allow_merge_commit"] = allow_merge_commit 1947 if is_defined(allow_rebase_merge): 1948 post_parameters["allow_rebase_merge"] = allow_rebase_merge 1949 if is_defined(allow_auto_merge): 1950 post_parameters["allow_auto_merge"] = allow_auto_merge 1951 if is_defined(delete_branch_on_merge): 1952 post_parameters["delete_branch_on_merge"] = delete_branch_on_merge 1953 if is_defined(allow_update_branch): 1954 post_parameters["allow_update_branch"] = allow_update_branch 1955 if is_defined(use_squash_pr_title_as_default): 1956 post_parameters["use_squash_pr_title_as_default"] = use_squash_pr_title_as_default 1957 if is_defined(squash_merge_commit_title): 1958 post_parameters["squash_merge_commit_title"] = squash_merge_commit_title 1959 if is_defined(squash_merge_commit_message): 1960 post_parameters["squash_merge_commit_message"] = squash_merge_commit_message 1961 if is_defined(merge_commit_title): 1962 post_parameters["merge_commit_title"] = merge_commit_title 1963 if is_defined(merge_commit_message): 1964 post_parameters["merge_commit_message"] = merge_commit_message 1965 if is_defined(archived): 1966 post_parameters["archived"] = archived 1967 if is_defined(allow_forking): 1968 post_parameters["allow_forking"] = allow_forking 1969 if is_defined(web_commit_signoff_required): 1970 post_parameters["web_commit_signoff_required"] = web_commit_signoff_required 1971 headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters) 1972 self._useAttributes(data) 1973 1974 def get_archive_link(self, archive_format: str, ref: Opt[str] = NotSet) -> str: 1975 """ 1976 :calls: `GET /repos/{owner}/{repo}/{archive_format}/{ref} <https://docs.github.com/en/rest/reference/repos#contents>`_ 1977 :param archive_format: string 1978 :param ref: string 1979 :rtype: string 1980 """ 1981 assert isinstance(archive_format, str), archive_format 1982 assert is_undefined(ref) or isinstance(ref, str), ref 1983 url = f"{self.url}/{archive_format}" 1984 if is_defined(ref): 1985 url += f"/{ref}" 1986 headers, data = self._requester.requestJsonAndCheck("GET", url) 1987 return headers["location"] 1988 1989 def get_assignees(self) -> PaginatedList[NamedUser]: 1990 """ 1991 :calls: `GET /repos/{owner}/{repo}/assignees <https://docs.github.com/en/rest/reference/issues#assignees>`_ 1992 :rtype: :class:`PaginatedList` of :class:`github.NamedUser.NamedUser` 1993 """ 1994 return PaginatedList(github.NamedUser.NamedUser, self._requester, f"{self.url}/assignees", None) 1995 1996 def get_branch(self, branch: str) -> Branch: 1997 """ 1998 :calls: `GET /repos/{owner}/{repo}/branches/{branch} <https://docs.github.com/en/rest/reference/repos#get-a-branch>`_ 1999 :param branch: string 2000 :rtype: :class:`github.Branch.Branch` 2001 """ 2002 assert isinstance(branch, str), branch 2003 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/branches/{branch}") 2004 return github.Branch.Branch(self._requester, headers, data, completed=True) 2005 2006 def rename_branch(self, branch: str | Branch, new_name: str) -> bool: 2007 """ 2008 :calls: `POST /repos/{owner}/{repo}/branches/{branch}/rename <https://docs.github.com/en/rest/reference/repos#branches>`_ 2009 :param branch: :class:`github.Branch.Branch` or string 2010 :param new_name: string 2011 :rtype: bool 2012 2013 NOTE: This method does not return the branch since it may take some 2014 time to fully complete server-side. 2015 """ 2016 is_branch = isinstance(branch, github.Branch.Branch) 2017 assert isinstance(branch, str) or is_branch, branch 2018 assert isinstance(new_name, str), new_name 2019 if is_branch: 2020 branch = branch.name # type: ignore 2021 parameters = {"new_name": new_name} 2022 status, _, _ = self._requester.requestJson("POST", f"{self.url}/branches/{branch}/rename", input=parameters) 2023 return status == 201 2024 2025 def get_branches(self) -> PaginatedList[Branch]: 2026 """ 2027 :calls: `GET /repos/{owner}/{repo}/branches <https://docs.github.com/en/rest/reference/repos>`_ 2028 :rtype: :class:`PaginatedList` of :class:`github.Branch.Branch` 2029 """ 2030 return PaginatedList(github.Branch.Branch, self._requester, f"{self.url}/branches", None) 2031 2032 def get_collaborators(self, affiliation: Opt[str] = NotSet) -> PaginatedList[NamedUser]: 2033 """ 2034 :calls: `GET /repos/{owner}/{repo}/collaborators <https://docs.github.com/en/rest/reference/repos#collaborators>`_ 2035 :param affiliation: string 2036 :rtype: :class:`PaginatedList` of :class:`github.NamedUser.NamedUser` 2037 """ 2038 2039 url_parameters = dict() 2040 allowed_affiliations = ["outside", "direct", "all"] 2041 if is_defined(affiliation): 2042 assert isinstance(affiliation, str), affiliation 2043 assert affiliation in allowed_affiliations, f"Affiliation can be one of {', '.join(allowed_affiliations)}" 2044 url_parameters["affiliation"] = affiliation 2045 2046 return PaginatedList( 2047 github.NamedUser.NamedUser, 2048 self._requester, 2049 f"{self.url}/collaborators", 2050 url_parameters, 2051 ) 2052 2053 def get_comment(self, id: int) -> CommitComment: 2054 """ 2055 :calls: `GET /repos/{owner}/{repo}/comments/{id} <https://docs.github.com/en/rest/reference/repos#comments>`_ 2056 :param id: integer 2057 :rtype: :class:`github.CommitComment.CommitComment` 2058 """ 2059 assert isinstance(id, int), id 2060 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/comments/{id}") 2061 return github.CommitComment.CommitComment(self._requester, headers, data, completed=True) 2062 2063 def get_comments(self) -> PaginatedList[CommitComment]: 2064 """ 2065 :calls: `GET /repos/{owner}/{repo}/comments <https://docs.github.com/en/rest/reference/repos#comments>`_ 2066 :rtype: :class:`PaginatedList` of :class:`github.CommitComment.CommitComment` 2067 """ 2068 return PaginatedList( 2069 github.CommitComment.CommitComment, 2070 self._requester, 2071 f"{self.url}/comments", 2072 None, 2073 ) 2074 2075 def get_commit(self, sha: str) -> Commit: 2076 """ 2077 :calls: `GET /repos/{owner}/{repo}/commits/{sha} <https://docs.github.com/en/rest/reference/repos#commits>`_ 2078 :param sha: string 2079 :rtype: :class:`github.Commit.Commit` 2080 """ 2081 assert isinstance(sha, str), sha 2082 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/commits/{sha}") 2083 return github.Commit.Commit(self._requester, headers, data, completed=True) 2084 2085 def get_commits( 2086 self, 2087 sha: Opt[str] = NotSet, 2088 path: Opt[str] = NotSet, 2089 since: Opt[datetime] = NotSet, 2090 until: Opt[datetime] = NotSet, 2091 author: Opt[AuthenticatedUser | NamedUser | str] = NotSet, 2092 ) -> PaginatedList[Commit]: 2093 """ 2094 :calls: `GET /repos/{owner}/{repo}/commits <https://docs.github.com/en/rest/reference/repos#commits>`_ 2095 :param sha: string 2096 :param path: string 2097 :param since: datetime 2098 :param until: datetime 2099 :param author: string or :class:`github.NamedUser.NamedUser` or :class:`github.AuthenticatedUser.AuthenticatedUser` 2100 :rtype: :class:`PaginatedList` of :class:`github.Commit.Commit` 2101 """ 2102 assert is_undefined(sha) or isinstance(sha, str), sha 2103 assert is_undefined(path) or isinstance(path, str), path 2104 assert is_undefined(since) or isinstance(since, datetime), since 2105 assert is_undefined(until) or isinstance(until, datetime), until 2106 assert is_undefined(author) or isinstance( 2107 author, 2108 ( 2109 str, 2110 github.NamedUser.NamedUser, 2111 github.AuthenticatedUser.AuthenticatedUser, 2112 ), 2113 ), author 2114 url_parameters: dict[str, Any] = {} 2115 if is_defined(sha): 2116 url_parameters["sha"] = sha 2117 if is_defined(path): 2118 url_parameters["path"] = path 2119 if is_defined(since): 2120 url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") 2121 if is_defined(until): 2122 url_parameters["until"] = until.strftime("%Y-%m-%dT%H:%M:%SZ") 2123 if is_defined(author): 2124 if isinstance( 2125 author, 2126 ( 2127 github.NamedUser.NamedUser, 2128 github.AuthenticatedUser.AuthenticatedUser, 2129 ), 2130 ): 2131 url_parameters["author"] = author.login 2132 else: 2133 url_parameters["author"] = author 2134 return PaginatedList(github.Commit.Commit, self._requester, f"{self.url}/commits", url_parameters) 2135 2136 def get_contents(self, path: str, ref: Opt[str] = NotSet) -> list[ContentFile] | ContentFile: 2137 """ 2138 :calls: `GET /repos/{owner}/{repo}/contents/{path} <https://docs.github.com/en/rest/reference/repos#contents>`_ 2139 :param path: string 2140 :param ref: string 2141 :rtype: :class:`github.ContentFile.ContentFile` or a list of them 2142 """ 2143 assert isinstance(path, str), path 2144 assert is_undefined(ref) or isinstance(ref, str), ref 2145 # Path of '/' should be the empty string. 2146 if path == "/": 2147 path = "" 2148 url_parameters = dict() 2149 if is_defined(ref): 2150 url_parameters["ref"] = ref 2151 headers, data = self._requester.requestJsonAndCheck( 2152 "GET", 2153 f"{self.url}/contents/{urllib.parse.quote(path)}", 2154 parameters=url_parameters, 2155 ) 2156 2157 # Handle 302 redirect response 2158 if headers.get("status") == "302 Found" and headers.get("location"): 2159 headers, data = self._requester.requestJsonAndCheck("GET", headers["location"], parameters=url_parameters) 2160 2161 if isinstance(data, list): 2162 return [ 2163 # Lazy completion only makes sense for files. See discussion 2164 # here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130 2165 github.ContentFile.ContentFile(self._requester, headers, item, completed=(item["type"] != "file")) 2166 for item in data 2167 ] 2168 return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) 2169 2170 def get_deployments( 2171 self, 2172 sha: Opt[str] = NotSet, 2173 ref: Opt[str] = NotSet, 2174 task: Opt[str] = NotSet, 2175 environment: Opt[str] = NotSet, 2176 ) -> PaginatedList[Deployment]: 2177 """ 2178 :calls: `GET /repos/{owner}/{repo}/deployments <https://docs.github.com/en/rest/reference/repos#deployments>`_ 2179 :param: sha: string 2180 :param: ref: string 2181 :param: task: string 2182 :param: environment: string 2183 :rtype: :class:`PaginatedList` of :class:`github.Deployment.Deployment` 2184 """ 2185 assert is_undefined(sha) or isinstance(sha, str), sha 2186 assert is_undefined(ref) or isinstance(ref, str), ref 2187 assert is_undefined(task) or isinstance(task, str), task 2188 assert is_undefined(environment) or isinstance(environment, str), environment 2189 parameters = {} 2190 if is_defined(sha): 2191 parameters["sha"] = sha 2192 if is_defined(ref): 2193 parameters["ref"] = ref 2194 if is_defined(task): 2195 parameters["task"] = task 2196 if is_defined(environment): 2197 parameters["environment"] = environment 2198 return PaginatedList( 2199 github.Deployment.Deployment, 2200 self._requester, 2201 f"{self.url}/deployments", 2202 parameters, 2203 headers={"Accept": Consts.deploymentEnhancementsPreview}, 2204 ) 2205 2206 def get_deployment(self, id_: int) -> Deployment: 2207 """ 2208 :calls: `GET /repos/{owner}/{repo}/deployments/{deployment_id} <https://docs.github.com/en/rest/reference/repos#deployments>`_ 2209 :param: id_: int 2210 :rtype: :class:`github.Deployment.Deployment` 2211 """ 2212 assert isinstance(id_, int), id_ 2213 headers, data = self._requester.requestJsonAndCheck( 2214 "GET", 2215 f"{self.url}/deployments/{id_}", 2216 headers={"Accept": Consts.deploymentEnhancementsPreview}, 2217 ) 2218 return github.Deployment.Deployment(self._requester, headers, data, completed=True) 2219 2220 def create_deployment( 2221 self, 2222 ref: str, 2223 task: Opt[str] = NotSet, 2224 auto_merge: Opt[bool] = NotSet, 2225 required_contexts: Opt[list[str]] = NotSet, 2226 payload: Opt[dict[str, Any]] = NotSet, 2227 environment: Opt[str] = NotSet, 2228 description: Opt[str] = NotSet, 2229 transient_environment: Opt[bool] = NotSet, 2230 production_environment: Opt[bool] = NotSet, 2231 ) -> Deployment: 2232 """ 2233 :calls: `POST /repos/{owner}/{repo}/deployments <https://docs.github.com/en/rest/reference/repos#deployments>`_ 2234 :param: ref: string 2235 :param: task: string 2236 :param: auto_merge: bool 2237 :param: required_contexts: list of status contexts 2238 :param: payload: dict 2239 :param: environment: string 2240 :param: description: string 2241 :param: transient_environment: bool 2242 :param: production_environment: bool 2243 :rtype: :class:`github.Deployment.Deployment` 2244 """ 2245 assert isinstance(ref, str), ref 2246 assert is_undefined(task) or isinstance(task, str), task 2247 assert is_undefined(auto_merge) or isinstance(auto_merge, bool), auto_merge 2248 assert is_undefined(required_contexts) or isinstance( 2249 required_contexts, list 2250 ), required_contexts # need to do better checking here 2251 assert is_undefined(payload) or isinstance(payload, dict), payload 2252 assert is_undefined(environment) or isinstance(environment, str), environment 2253 assert is_undefined(description) or isinstance(description, str), description 2254 assert is_undefined(transient_environment) or isinstance(transient_environment, bool), transient_environment 2255 assert is_undefined(production_environment) or isinstance(production_environment, bool), production_environment 2256 2257 post_parameters: dict[str, Any] = {"ref": ref} 2258 if is_defined(task): 2259 post_parameters["task"] = task 2260 if is_defined(auto_merge): 2261 post_parameters["auto_merge"] = auto_merge 2262 if is_defined(required_contexts): 2263 post_parameters["required_contexts"] = required_contexts 2264 if is_defined(payload): 2265 post_parameters["payload"] = payload 2266 if is_defined(environment): 2267 post_parameters["environment"] = environment 2268 if is_defined(description): 2269 post_parameters["description"] = description 2270 if is_defined(transient_environment): 2271 post_parameters["transient_environment"] = transient_environment 2272 if is_defined(production_environment): 2273 post_parameters["production_environment"] = production_environment 2274 2275 headers, data = self._requester.requestJsonAndCheck( 2276 "POST", 2277 f"{self.url}/deployments", 2278 input=post_parameters, 2279 headers={"Accept": Consts.deploymentEnhancementsPreview}, 2280 ) 2281 2282 return github.Deployment.Deployment(self._requester, headers, data, completed=True) 2283 2284 def get_top_referrers(self) -> None | list[Referrer]: 2285 """ 2286 :calls: `GET /repos/{owner}/{repo}/traffic/popular/referrers <https://docs.github.com/en/rest/reference/repos#traffic>`_ 2287 """ 2288 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/traffic/popular/referrers") 2289 if isinstance(data, list): 2290 return [github.Referrer.Referrer(self._requester, headers, item, completed=True) for item in data] 2291 2292 def get_top_paths(self) -> None | list[Path]: 2293 """ 2294 :calls: `GET /repos/{owner}/{repo}/traffic/popular/paths <https://docs.github.com/en/rest/reference/repos#traffic>`_ 2295 :rtype: :class:`list` of :class:`github.Path.Path` 2296 """ 2297 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/traffic/popular/paths") 2298 if isinstance(data, list): 2299 return [github.Path.Path(self._requester, headers, item, completed=True) for item in data] 2300 2301 def get_views_traffic(self, per: Opt[str] = NotSet) -> None | dict[str, int | list[View]]: 2302 """ 2303 :calls: `GET /repos/{owner}/{repo}/traffic/views <https://docs.github.com/en/rest/reference/repos#traffic>`_ 2304 :param per: string, must be one of day or week, day by default 2305 """ 2306 assert is_undefined(per) or ( 2307 isinstance(per, str) and (per == "day" or per == "week") 2308 ), "per must be day or week, day by default" 2309 url_parameters = dict() 2310 if is_defined(per): 2311 url_parameters["per"] = per 2312 headers, data = self._requester.requestJsonAndCheck( 2313 "GET", f"{self.url}/traffic/views", parameters=url_parameters 2314 ) 2315 if (isinstance(data, dict)) and ("views" in data) and (isinstance(data["views"], list)): 2316 data["views"] = [github.View.View(self._requester, headers, item, completed=True) for item in data["views"]] 2317 return data 2318 2319 def get_clones_traffic(self, per: Opt[str] = NotSet) -> dict[str, int | list[Clones]] | None: 2320 """ 2321 :calls: `GET /repos/{owner}/{repo}/traffic/clones <https://docs.github.com/en/rest/reference/repos#traffic>`_ 2322 :param per: string, must be one of day or week, day by default 2323 :rtype: None or list of :class:`github.Clones.Clones` 2324 """ 2325 assert is_undefined(per) or ( 2326 isinstance(per, str) and (per == "day" or per == "week") 2327 ), "per must be day or week, day by default" 2328 url_parameters: dict[str, Any] = NotSet.remove_unset_items({"per": per}) 2329 headers, data = self._requester.requestJsonAndCheck( 2330 "GET", f"{self.url}/traffic/clones", parameters=url_parameters 2331 ) 2332 if (isinstance(data, dict)) and ("clones" in data) and (isinstance(data["clones"], list)): 2333 data["clones"] = [ 2334 github.Clones.Clones(self._requester, headers, item, completed=True) for item in data["clones"] 2335 ] 2336 return data 2337 2338 def get_projects(self, state: Opt[str] = NotSet) -> PaginatedList[Project]: 2339 """ 2340 :calls: `GET /repos/{owner}/{repo}/projects <https://docs.github.com/en/rest/reference/projects#list-repository-projects>`_ 2341 :rtype: :class:`PaginatedList` of :class:`github.Project.Project` 2342 :param state: string 2343 """ 2344 2345 url_parameters = dict() 2346 if is_defined(state): 2347 url_parameters["state"] = state 2348 2349 return PaginatedList( 2350 github.Project.Project, 2351 self._requester, 2352 f"{self.url}/projects", 2353 url_parameters, 2354 {"Accept": Consts.mediaTypeProjectsPreview}, 2355 ) 2356 2357 def get_autolinks(self) -> PaginatedList[Autolink]: 2358 """ 2359 :calls: `GET /repos/{owner}/{repo}/autolinks <http://docs.github.com/en/rest/reference/repos>`_ 2360 :rtype: :class:`PaginatedList` of :class:`github.Autolink.Autolink` 2361 """ 2362 return PaginatedList(github.Autolink.Autolink, self._requester, f"{self.url}/autolinks", None) 2363 2364 def create_file( 2365 self, 2366 path: str, 2367 message: str, 2368 content: str | bytes, 2369 branch: Opt[str] = NotSet, 2370 committer: Opt[InputGitAuthor] = NotSet, 2371 author: Opt[InputGitAuthor] = NotSet, 2372 ) -> dict[str, ContentFile | Commit]: 2373 """Create a file in this repository. 2374 2375 :calls: `PUT /repos/{owner}/{repo}/contents/{path} <https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents>`_ 2376 :param path: string, (required), path of the file in the repository 2377 :param message: string, (required), commit message 2378 :param content: string, (required), the actual data in the file 2379 :param branch: string, (optional), branch to create the commit on. Defaults to the default branch of the repository 2380 :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. 2381 :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. 2382 :rtype: { 2383 'content': :class:`ContentFile <github.ContentFile.ContentFile>`:, 2384 'commit': :class:`Commit <github.Commit.Commit>`} 2385 """ 2386 assert isinstance(path, str) 2387 assert isinstance(message, str) 2388 assert isinstance(content, (str, bytes)) 2389 assert is_undefined(branch) or isinstance(branch, str) 2390 assert is_undefined(author) or isinstance(author, github.InputGitAuthor) 2391 assert is_undefined(committer) or isinstance(committer, github.InputGitAuthor) 2392 2393 if not isinstance(content, bytes): 2394 content = content.encode("utf-8") 2395 content = b64encode(content).decode("utf-8") 2396 put_parameters: dict[str, Any] = {"message": message, "content": content} 2397 2398 if is_defined(branch): 2399 put_parameters["branch"] = branch 2400 if is_defined(author): 2401 put_parameters["author"] = author._identity 2402 if is_defined(committer): 2403 put_parameters["committer"] = committer._identity 2404 2405 headers, data = self._requester.requestJsonAndCheck( 2406 "PUT", 2407 f"{self.url}/contents/{urllib.parse.quote(path)}", 2408 input=put_parameters, 2409 ) 2410 2411 return { 2412 "content": github.ContentFile.ContentFile(self._requester, headers, data["content"], completed=False), 2413 "commit": github.Commit.Commit(self._requester, headers, data["commit"], completed=True), 2414 } 2415 2416 def get_repository_advisories( 2417 self, 2418 ) -> PaginatedList[github.RepositoryAdvisory.RepositoryAdvisory]: 2419 """ 2420 :calls: `GET /repos/{owner}/{repo}/security-advisories <https://docs.github.com/en/rest/security-advisories/repository-advisories>`_ 2421 :rtype: :class:`PaginatedList` of :class:`github.RepositoryAdvisory.RepositoryAdvisory` 2422 """ 2423 return PaginatedList( 2424 github.RepositoryAdvisory.RepositoryAdvisory, 2425 self._requester, 2426 f"{self.url}/security-advisories", 2427 None, 2428 ) 2429 2430 def get_repository_advisory(self, ghsa: str) -> github.RepositoryAdvisory.RepositoryAdvisory: 2431 """ 2432 :calls: `GET /repos/{owner}/{repo}/security-advisories/{ghsa} <https://docs.github.com/en/rest/security-advisories/repository-advisories>`_ 2433 :param ghsa: string 2434 :rtype: :class:`github.RepositoryAdvisory.RepositoryAdvisory` 2435 """ 2436 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/security-advisories/{ghsa}") 2437 return github.RepositoryAdvisory.RepositoryAdvisory(self._requester, headers, data, completed=True) 2438 2439 def update_file( 2440 self, 2441 path: str, 2442 message: str, 2443 content: bytes | str, 2444 sha: str, 2445 branch: Opt[str] = NotSet, 2446 committer: Opt[InputGitAuthor] = NotSet, 2447 author: Opt[InputGitAuthor] = NotSet, 2448 ) -> dict[str, ContentFile | Commit]: 2449 """This method updates a file in a repository 2450 2451 :calls: `PUT /repos/{owner}/{repo}/contents/{path} <https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents>`_ 2452 :param path: string, Required. The content path. 2453 :param message: string, Required. The commit message. 2454 :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded. 2455 :param sha: string, Required. The blob SHA of the file being replaced. 2456 :param branch: string. The branch name. Default: the repository’s default branch (usually master) 2457 :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. 2458 :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. 2459 :rtype: { 2460 'content': :class:`ContentFile <github.ContentFile.ContentFile>`:, 2461 'commit': :class:`Commit <github.Commit.Commit>`} 2462 """ 2463 assert isinstance(path, str) 2464 assert isinstance(message, str) 2465 assert isinstance(content, (str, bytes)) 2466 assert isinstance(sha, str) 2467 assert is_undefined(branch) or isinstance(branch, str) 2468 assert is_undefined(author) or isinstance(author, github.InputGitAuthor) 2469 assert is_undefined(committer) or isinstance(committer, github.InputGitAuthor) 2470 2471 if not isinstance(content, bytes): 2472 content = content.encode("utf-8") 2473 content = b64encode(content).decode("utf-8") 2474 2475 put_parameters: dict[str, Any] = {"message": message, "content": content, "sha": sha} 2476 2477 if is_defined(branch): 2478 put_parameters["branch"] = branch 2479 if is_defined(author): 2480 put_parameters["author"] = author._identity 2481 if is_defined(committer): 2482 put_parameters["committer"] = committer._identity 2483 2484 headers, data = self._requester.requestJsonAndCheck( 2485 "PUT", 2486 f"{self.url}/contents/{urllib.parse.quote(path)}", 2487 input=put_parameters, 2488 ) 2489 2490 return { 2491 "commit": github.Commit.Commit(self._requester, headers, data["commit"], completed=True), 2492 "content": github.ContentFile.ContentFile(self._requester, headers, data["content"], completed=False), 2493 } 2494 2495 def delete_file( 2496 self, 2497 path: str, 2498 message: str, 2499 sha: str, 2500 branch: Opt[str] = NotSet, 2501 committer: Opt[InputGitAuthor] = NotSet, 2502 author: Opt[InputGitAuthor] = NotSet, 2503 ) -> dict[str, Commit | _NotSetType]: 2504 """This method deletes a file in a repository 2505 2506 :calls: `DELETE /repos/{owner}/{repo}/contents/{path} <https://docs.github.com/en/rest/reference/repos#delete-a-file>`_ 2507 :param path: string, Required. The content path. 2508 :param message: string, Required. The commit message. 2509 :param sha: string, Required. The blob SHA of the file being replaced. 2510 :param branch: string. The branch name. Default: the repository’s default branch (usually master) 2511 :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. 2512 :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. 2513 :rtype: { 2514 'content': :class:`null <NotSet>`:, 2515 'commit': :class:`Commit <github.Commit.Commit>`} 2516 """ 2517 assert isinstance(path, str), "path must be str/unicode object" 2518 assert isinstance(message, str), "message must be str/unicode object" 2519 assert isinstance(sha, str), "sha must be a str/unicode object" 2520 assert is_undefined(branch) or isinstance(branch, str), "branch must be a str/unicode object" 2521 assert is_undefined(author) or isinstance( 2522 author, github.InputGitAuthor 2523 ), "author must be a github.InputGitAuthor object" 2524 assert is_undefined(committer) or isinstance( 2525 committer, github.InputGitAuthor 2526 ), "committer must be a github.InputGitAuthor object" 2527 2528 url_parameters: dict[str, Any] = {"message": message, "sha": sha} 2529 if is_defined(branch): 2530 url_parameters["branch"] = branch 2531 if is_defined(author): 2532 url_parameters["author"] = author._identity 2533 if is_defined(committer): 2534 url_parameters["committer"] = committer._identity 2535 2536 headers, data = self._requester.requestJsonAndCheck( 2537 "DELETE", 2538 f"{self.url}/contents/{urllib.parse.quote(path)}", 2539 input=url_parameters, 2540 ) 2541 2542 return { 2543 "commit": github.Commit.Commit(self._requester, headers, data["commit"], completed=True), 2544 "content": NotSet, 2545 } 2546 2547 @deprecated( 2548 reason=""" 2549 Repository.get_dir_contents() is deprecated, use 2550 Repository.get_contents() instead. 2551 """ 2552 ) 2553 def get_dir_contents(self, path: str, ref: Opt[str] = NotSet) -> list[ContentFile]: 2554 """ 2555 :calls: `GET /repos/{owner}/{repo}/contents/{path} <https://docs.github.com/en/rest/reference/repos#contents>`_ 2556 """ 2557 return self.get_contents(path, ref=ref) # type: ignore 2558 2559 def get_contributors(self, anon: Opt[str] = NotSet) -> PaginatedList[NamedUser]: 2560 """ 2561 :calls: `GET /repos/{owner}/{repo}/contributors <https://docs.github.com/en/rest/reference/repos>`_ 2562 :param anon: string 2563 :rtype: :class:`PaginatedList` of :class:`github.NamedUser.NamedUser` 2564 """ 2565 url_parameters = dict() 2566 if is_defined(anon): 2567 url_parameters["anon"] = anon 2568 2569 return PaginatedList( 2570 github.NamedUser.NamedUser, 2571 self._requester, 2572 f"{self.url}/contributors", 2573 url_parameters, 2574 ) 2575 2576 def get_download(self, id: int) -> Download: 2577 """ 2578 :calls: `GET /repos/{owner}/{repo}/downloads/{id} <https://docs.github.com/en/rest/reference/repos>`_ 2579 :param id: integer 2580 :rtype: :class:`github.Download.Download` 2581 """ 2582 assert isinstance(id, int), id 2583 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/downloads/{id}") 2584 return github.Download.Download(self._requester, headers, data, completed=True) 2585 2586 def get_downloads(self) -> PaginatedList[Download]: 2587 """ 2588 :calls: `GET /repos/{owner}/{repo}/downloads <https://docs.github.com/en/rest/reference/repos>`_ 2589 :rtype: :class:`PaginatedList` of :class:`github.Download.Download` 2590 """ 2591 return PaginatedList(github.Download.Download, self._requester, f"{self.url}/downloads", None) 2592 2593 def get_events(self) -> PaginatedList[Event]: 2594 """ 2595 :calls: `GET /repos/{owner}/{repo}/events <https://docs.github.com/en/rest/reference/activity#events>`_ 2596 :rtype: :class:`PaginatedList` of :class:`github.Event.Event` 2597 """ 2598 return PaginatedList(github.Event.Event, self._requester, f"{self.url}/events", None) 2599 2600 def get_forks(self) -> PaginatedList[Repository]: 2601 """ 2602 :calls: `GET /repos/{owner}/{repo}/forks <https://docs.github.com/en/rest/reference/repos#forks>`_ 2603 :rtype: :class:`PaginatedList` of :class:`github.Repository.Repository` 2604 """ 2605 return PaginatedList(Repository, self._requester, f"{self.url}/forks", None) 2606 2607 def create_fork( 2608 self, 2609 organization: Organization | Opt[str] = NotSet, 2610 name: Opt[str] = NotSet, 2611 default_branch_only: Opt[bool] = NotSet, 2612 ) -> Repository: 2613 """ 2614 :calls: `POST /repos/{owner}/{repo}/forks <https://docs.github.com/en/rest/reference/repos#forks>`_ 2615 :param organization: :class:`github.Organization.Organization` or string 2616 :param name: string 2617 :param default_branch_only: bool 2618 :rtype: :class:`github.Repository.Repository` 2619 """ 2620 post_parameters: dict[str, Any] = {} 2621 if isinstance(organization, github.Organization.Organization): 2622 post_parameters["organization"] = organization.login 2623 elif isinstance(organization, str): 2624 post_parameters["organization"] = organization 2625 else: 2626 assert is_undefined(organization), organization 2627 assert is_undefined(name) or isinstance(name, str), name 2628 assert is_undefined(default_branch_only) or isinstance(default_branch_only, bool), default_branch_only 2629 if is_defined(name): 2630 post_parameters["name"] = name 2631 if is_defined(default_branch_only): 2632 post_parameters["default_branch_only"] = default_branch_only 2633 headers, data = self._requester.requestJsonAndCheck( 2634 "POST", 2635 f"{self.url}/forks", 2636 input=post_parameters, 2637 ) 2638 return Repository(self._requester, headers, data, completed=True) 2639 2640 def get_git_blob(self, sha: str) -> GitBlob: 2641 """ 2642 :calls: `GET /repos/{owner}/{repo}/git/blobs/{sha} <https://docs.github.com/en/rest/reference/git#blobs>`_ 2643 :param sha: string 2644 :rtype: :class:`github.GitBlob.GitBlob` 2645 """ 2646 assert isinstance(sha, str), sha 2647 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/git/blobs/{sha}") 2648 return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) 2649 2650 def get_git_commit(self, sha: str) -> GitCommit: 2651 """ 2652 :calls: `GET /repos/{owner}/{repo}/git/commits/{sha} <https://docs.github.com/en/rest/reference/git#commits>`_ 2653 :param sha: string 2654 :rtype: :class:`github.GitCommit.GitCommit` 2655 """ 2656 assert isinstance(sha, str), sha 2657 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/git/commits/{sha}") 2658 return github.GitCommit.GitCommit(self._requester, headers, data, completed=True) 2659 2660 def get_git_ref(self, ref: str) -> GitRef: 2661 """ 2662 :calls: `GET /repos/{owner}/{repo}/git/refs/{ref} <https://docs.github.com/en/rest/reference/git#references>`_ 2663 :param ref: string 2664 :rtype: :class:`github.GitRef.GitRef` 2665 """ 2666 prefix = "/git/refs/" 2667 if not self._requester.FIX_REPO_GET_GIT_REF: 2668 prefix = "/git/" 2669 assert isinstance(ref, str), ref 2670 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}{prefix}{ref}") 2671 return github.GitRef.GitRef(self._requester, headers, data, completed=True) 2672 2673 def get_git_refs(self) -> PaginatedList[GitRef]: 2674 """ 2675 :calls: `GET /repos/{owner}/{repo}/git/refs <https://docs.github.com/en/rest/reference/git#references>`_ 2676 :rtype: :class:`PaginatedList` of :class:`github.GitRef.GitRef` 2677 """ 2678 return PaginatedList(github.GitRef.GitRef, self._requester, f"{self.url}/git/refs", None) 2679 2680 def get_git_matching_refs(self, ref: str) -> PaginatedList[GitRef]: 2681 """ 2682 :calls: `GET /repos/{owner}/{repo}/git/matching-refs/{ref} <https://docs.github.com/en/rest/reference/git#list-matching-references>`_ 2683 :rtype: :class:`PaginatedList` of :class:`github.GitRef.GitRef` 2684 """ 2685 assert isinstance(ref, str), ref 2686 return PaginatedList( 2687 github.GitRef.GitRef, 2688 self._requester, 2689 f"{self.url}/git/matching-refs/{ref}", 2690 None, 2691 ) 2692 2693 def get_git_tag(self, sha: str) -> GitTag: 2694 """ 2695 :calls: `GET /repos/{owner}/{repo}/git/tags/{sha} <https://docs.github.com/en/rest/reference/git#tags>`_ 2696 :param sha: string 2697 :rtype: :class:`github.GitTag.GitTag` 2698 """ 2699 assert isinstance(sha, str), sha 2700 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/git/tags/{sha}") 2701 return github.GitTag.GitTag(self._requester, headers, data, completed=True) 2702 2703 def get_git_tree(self, sha: str, recursive: Opt[bool] = NotSet) -> GitTree: 2704 """ 2705 :calls: `GET /repos/{owner}/{repo}/git/trees/{sha} <https://docs.github.com/en/rest/reference/git#trees>`_ 2706 :param sha: string 2707 :param recursive: bool 2708 :rtype: :class:`github.GitTree.GitTree` 2709 """ 2710 assert isinstance(sha, str), sha 2711 assert is_undefined(recursive) or isinstance(recursive, bool), recursive 2712 url_parameters = dict() 2713 if is_defined(recursive) and recursive: 2714 # GitHub API requires the recursive parameter be set to 1. 2715 url_parameters["recursive"] = 1 2716 headers, data = self._requester.requestJsonAndCheck( 2717 "GET", f"{self.url}/git/trees/{sha}", parameters=url_parameters 2718 ) 2719 return github.GitTree.GitTree(self._requester, headers, data, completed=True) 2720 2721 def get_hook(self, id: int) -> Hook: 2722 """ 2723 :calls: `GET /repos/{owner}/{repo}/hooks/{id} <https://docs.github.com/en/rest/reference/repos#webhooks>`_ 2724 :param id: integer 2725 :rtype: :class:`github.Hook.Hook` 2726 """ 2727 assert isinstance(id, int), id 2728 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/hooks/{id}") 2729 return github.Hook.Hook(self._requester, headers, data, completed=True) 2730 2731 def get_hooks(self) -> PaginatedList[Hook]: 2732 """ 2733 :calls: `GET /repos/{owner}/{repo}/hooks <https://docs.github.com/en/rest/reference/repos#webhooks>`_ 2734 :rtype: :class:`PaginatedList` of :class:`github.Hook.Hook` 2735 """ 2736 return PaginatedList(github.Hook.Hook, self._requester, f"{self.url}/hooks", None) 2737 2738 def get_hook_delivery(self, hook_id: int, delivery_id: int) -> github.HookDelivery.HookDelivery: 2739 """ 2740 :calls: `GET /repos/{owner}/{repo}/hooks/{hook_id}/deliveries/{delivery_id} <https://docs.github.com/en/rest/webhooks/repo-deliveries>`_ 2741 :param hook_id: integer 2742 :param delivery_id: integer 2743 :rtype: :class:`github.HookDelivery.HookDelivery` 2744 """ 2745 assert isinstance(hook_id, int), hook_id 2746 assert isinstance(delivery_id, int), delivery_id 2747 headers, data = self._requester.requestJsonAndCheck( 2748 "GET", f"{self.url}/hooks/{hook_id}/deliveries/{delivery_id}" 2749 ) 2750 return github.HookDelivery.HookDelivery(self._requester, headers, data, completed=True) 2751 2752 def get_hook_deliveries(self, hook_id: int) -> PaginatedList[github.HookDelivery.HookDeliverySummary]: 2753 """ 2754 :calls: `GET /repos/{owner}/{repo}/hooks/{hook_id}/deliveries <https://docs.github.com/en/rest/webhooks/repo-deliveries>`_ 2755 :param hook_id: integer 2756 :rtype: :class:`PaginatedList` of :class:`github.HookDelivery.HookDeliverySummary` 2757 """ 2758 assert isinstance(hook_id, int), hook_id 2759 2760 return PaginatedList( 2761 github.HookDelivery.HookDeliverySummary, 2762 self._requester, 2763 f"{self.url}/hooks/{hook_id}/deliveries", 2764 None, 2765 ) 2766 2767 def get_issue(self, number: int) -> Issue: 2768 """ 2769 :calls: `GET /repos/{owner}/{repo}/issues/{number} <https://docs.github.com/en/rest/reference/issues>`_ 2770 :param number: integer 2771 :rtype: :class:`github.Issue.Issue` 2772 """ 2773 assert isinstance(number, int), number 2774 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/issues/{number}") 2775 return github.Issue.Issue(self._requester, headers, data, completed=True) 2776 2777 def get_issues( 2778 self, 2779 milestone: Milestone | Opt[str] = NotSet, 2780 state: Opt[str] = NotSet, 2781 assignee: NamedUser | Opt[str] = NotSet, 2782 mentioned: Opt[NamedUser] = NotSet, 2783 labels: Opt[list[str] | list[Label]] = NotSet, 2784 sort: Opt[str] = NotSet, 2785 direction: Opt[str] = NotSet, 2786 since: Opt[datetime] = NotSet, 2787 creator: Opt[NamedUser] = NotSet, 2788 ) -> PaginatedList[Issue]: 2789 """ 2790 :calls: `GET /repos/{owner}/{repo}/issues <https://docs.github.com/en/rest/reference/issues>`_ 2791 :param milestone: :class:`github.Milestone.Milestone` or "none" or "*" 2792 :param state: string. `open`, `closed`, or `all`. If this is not set the GitHub API default behavior will be used. At the moment this is to return only open issues. This might change anytime on GitHub API side and it could be clever to explicitly specify the state value. 2793 :param assignee: string or :class:`github.NamedUser.NamedUser` or "none" or "*" 2794 :param mentioned: :class:`github.NamedUser.NamedUser` 2795 :param labels: list of string or :class:`github.Label.Label` 2796 :param sort: string 2797 :param direction: string 2798 :param since: datetime 2799 :param creator: string or :class:`github.NamedUser.NamedUser` 2800 :rtype: :class:`PaginatedList` of :class:`github.Issue.Issue` 2801 """ 2802 assert ( 2803 is_undefined(milestone) 2804 or milestone == "*" 2805 or milestone == "none" 2806 or isinstance(milestone, github.Milestone.Milestone) 2807 ), milestone 2808 assert is_undefined(state) or isinstance(state, str), state 2809 assert ( 2810 is_undefined(assignee) or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, str) 2811 ), assignee 2812 assert is_undefined(mentioned) or isinstance(mentioned, github.NamedUser.NamedUser), mentioned 2813 assert is_optional_list(labels, (github.Label.Label, str)), labels 2814 assert is_undefined(sort) or isinstance(sort, str), sort 2815 assert is_undefined(direction) or isinstance(direction, str), direction 2816 assert is_undefined(since) or isinstance(since, datetime), since 2817 assert ( 2818 is_undefined(creator) or isinstance(creator, github.NamedUser.NamedUser) or isinstance(creator, str) 2819 ), creator 2820 url_parameters: dict[str, Any] = {} 2821 if is_defined(milestone): 2822 if isinstance(milestone, github.Milestone.Milestone): 2823 url_parameters["milestone"] = milestone._identity 2824 else: 2825 url_parameters["milestone"] = milestone 2826 if is_defined(state): 2827 url_parameters["state"] = state 2828 if is_defined(assignee): 2829 if isinstance(assignee, github.NamedUser.NamedUser): 2830 url_parameters["assignee"] = assignee._identity 2831 else: 2832 url_parameters["assignee"] = assignee 2833 if is_defined(mentioned): 2834 url_parameters["mentioned"] = mentioned._identity 2835 if is_defined(labels): 2836 url_parameters["labels"] = ",".join( 2837 [label.name if isinstance(label, github.Label.Label) else label for label in labels] # type: ignore 2838 ) 2839 if is_defined(sort): 2840 url_parameters["sort"] = sort 2841 if is_defined(direction): 2842 url_parameters["direction"] = direction 2843 if is_defined(since): 2844 url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") 2845 if is_defined(creator): 2846 if isinstance(creator, str): 2847 url_parameters["creator"] = creator 2848 else: 2849 url_parameters["creator"] = creator._identity 2850 return PaginatedList(github.Issue.Issue, self._requester, f"{self.url}/issues", url_parameters) 2851 2852 def get_issues_comments( 2853 self, 2854 sort: Opt[str] = NotSet, 2855 direction: Opt[str] = NotSet, 2856 since: Opt[datetime] = NotSet, 2857 ) -> PaginatedList[IssueComment]: 2858 """ 2859 :calls: `GET /repos/{owner}/{repo}/issues/comments <https://docs.github.com/en/rest/reference/issues#comments>`_ 2860 :param sort: string 2861 :param direction: string 2862 :param since: datetime 2863 :rtype: :class:`PaginatedList` of :class:`github.IssueComment.IssueComment` 2864 """ 2865 assert is_undefined(sort) or isinstance(sort, str), sort 2866 assert is_undefined(direction) or isinstance(direction, str), direction 2867 assert is_undefined(since) or isinstance(since, datetime), since 2868 url_parameters = dict() 2869 if is_defined(sort): 2870 url_parameters["sort"] = sort 2871 if is_defined(direction): 2872 url_parameters["direction"] = direction 2873 if is_defined(since): 2874 url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") 2875 return PaginatedList( 2876 github.IssueComment.IssueComment, 2877 self._requester, 2878 f"{self.url}/issues/comments", 2879 url_parameters, 2880 ) 2881 2882 def get_issues_event(self, id: int) -> IssueEvent: 2883 """ 2884 :calls: `GET /repos/{owner}/{repo}/issues/events/{id} <https://docs.github.com/en/rest/reference/issues#events>`_ 2885 :param id: integer 2886 :rtype: :class:`github.IssueEvent.IssueEvent` 2887 """ 2888 assert isinstance(id, int), id 2889 headers, data = self._requester.requestJsonAndCheck( 2890 "GET", 2891 f"{self.url}/issues/events/{id}", 2892 headers={"Accept": Consts.mediaTypeLockReasonPreview}, 2893 ) 2894 return github.IssueEvent.IssueEvent(self._requester, headers, data, completed=True) 2895 2896 def get_issues_events(self) -> PaginatedList[IssueEvent]: 2897 """ 2898 :calls: `GET /repos/{owner}/{repo}/issues/events <https://docs.github.com/en/rest/reference/issues#events>`_ 2899 :rtype: :class:`PaginatedList` of :class:`github.IssueEvent.IssueEvent` 2900 """ 2901 return PaginatedList( 2902 github.IssueEvent.IssueEvent, 2903 self._requester, 2904 f"{self.url}/issues/events", 2905 None, 2906 headers={"Accept": Consts.mediaTypeLockReasonPreview}, 2907 ) 2908 2909 def get_key(self, id: int) -> RepositoryKey: 2910 """ 2911 :calls: `GET /repos/{owner}/{repo}/keys/{id} <https://docs.github.com/en/rest/reference/repos#deploy-keys>`_ 2912 :param id: integer 2913 :rtype: :class:`github.RepositoryKey.RepositoryKey` 2914 """ 2915 assert isinstance(id, int), id 2916 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/keys/{id}") 2917 return github.RepositoryKey.RepositoryKey(self._requester, headers, data, completed=True) 2918 2919 def get_keys(self) -> PaginatedList[RepositoryKey]: 2920 """ 2921 :calls: `GET /repos/{owner}/{repo}/keys <https://docs.github.com/en/rest/reference/repos#deploy-keys>`_ 2922 :rtype: :class:`PaginatedList` of :class:`github.RepositoryKey.RepositoryKey` 2923 """ 2924 return PaginatedList( 2925 github.RepositoryKey.RepositoryKey, 2926 self._requester, 2927 f"{self.url}/keys", 2928 None, 2929 ) 2930 2931 def get_label(self, name: str) -> Label: 2932 """ 2933 :calls: `GET /repos/{owner}/{repo}/labels/{name} <https://docs.github.com/en/rest/reference/issues#labels>`_ 2934 :param name: string 2935 :rtype: :class:`github.Label.Label` 2936 """ 2937 assert isinstance(name, str), name 2938 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/labels/{urllib.parse.quote(name)}") 2939 return github.Label.Label(self._requester, headers, data, completed=True) 2940 2941 def get_labels(self) -> PaginatedList[Label]: 2942 """ 2943 :calls: `GET /repos/{owner}/{repo}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_ 2944 :rtype: :class:`PaginatedList` of :class:`github.Label.Label` 2945 """ 2946 return PaginatedList(github.Label.Label, self._requester, f"{self.url}/labels", None) 2947 2948 def get_languages(self) -> dict[str, int]: 2949 """ 2950 :calls: `GET /repos/{owner}/{repo}/languages <https://docs.github.com/en/rest/reference/repos>`_ 2951 :rtype: dict of string to integer 2952 """ 2953 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/languages") 2954 return data 2955 2956 def get_license(self) -> ContentFile: 2957 """ 2958 :calls: `GET /repos/{owner}/{repo}/license <https://docs.github.com/en/rest/reference/licenses>`_ 2959 :rtype: :class:`github.ContentFile.ContentFile` 2960 """ 2961 2962 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/license") 2963 return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) 2964 2965 def get_milestone(self, number: int) -> Milestone: 2966 """ 2967 :calls: `GET /repos/{owner}/{repo}/milestones/{number} <https://docs.github.com/en/rest/reference/issues#milestones>`_ 2968 :param number: integer 2969 :rtype: :class:`github.Milestone.Milestone` 2970 """ 2971 assert isinstance(number, int), number 2972 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/milestones/{number}") 2973 return github.Milestone.Milestone(self._requester, headers, data, completed=True) 2974 2975 def get_milestones( 2976 self, 2977 state: Opt[str] = NotSet, 2978 sort: Opt[str] = NotSet, 2979 direction: Opt[str] = NotSet, 2980 ) -> PaginatedList[Milestone]: 2981 """ 2982 :calls: `GET /repos/{owner}/{repo}/milestones <https://docs.github.com/en/rest/reference/issues#milestones>`_ 2983 :param state: string 2984 :param sort: string 2985 :param direction: string 2986 :rtype: :class:`PaginatedList` of :class:`github.Milestone.Milestone` 2987 """ 2988 assert is_undefined(state) or isinstance(state, str), state 2989 assert is_undefined(sort) or isinstance(sort, str), sort 2990 assert is_undefined(direction) or isinstance(direction, str), direction 2991 url_parameters = dict() 2992 if is_defined(state): 2993 url_parameters["state"] = state 2994 if is_defined(sort): 2995 url_parameters["sort"] = sort 2996 if is_defined(direction): 2997 url_parameters["direction"] = direction 2998 return PaginatedList( 2999 github.Milestone.Milestone, 3000 self._requester, 3001 f"{self.url}/milestones", 3002 url_parameters, 3003 ) 3004 3005 def get_network_events(self) -> PaginatedList[Event]: 3006 """ 3007 :calls: `GET /networks/{owner}/{repo}/events <https://docs.github.com/en/rest/reference/activity#events>`_ 3008 :rtype: :class:`PaginatedList` of :class:`github.Event.Event` 3009 """ 3010 return PaginatedList( 3011 github.Event.Event, 3012 self._requester, 3013 f"/networks/{self.owner.login}/{self.name}/events", 3014 None, 3015 ) 3016 3017 def get_public_key(self) -> PublicKey: 3018 """ 3019 :calls: `GET /repos/{owner}/{repo}/actions/secrets/public-key <https://docs.github.com/en/rest/reference/actions#get-a-repository-public-key>`_ 3020 :rtype: :class:`github.PublicKey.PublicKey` 3021 """ 3022 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/secrets/public-key") 3023 return github.PublicKey.PublicKey(self._requester, headers, data, completed=True) 3024 3025 def get_pull(self, number: int) -> PullRequest: 3026 """ 3027 :calls: `GET /repos/{owner}/{repo}/pulls/{number} <https://docs.github.com/en/rest/reference/pulls>`_ 3028 :param number: integer 3029 :rtype: :class:`github.PullRequest.PullRequest` 3030 """ 3031 assert isinstance(number, int), number 3032 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/pulls/{number}") 3033 return github.PullRequest.PullRequest(self._requester, headers, data, completed=True) 3034 3035 def get_pulls( 3036 self, 3037 state: Opt[str] = NotSet, 3038 sort: Opt[str] = NotSet, 3039 direction: Opt[str] = NotSet, 3040 base: Opt[str] = NotSet, 3041 head: Opt[str] = NotSet, 3042 ) -> PaginatedList[PullRequest]: 3043 """ 3044 :calls: `GET /repos/{owner}/{repo}/pulls <https://docs.github.com/en/rest/reference/pulls>`_ 3045 :param state: string 3046 :param sort: string 3047 :param direction: string 3048 :param base: string 3049 :param head: string 3050 :rtype: :class:`PaginatedList` of :class:`github.PullRequest.PullRequest` 3051 """ 3052 assert is_undefined(state) or isinstance(state, str), state 3053 assert is_undefined(sort) or isinstance(sort, str), sort 3054 assert is_undefined(direction) or isinstance(direction, str), direction 3055 assert is_undefined(base) or isinstance(base, str), base 3056 assert is_undefined(head) or isinstance(head, str), head 3057 url_parameters = dict() 3058 if is_defined(state): 3059 url_parameters["state"] = state 3060 if is_defined(sort): 3061 url_parameters["sort"] = sort 3062 if is_defined(direction): 3063 url_parameters["direction"] = direction 3064 if is_defined(base): 3065 url_parameters["base"] = base 3066 if is_defined(head): 3067 url_parameters["head"] = head 3068 return PaginatedList( 3069 github.PullRequest.PullRequest, 3070 self._requester, 3071 f"{self.url}/pulls", 3072 url_parameters, 3073 ) 3074 3075 def get_pulls_comments( 3076 self, 3077 sort: Opt[str] = NotSet, 3078 direction: Opt[str] = NotSet, 3079 since: Opt[datetime] = NotSet, 3080 ) -> PaginatedList[PullRequestComment]: 3081 """ 3082 :calls: `GET /repos/{owner}/{repo}/pulls/comments <https://docs.github.com/en/rest/reference/pulls#comments>`_ 3083 :param sort: string 3084 :param direction: string 3085 :param since: datetime 3086 :rtype: :class:`PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` 3087 """ 3088 return self.get_pulls_review_comments(sort, direction, since) 3089 3090 def get_pulls_review_comments( 3091 self, 3092 sort: Opt[str] = NotSet, 3093 direction: Opt[str] = NotSet, 3094 since: Opt[datetime] = NotSet, 3095 ) -> PaginatedList[PullRequestComment]: 3096 """ 3097 :calls: `GET /repos/{owner}/{repo}/pulls/comments <https://docs.github.com/en/rest/reference/pulls#review-comments>`_ 3098 :param sort: string 'created', 'updated', 'created_at' 3099 :param direction: string 'asc' or 'desc' 3100 :param since: datetime 3101 :rtype: :class:`PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` 3102 """ 3103 assert is_undefined(sort) or isinstance(sort, str), sort 3104 assert is_undefined(direction) or isinstance(direction, str), direction 3105 assert is_undefined(since) or isinstance(since, datetime), since 3106 url_parameters = dict() 3107 if is_defined(sort): 3108 url_parameters["sort"] = sort 3109 if is_defined(direction): 3110 url_parameters["direction"] = direction 3111 if is_defined(since): 3112 url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") 3113 return PaginatedList( 3114 github.PullRequestComment.PullRequestComment, 3115 self._requester, 3116 f"{self.url}/pulls/comments", 3117 url_parameters, 3118 ) 3119 3120 def get_readme(self, ref: Opt[str] = NotSet) -> ContentFile: 3121 """ 3122 :calls: `GET /repos/{owner}/{repo}/readme <https://docs.github.com/en/rest/reference/repos#contents>`_ 3123 :param ref: string 3124 :rtype: :class:`github.ContentFile.ContentFile` 3125 """ 3126 assert is_undefined(ref) or isinstance(ref, str), ref 3127 url_parameters = dict() 3128 if is_defined(ref): 3129 url_parameters["ref"] = ref 3130 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/readme", parameters=url_parameters) 3131 return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) 3132 3133 def get_self_hosted_runner(self, runner_id: int) -> SelfHostedActionsRunner: 3134 """ 3135 :calls: `GET /repos/{owner}/{repo}/actions/runners/{id} <https://docs.github.com/en/rest/reference/actions#get-a-self-hosted-runner-for-a-repository>`_ 3136 :param runner_id: int 3137 :rtype: :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` 3138 """ 3139 assert isinstance(runner_id, int), runner_id 3140 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/runners/{runner_id}") 3141 return github.SelfHostedActionsRunner.SelfHostedActionsRunner(self._requester, headers, data, completed=True) 3142 3143 def get_self_hosted_runners(self) -> PaginatedList[SelfHostedActionsRunner]: 3144 """ 3145 :calls: `GET /repos/{owner}/{repo}/actions/runners <https://docs.github.com/en/rest/reference/actions#list-self-hosted-runners-for-a-repository>`_ 3146 :rtype: :class:`PaginatedList` of :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` 3147 """ 3148 return PaginatedList( 3149 github.SelfHostedActionsRunner.SelfHostedActionsRunner, 3150 self._requester, 3151 f"{self.url}/actions/runners", 3152 None, 3153 list_item="runners", 3154 ) 3155 3156 def get_source_import(self) -> SourceImport | None: 3157 """ 3158 :calls: `GET /repos/{owner}/{repo}/import <https://docs.github.com/en/rest/reference/migrations#source-imports>`_ 3159 """ 3160 import_header = {"Accept": Consts.mediaTypeImportPreview} 3161 headers, data = self._requester.requestJsonAndCheck( 3162 "GET", 3163 f"{self.url}/import", 3164 headers=import_header, 3165 ) 3166 if not data: 3167 return None 3168 else: 3169 return github.SourceImport.SourceImport(self._requester, headers, data, completed=True) 3170 3171 def get_stargazers(self) -> PaginatedList[NamedUser]: 3172 """ 3173 :calls: `GET /repos/{owner}/{repo}/stargazers <https://docs.github.com/en/rest/reference/activity#starring>`_ 3174 :rtype: :class:`PaginatedList` of :class:`github.NamedUser.NamedUser` 3175 """ 3176 return PaginatedList(github.NamedUser.NamedUser, self._requester, f"{self.url}/stargazers", None) 3177 3178 def get_stargazers_with_dates(self) -> PaginatedList[Stargazer]: 3179 """ 3180 :calls: `GET /repos/{owner}/{repo}/stargazers <https://docs.github.com/en/rest/reference/activity#starring>`_ 3181 :rtype: :class:`PaginatedList` of :class:`github.Stargazer.Stargazer` 3182 """ 3183 return PaginatedList( 3184 github.Stargazer.Stargazer, 3185 self._requester, 3186 f"{self.url}/stargazers", 3187 None, 3188 headers={"Accept": Consts.mediaTypeStarringPreview}, 3189 ) 3190 3191 def get_stats_contributors(self) -> list[StatsContributor] | None: 3192 """ 3193 :calls: `GET /repos/{owner}/{repo}/stats/contributors <https://docs.github.com/en/rest/reference/repos#get-all-contributor-commit-activity>`_ 3194 :rtype: None or list of :class:`github.StatsContributor.StatsContributor` 3195 """ 3196 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/stats/contributors") 3197 if not data: 3198 return None 3199 else: 3200 return [ 3201 github.StatsContributor.StatsContributor(self._requester, headers, attributes, completed=True) 3202 for attributes in data 3203 ] 3204 3205 def get_stats_commit_activity(self) -> list[StatsCommitActivity] | None: 3206 """ 3207 :calls: `GET /repos/{owner}/{repo}/stats/commit_activity <https://docs.github.com/en/rest/reference/repos#get-the-last-year-of-commit-activity>`_ 3208 :rtype: None or list of :class:`github.StatsCommitActivity.StatsCommitActivity` 3209 """ 3210 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/stats/commit_activity") 3211 if not data: 3212 return None 3213 else: 3214 return [ 3215 github.StatsCommitActivity.StatsCommitActivity(self._requester, headers, attributes, completed=True) 3216 for attributes in data 3217 ] 3218 3219 def get_stats_code_frequency(self) -> list[StatsCodeFrequency] | None: 3220 """ 3221 :calls: `GET /repos/{owner}/{repo}/stats/code_frequency <https://docs.github.com/en/rest/reference/repos#get-the-weekly-commit-activity>`_ 3222 :rtype: None or list of :class:`github.StatsCodeFrequency.StatsCodeFrequency` 3223 """ 3224 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/stats/code_frequency") 3225 if not data: 3226 return None 3227 else: 3228 return [ 3229 github.StatsCodeFrequency.StatsCodeFrequency(self._requester, headers, attributes, completed=True) 3230 for attributes in data 3231 ] 3232 3233 def get_stats_participation(self) -> StatsParticipation | None: 3234 """ 3235 :calls: `GET /repos/{owner}/{repo}/stats/participation <https://docs.github.com/en/rest/reference/repos#get-the-weekly-commit-count>`_ 3236 :rtype: None or :class:`github.StatsParticipation.StatsParticipation` 3237 """ 3238 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/stats/participation") 3239 if not data: 3240 return None 3241 else: 3242 return github.StatsParticipation.StatsParticipation(self._requester, headers, data, completed=True) 3243 3244 def get_stats_punch_card(self) -> StatsPunchCard | None: 3245 """ 3246 :calls: `GET /repos/{owner}/{repo}/stats/punch_card <https://docs.github.com/en/rest/reference/repos#get-the-hourly-commit-count-for-each-day>`_ 3247 :rtype: None or :class:`github.StatsPunchCard.StatsPunchCard` 3248 """ 3249 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/stats/punch_card") 3250 if not data: 3251 return None 3252 else: 3253 return github.StatsPunchCard.StatsPunchCard(self._requester, headers, data, completed=True) 3254 3255 def get_subscribers(self) -> PaginatedList[NamedUser]: 3256 """ 3257 :calls: `GET /repos/{owner}/{repo}/subscribers <https://docs.github.com/en/rest/reference/activity#watching>`_ 3258 :rtype: :class:`PaginatedList` of :class:`github.NamedUser.NamedUser` 3259 """ 3260 return PaginatedList(github.NamedUser.NamedUser, self._requester, f"{self.url}/subscribers", None) 3261 3262 def get_tags(self) -> PaginatedList[Tag]: 3263 """ 3264 :calls: `GET /repos/{owner}/{repo}/tags <https://docs.github.com/en/rest/reference/repos>`_ 3265 :rtype: :class:`PaginatedList` of :class:`github.Tag.Tag` 3266 """ 3267 return PaginatedList(github.Tag.Tag, self._requester, f"{self.url}/tags", None) 3268 3269 def get_releases(self) -> PaginatedList[GitRelease]: 3270 """ 3271 :calls: `GET /repos/{owner}/{repo}/releases <https://docs.github.com/en/rest/reference/repos#list-releases>`_ 3272 :rtype: :class:`PaginatedList` of :class:`github.GitRelease.GitRelease` 3273 """ 3274 return PaginatedList(github.GitRelease.GitRelease, self._requester, f"{self.url}/releases", None) 3275 3276 def get_release(self, id: int | str) -> GitRelease: 3277 """ 3278 :calls: `GET /repos/{owner}/{repo}/releases/{id} <https://docs.github.com/en/rest/reference/repos#get-a-release>`_ 3279 :param id: int (release id), str (tag name) 3280 :rtype: None or :class:`github.GitRelease.GitRelease` 3281 """ 3282 if isinstance(id, int): 3283 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/releases/{id}") 3284 return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) 3285 elif isinstance(id, str): 3286 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/releases/tags/{id}") 3287 return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) 3288 3289 def get_latest_release(self) -> GitRelease: 3290 """ 3291 :calls: `GET /repos/{owner}/{repo}/releases/latest <https://docs.github.com/en/rest/reference/repos#get-the-latest-release>`_ 3292 :rtype: :class:`github.GitRelease.GitRelease` 3293 """ 3294 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/releases/latest") 3295 return github.GitRelease.GitRelease(self._requester, headers, data, completed=True) 3296 3297 def get_teams(self) -> PaginatedList[Team]: 3298 """ 3299 :calls: `GET /repos/{owner}/{repo}/teams <https://docs.github.com/en/rest/reference/repos>`_ 3300 :rtype: :class:`PaginatedList` of :class:`github.Team.Team` 3301 """ 3302 return PaginatedList(github.Team.Team, self._requester, f"{self.url}/teams", None) 3303 3304 def get_topics(self) -> list[str]: 3305 """ 3306 :calls: `GET /repos/{owner}/{repo}/topics <https://docs.github.com/en/rest/reference/repos#replace-all-repository-topics>`_ 3307 :rtype: list of strings 3308 """ 3309 headers, data = self._requester.requestJsonAndCheck( 3310 "GET", 3311 f"{self.url}/topics", 3312 headers={"Accept": Consts.mediaTypeTopicsPreview}, 3313 ) 3314 return data["names"] 3315 3316 def get_watchers(self) -> PaginatedList[NamedUser]: 3317 """ 3318 :calls: `GET /repos/{owner}/{repo}/watchers <https://docs.github.com/en/rest/reference/activity#starring>`_ 3319 :rtype: :class:`PaginatedList` of :class:`github.NamedUser.NamedUser` 3320 """ 3321 return PaginatedList(github.NamedUser.NamedUser, self._requester, f"{self.url}/watchers", None) 3322 3323 def get_workflows(self) -> PaginatedList[Workflow]: 3324 """ 3325 :calls: `GET /repos/{owner}/{repo}/actions/workflows <https://docs.github.com/en/rest/reference/actions#workflows>`_ 3326 :rtype: :class:`PaginatedList` of :class:`github.Workflow.Workflow` 3327 """ 3328 return PaginatedList( 3329 github.Workflow.Workflow, 3330 self._requester, 3331 f"{self.url}/actions/workflows", 3332 None, 3333 list_item="workflows", 3334 ) 3335 3336 def get_workflow(self, id_or_file_name: str | int) -> Workflow: 3337 """ 3338 :calls: `GET /repos/{owner}/{repo}/actions/workflows/{workflow_id} <https://docs.github.com/en/rest/reference/actions#workflows>`_ 3339 :param id_or_file_name: int or string. Can be either a workflow ID or a filename. 3340 3341 :rtype: :class:`github.Workflow.Workflow` 3342 """ 3343 assert isinstance(id_or_file_name, (int, str)), id_or_file_name 3344 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/workflows/{id_or_file_name}") 3345 return github.Workflow.Workflow(self._requester, headers, data, completed=True) 3346 3347 def get_workflow_runs( 3348 self, 3349 actor: Opt[NamedUser] = NotSet, 3350 branch: Opt[Branch] = NotSet, 3351 event: Opt[str] = NotSet, 3352 status: Opt[str] = NotSet, 3353 exclude_pull_requests: Opt[bool] = NotSet, 3354 head_sha: Opt[str] = NotSet, 3355 ) -> PaginatedList[WorkflowRun]: 3356 """ 3357 :calls: `GET /repos/{owner}/{repo}/actions/runs <https://docs.github.com/en/rest/reference/actions#list-workflow-runs-for-a-repository>`_ 3358 :param actor: :class:`github.NamedUser.NamedUser` or string 3359 :param branch: :class:`github.Branch.Branch` or string 3360 :param event: string 3361 :param status: string `queued`, `in_progress`, `completed`, `success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, or `action_required` 3362 :param exclude_pull_requests: bool 3363 :param head_sha: string 3364 3365 :rtype: :class:`PaginatedList` of :class:`github.WorkflowRun.WorkflowRun` 3366 """ 3367 assert is_optional(actor, (github.NamedUser.NamedUser, str)), actor 3368 assert is_optional(branch, (github.Branch.Branch, str)), branch 3369 assert is_optional(event, str), event 3370 assert is_optional(status, str), status 3371 assert is_optional(exclude_pull_requests, bool), exclude_pull_requests 3372 assert is_optional(head_sha, str), head_sha 3373 3374 url_parameters: dict[str, Any] = {} 3375 if is_defined(actor): 3376 if isinstance(actor, github.NamedUser.NamedUser): 3377 url_parameters["actor"] = actor._identity 3378 else: 3379 url_parameters["actor"] = actor 3380 if is_defined(branch): 3381 if isinstance(branch, github.Branch.Branch): 3382 url_parameters["branch"] = branch.name 3383 else: 3384 url_parameters["branch"] = branch 3385 if is_defined(event): 3386 url_parameters["event"] = event 3387 if is_defined(status): 3388 url_parameters["status"] = status 3389 if is_defined(exclude_pull_requests) and exclude_pull_requests: 3390 url_parameters["exclude_pull_requests"] = 1 3391 if is_defined(head_sha): 3392 url_parameters["head_sha"] = head_sha 3393 3394 return PaginatedList( 3395 github.WorkflowRun.WorkflowRun, 3396 self._requester, 3397 f"{self.url}/actions/runs", 3398 url_parameters, 3399 list_item="workflow_runs", 3400 ) 3401 3402 def get_workflow_run(self, id_: int) -> WorkflowRun: 3403 """ 3404 :calls: `GET /repos/{owner}/{repo}/actions/runs/{run_id} <https://docs.github.com/en/rest/reference/actions#workflow-runs>`_ 3405 :param id_: int 3406 3407 :rtype: :class:`github.WorkflowRun.WorkflowRun` 3408 """ 3409 assert isinstance(id_, int) 3410 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/runs/{id_}") 3411 return github.WorkflowRun.WorkflowRun(self._requester, headers, data, completed=True) 3412 3413 def has_in_assignees(self, assignee: str | NamedUser) -> bool: 3414 """ 3415 :calls: `GET /repos/{owner}/{repo}/assignees/{assignee} <https://docs.github.com/en/rest/reference/issues#assignees>`_ 3416 :param assignee: string or :class:`github.NamedUser.NamedUser` 3417 :rtype: bool 3418 """ 3419 assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, str), assignee 3420 3421 if isinstance(assignee, github.NamedUser.NamedUser): 3422 assignee = assignee._identity 3423 3424 status, headers, data = self._requester.requestJson("GET", f"{self.url}/assignees/{assignee}") 3425 return status == 204 3426 3427 def has_in_collaborators(self, collaborator: str | NamedUser) -> bool: 3428 """ 3429 :calls: `GET /repos/{owner}/{repo}/collaborators/{user} <https://docs.github.com/en/rest/reference/repos#collaborators>`_ 3430 :param collaborator: string or :class:`github.NamedUser.NamedUser` 3431 :rtype: bool 3432 """ 3433 assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, str), collaborator 3434 3435 if isinstance(collaborator, github.NamedUser.NamedUser): 3436 collaborator = collaborator._identity 3437 3438 status, headers, data = self._requester.requestJson("GET", f"{self.url}/collaborators/{collaborator}") 3439 return status == 204 3440 3441 def _legacy_convert_issue(self, attributes: dict[str, Any]) -> dict[str, Any]: 3442 convertedAttributes = { 3443 "number": attributes["number"], 3444 "url": f"/repos{urllib.parse.urlparse(attributes['html_url']).path}", 3445 "user": { 3446 "login": attributes["user"], 3447 "url": f"/users/{attributes['user']}", 3448 }, 3449 } 3450 if "labels" in attributes: # pragma no branch 3451 convertedAttributes["labels"] = [{"name": label} for label in attributes["labels"]] 3452 for attr in ("title", "created_at", "comments", "body", "updated_at", "state"): 3453 if attr in attributes: # pragma no branch 3454 convertedAttributes[attr] = attributes[attr] 3455 return convertedAttributes 3456 3457 def legacy_search_issues(self, state: str, keyword: str) -> list[Issue]: 3458 """ 3459 :calls: `GET /legacy/issues/search/{owner}/{repository}/{state}/{keyword} <https://docs.github.com/en/rest/reference/search>`_ 3460 :param state: "open" or "closed" 3461 :param keyword: string 3462 :rtype: List of :class:`github.Issue.Issue` 3463 """ 3464 assert state in ["open", "closed"], state 3465 assert isinstance(keyword, str), keyword 3466 headers, data = self._requester.requestJsonAndCheck( 3467 "GET", 3468 f"/legacy/issues/search/{self.owner.login}/{self.name}/{state}/{urllib.parse.quote(keyword)}", 3469 ) 3470 return [ 3471 github.Issue.Issue( 3472 self._requester, 3473 headers, 3474 self._legacy_convert_issue(element), 3475 completed=False, 3476 ) 3477 for element in data["issues"] 3478 ] 3479 3480 def get_notifications( 3481 self, 3482 all: Opt[bool] = NotSet, 3483 participating: Opt[bool] = NotSet, 3484 since: Opt[datetime] = NotSet, 3485 before: Opt[datetime] = NotSet, 3486 ) -> PaginatedList[Notification]: 3487 """ 3488 :calls: `GET /repos/{owner}/{repo}/notifications <https://docs.github.com/en/rest/reference/activity#notifications>`_ 3489 :param all: bool 3490 :param participating: bool 3491 :param since: datetime 3492 :param before: datetime 3493 :rtype: :class:`PaginatedList` of :class:`github.Notification.Notification` 3494 """ 3495 3496 assert is_optional(all, bool), all 3497 assert is_optional(participating, bool), participating 3498 assert is_optional(since, datetime), since 3499 assert is_optional(before, datetime), before 3500 3501 params = NotSet.remove_unset_items({"all": all, "participating": participating}) 3502 if is_defined(since): 3503 params["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") 3504 if is_defined(before): 3505 params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ") 3506 3507 return PaginatedList( 3508 github.Notification.Notification, 3509 self._requester, 3510 f"{self.url}/notifications", 3511 params, 3512 ) 3513 3514 def mark_notifications_as_read(self, last_read_at: datetime = datetime.now(timezone.utc)) -> None: 3515 """ 3516 :calls: `PUT /repos/{owner}/{repo}/notifications <https://docs.github.com/en/rest/reference/activity#notifications>`_ 3517 :param last_read_at: datetime 3518 """ 3519 assert isinstance(last_read_at, datetime) 3520 put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} 3521 3522 headers, data = self._requester.requestJsonAndCheck("PUT", f"{self.url}/notifications", input=put_parameters) 3523 3524 def merge(self, base: str, head: str, commit_message: Opt[str] = NotSet) -> Commit | None: 3525 """ 3526 :calls: `POST /repos/{owner}/{repo}/merges <https://docs.github.com/en/rest/reference/repos#merging>`_ 3527 :param base: string 3528 :param head: string 3529 :param commit_message: string 3530 :rtype: :class:`github.Commit.Commit` 3531 """ 3532 assert isinstance(base, str), base 3533 assert isinstance(head, str), head 3534 assert is_undefined(commit_message) or isinstance(commit_message, str), commit_message 3535 post_parameters = { 3536 "base": base, 3537 "head": head, 3538 } 3539 if is_defined(commit_message): 3540 post_parameters["commit_message"] = commit_message 3541 headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/merges", input=post_parameters) 3542 if data is None: 3543 return None 3544 else: 3545 return github.Commit.Commit(self._requester, headers, data, completed=True) 3546 3547 def replace_topics(self, topics: list[str]) -> None: 3548 """ 3549 :calls: `PUT /repos/{owner}/{repo}/topics <https://docs.github.com/en/rest/reference/repos>`_ 3550 :param topics: list of strings 3551 :rtype: None 3552 """ 3553 post_parameters = {"names": topics} 3554 headers, data = self._requester.requestJsonAndCheck( 3555 "PUT", 3556 f"{self.url}/topics", 3557 headers={"Accept": Consts.mediaTypeTopicsPreview}, 3558 input=post_parameters, 3559 ) 3560 3561 def get_vulnerability_alert(self) -> bool: 3562 """ 3563 :calls: `GET /repos/{owner}/{repo}/vulnerability-alerts <https://docs.github.com/en/rest/reference/repos>`_ 3564 :rtype: bool 3565 """ 3566 status, _, _ = self._requester.requestJson( 3567 "GET", 3568 f"{self.url}/vulnerability-alerts", 3569 headers={"Accept": Consts.vulnerabilityAlertsPreview}, 3570 ) 3571 return status == 204 3572 3573 def enable_vulnerability_alert(self) -> bool: 3574 """ 3575 :calls: `PUT /repos/{owner}/{repo}/vulnerability-alerts <https://docs.github.com/en/rest/reference/repos>`_ 3576 :rtype: bool 3577 """ 3578 status, _, _ = self._requester.requestJson( 3579 "PUT", 3580 f"{self.url}/vulnerability-alerts", 3581 headers={"Accept": Consts.vulnerabilityAlertsPreview}, 3582 ) 3583 return status == 204 3584 3585 def disable_vulnerability_alert(self) -> bool: 3586 """ 3587 :calls: `DELETE /repos/{owner}/{repo}/vulnerability-alerts <https://docs.github.com/en/rest/reference/repos>`_ 3588 :rtype: bool 3589 """ 3590 status, _, _ = self._requester.requestJson( 3591 "DELETE", 3592 f"{self.url}/vulnerability-alerts", 3593 headers={"Accept": Consts.vulnerabilityAlertsPreview}, 3594 ) 3595 return status == 204 3596 3597 def enable_automated_security_fixes(self) -> bool: 3598 """ 3599 :calls: `PUT /repos/{owner}/{repo}/automated-security-fixes <https://docs.github.com/en/rest/reference/repos>`_ 3600 :rtype: bool 3601 """ 3602 status, _, _ = self._requester.requestJson( 3603 "PUT", 3604 f"{self.url}/automated-security-fixes", 3605 headers={"Accept": Consts.automatedSecurityFixes}, 3606 ) 3607 return status == 204 3608 3609 def disable_automated_security_fixes(self) -> bool: 3610 """ 3611 :calls: `DELETE /repos/{owner}/{repo}/automated-security-fixes <https://docs.github.com/en/rest/reference/repos>`_ 3612 :rtype: bool 3613 """ 3614 status, _, _ = self._requester.requestJson( 3615 "DELETE", 3616 f"{self.url}/automated-security-fixes", 3617 headers={"Accept": Consts.automatedSecurityFixes}, 3618 ) 3619 return status == 204 3620 3621 def remove_from_collaborators(self, collaborator: str | NamedUser) -> None: 3622 """ 3623 :calls: `DELETE /repos/{owner}/{repo}/collaborators/{user} <https://docs.github.com/en/rest/reference/repos#collaborators>`_ 3624 :param collaborator: string or :class:`github.NamedUser.NamedUser` 3625 :rtype: None 3626 """ 3627 assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, str), collaborator 3628 3629 if isinstance(collaborator, github.NamedUser.NamedUser): 3630 collaborator = collaborator._identity 3631 3632 headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/collaborators/{collaborator}") 3633 3634 def remove_self_hosted_runner(self, runner: SelfHostedActionsRunner | int) -> bool: 3635 """ 3636 :calls: `DELETE /repos/{owner}/{repo}/actions/runners/{runner_id} <https://docs.github.com/en/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository>`_ 3637 :param runner: int or :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` 3638 :rtype: bool 3639 """ 3640 assert isinstance(runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner) or isinstance( 3641 runner, int 3642 ), runner 3643 3644 if isinstance(runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner): 3645 runner = runner.id 3646 3647 status, _, _ = self._requester.requestJson("DELETE", f"{self.url}/actions/runners/{runner}") 3648 return status == 204 3649 3650 def remove_autolink(self, autolink: Autolink | int) -> bool: 3651 """ 3652 :calls: `DELETE /repos/{owner}/{repo}/autolinks/{id} <https://docs.github.com/en/rest/reference/repos>`_ 3653 :param autolink: int or :class:`github.Autolink.Autolink` 3654 :rtype: None 3655 """ 3656 is_autolink = isinstance(autolink, github.Autolink.Autolink) 3657 assert is_autolink or isinstance(autolink, int), autolink 3658 3659 status, _, _ = self._requester.requestJson( 3660 "DELETE", f"{self.url}/autolinks/{autolink.id if is_autolink else autolink}" # type: ignore 3661 ) 3662 return status == 204 3663 3664 def subscribe_to_hub(self, event: str, callback: str, secret: Opt[str] = NotSet) -> None: 3665 """ 3666 :calls: `POST /hub <https://docs.github.com/en/rest/reference/repos#pubsubhubbub>`_ 3667 :param event: string 3668 :param callback: string 3669 :param secret: string 3670 :rtype: None 3671 """ 3672 return self._hub("subscribe", event, callback, secret) 3673 3674 def unsubscribe_from_hub(self, event: str, callback: str) -> None: 3675 """ 3676 :calls: `POST /hub <https://docs.github.com/en/rest/reference/repos#pubsubhubbub>`_ 3677 :param event: string 3678 :param callback: string 3679 :param secret: string 3680 :rtype: None 3681 """ 3682 return self._hub("unsubscribe", event, callback, NotSet) 3683 3684 def create_check_suite(self, head_sha: str) -> CheckSuite: 3685 """ 3686 :calls: `POST /repos/{owner}/{repo}/check-suites <https://docs.github.com/en/rest/reference/checks#create-a-check-suite>`_ 3687 :param head_sha: string 3688 :rtype: :class:`github.CheckSuite.CheckSuite` 3689 """ 3690 assert isinstance(head_sha, str), head_sha 3691 headers, data = self._requester.requestJsonAndCheck( 3692 "POST", 3693 f"{self.url}/check-suites", 3694 input={"head_sha": head_sha}, 3695 ) 3696 return github.CheckSuite.CheckSuite(self._requester, headers, data, completed=True) 3697 3698 def get_check_suite(self, check_suite_id: int) -> CheckSuite: 3699 """ 3700 :calls: `GET /repos/{owner}/{repo}/check-suites/{check_suite_id} <https://docs.github.com/en/rest/reference/checks#get-a-check-suite>`_ 3701 :param check_suite_id: int 3702 :rtype: :class:`github.CheckSuite.CheckSuite` 3703 """ 3704 assert isinstance(check_suite_id, int), check_suite_id 3705 requestHeaders = {"Accept": "application/vnd.github.v3+json"} 3706 headers, data = self._requester.requestJsonAndCheck( 3707 "GET", 3708 f"{self.url}/check-suites/{check_suite_id}", 3709 headers=requestHeaders, 3710 ) 3711 return github.CheckSuite.CheckSuite(self._requester, headers, data, completed=True) 3712 3713 def update_check_suites_preferences( 3714 self, auto_trigger_checks: list[dict[str, bool | int]] 3715 ) -> RepositoryPreferences: 3716 """ 3717 :calls: `PATCH /repos/{owner}/{repo}/check-suites/preferences <https://docs.github.com/en/rest/reference/checks#update-repository-preferences-for-check-suites>`_ 3718 :param auto_trigger_checks: list of dict 3719 :rtype: :class:`github.RepositoryPreferences.RepositoryPreferences` 3720 """ 3721 assert all(isinstance(element, dict) for element in auto_trigger_checks), auto_trigger_checks 3722 headers, data = self._requester.requestJsonAndCheck( 3723 "PATCH", 3724 f"{self.url}/check-suites/preferences", 3725 input={"auto_trigger_checks": auto_trigger_checks}, 3726 ) 3727 return github.RepositoryPreferences.RepositoryPreferences(self._requester, headers, data, completed=True) 3728 3729 def _hub(self, mode: str, event: str, callback: str, secret: Opt[str]) -> None: 3730 assert isinstance(mode, str), mode 3731 assert isinstance(event, str), event 3732 assert isinstance(callback, str), callback 3733 assert is_undefined(secret) or isinstance(secret, str), secret 3734 3735 post_parameters = collections.OrderedDict() 3736 post_parameters["hub.callback"] = callback 3737 post_parameters["hub.topic"] = f"https://github.com/{self.full_name}/events/{event}" 3738 post_parameters["hub.mode"] = mode 3739 if is_defined(secret): 3740 post_parameters["hub.secret"] = secret 3741 3742 headers, output = self._requester.requestMultipartAndCheck("POST", "/hub", input=post_parameters) 3743 3744 @property 3745 def _identity(self) -> str: 3746 return f"{self.owner.login}/{self.name}" 3747 3748 def get_release_asset(self, id: int) -> GitReleaseAsset: 3749 assert isinstance(id, (int)), id 3750 3751 resp_headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/releases/assets/{id}") 3752 return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True) 3753 3754 def create_check_run( 3755 self, 3756 name: str, 3757 head_sha: str, 3758 details_url: Opt[str] = NotSet, 3759 external_id: Opt[str] = NotSet, 3760 status: Opt[str] = NotSet, 3761 started_at: Opt[datetime] = NotSet, 3762 conclusion: Opt[str] = NotSet, 3763 completed_at: Opt[datetime] = NotSet, 3764 output: Opt[dict[str, str | list[dict[str, str | int]]]] = NotSet, 3765 actions: Opt[list[dict[str, str]]] = NotSet, 3766 ) -> CheckRun: 3767 """ 3768 :calls: `POST /repos/{owner}/{repo}/check-runs <https://docs.github.com/en/rest/reference/checks#create-a-check-run>`_ 3769 :param name: string 3770 :param head_sha: string 3771 :param details_url: string 3772 :param external_id: string 3773 :param status: string 3774 :param started_at: datetime 3775 :param conclusion: string 3776 :param completed_at: datetime 3777 :param output: dict 3778 :param actions: list of dict 3779 :rtype: :class:`github.CheckRun.CheckRun` 3780 """ 3781 assert isinstance(name, str), name 3782 assert isinstance(head_sha, str), head_sha 3783 assert is_optional(details_url, str), details_url 3784 assert is_optional(external_id, str), external_id 3785 assert is_optional(status, str), status 3786 assert is_optional(started_at, datetime), started_at 3787 assert is_optional(conclusion, str), conclusion 3788 assert is_optional(completed_at, datetime), completed_at 3789 assert is_optional(output, dict), output 3790 assert is_optional_list(actions, dict), actions 3791 3792 post_parameters = NotSet.remove_unset_items( 3793 { 3794 "name": name, 3795 "head_sha": head_sha, 3796 "details_url": details_url, 3797 "external_id": external_id, 3798 "status": status, 3799 "conclusion": conclusion, 3800 "output": output, 3801 "actions": actions, 3802 } 3803 ) 3804 3805 if is_defined(started_at): 3806 post_parameters["started_at"] = started_at.strftime("%Y-%m-%dT%H:%M:%SZ") 3807 if is_defined(completed_at): 3808 post_parameters["completed_at"] = completed_at.strftime("%Y-%m-%dT%H:%M:%SZ") 3809 3810 headers, data = self._requester.requestJsonAndCheck( 3811 "POST", 3812 f"{self.url}/check-runs", 3813 input=post_parameters, 3814 ) 3815 return github.CheckRun.CheckRun(self._requester, headers, data, completed=True) 3816 3817 def get_check_run(self, check_run_id: int) -> CheckRun: 3818 """ 3819 :calls: `GET /repos/{owner}/{repo}/check-runs/{check_run_id} <https://docs.github.com/en/rest/reference/checks#get-a-check-run>`_ 3820 :param check_run_id: int 3821 :rtype: :class:`github.CheckRun.CheckRun` 3822 """ 3823 assert isinstance(check_run_id, int), check_run_id 3824 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/check-runs/{check_run_id}") 3825 return github.CheckRun.CheckRun(self._requester, headers, data, completed=True) 3826 3827 def get_artifacts(self, name: Opt[str] = NotSet) -> PaginatedList[Artifact]: 3828 """ 3829 :calls: `GET /repos/{owner}/{repo}/actions/artifacts <https://docs.github.com/en/rest/actions/artifacts#list-artifacts-for-a-repository>`_ 3830 :param name: str 3831 :rtype: :class:`PaginatedList` of :class:`github.Artifact.Artifact` 3832 """ 3833 3834 assert is_undefined(name) or isinstance(name, str), name 3835 3836 param = {key: value for key, value in {"name": name}.items() if is_defined(value)} 3837 3838 return PaginatedList( 3839 github.Artifact.Artifact, 3840 self._requester, 3841 f"{self.url}/actions/artifacts", 3842 firstParams=param, 3843 list_item="artifacts", 3844 ) 3845 3846 def get_artifact(self, artifact_id: int) -> Artifact: 3847 """ 3848 :calls: `GET /repos/{owner}/{repo}/actions/artifacts/{artifact_id} <https://docs.github.com/en/rest/actions/artifacts#get-an-artifact>`_ 3849 :param artifact_id: int 3850 :rtype: :class:`github.Artifact.Artifact` 3851 """ 3852 assert isinstance(artifact_id, int), artifact_id 3853 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/artifacts/{artifact_id}") 3854 3855 return github.Artifact.Artifact(self._requester, headers, data, completed=True) 3856 3857 def get_codescan_alerts(self) -> PaginatedList[CodeScanAlert]: 3858 """ 3859 :calls: `GET https://api.github.com/repos/{owner}/{repo}/code-scanning/alerts <https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-alerts-for-a-repository>`_ 3860 :rtype: :class:`PaginatedList` of :class:`github.CodeScanAlert.CodeScanAlert` 3861 """ 3862 return PaginatedList( 3863 github.CodeScanAlert.CodeScanAlert, 3864 self._requester, 3865 f"{self.url}/code-scanning/alerts", 3866 None, 3867 ) 3868 3869 def get_environments(self) -> PaginatedList[Environment]: 3870 """ 3871 :calls: `GET /repos/{owner}/{repo}/environments <https://docs.github.com/en/rest/reference/deployments#get-all-environments>`_ 3872 :rtype: :class:`PaginatedList` of :class:`github.Environment.Environment` 3873 """ 3874 return PaginatedList( 3875 github.Environment.Environment, 3876 self._requester, 3877 f"{self.url}/environments", 3878 None, 3879 list_item="environments", 3880 ) 3881 3882 def get_environment(self, environment_name: str) -> Environment: 3883 """ 3884 :calls: `GET /repos/{owner}/{repo}/environments/{environment_name} <https://docs.github.com/en/rest/reference/deployments#get-an-environment>`_ 3885 :rtype: :class:`github.Environment.Environment` 3886 """ 3887 assert isinstance(environment_name, str), environment_name 3888 headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/environments/{environment_name}") 3889 return github.Environment.Environment(self._requester, headers, data, completed=True) 3890 3891 def create_environment( 3892 self, 3893 environment_name: str, 3894 wait_timer: int = 0, 3895 reviewers: list[ReviewerParams] = [], 3896 deployment_branch_policy: EnvironmentDeploymentBranchPolicyParams | None = None, 3897 ) -> Environment: 3898 """ 3899 :calls: `PUT /repos/{owner}/{repo}/environments/{environment_name} <https://docs.github.com/en/rest/reference/deployments#create-or-update-an-environment>`_ 3900 :param environment_name: string 3901 :param wait_timer: int 3902 :param reviews: List[:class:github.EnvironmentDeploymentBranchPolicy.EnvironmentDeploymentBranchPolicyParams] 3903 :param deployment_branch_policy: Optional[:class:github.EnvironmentDeploymentBranchPolicy.EnvironmentDeploymentBranchPolicyParams`] 3904 :rtype: :class:`github.Environment.Environment` 3905 """ 3906 assert isinstance(environment_name, str), environment_name 3907 assert isinstance(wait_timer, int) 3908 assert isinstance(reviewers, list) 3909 assert all( 3910 [isinstance(reviewer, github.EnvironmentProtectionRuleReviewer.ReviewerParams) for reviewer in reviewers] 3911 ) 3912 assert ( 3913 isinstance( 3914 deployment_branch_policy, 3915 github.EnvironmentDeploymentBranchPolicy.EnvironmentDeploymentBranchPolicyParams, 3916 ) 3917 or deployment_branch_policy is None 3918 ) 3919 3920 put_parameters = { 3921 "wait_timer": wait_timer, 3922 "reviewers": [reviewer._asdict() for reviewer in reviewers], 3923 "deployment_branch_policy": deployment_branch_policy._asdict() if deployment_branch_policy else None, 3924 } 3925 3926 headers, data = self._requester.requestJsonAndCheck( 3927 "PUT", f"{self.url}/environments/{environment_name}", input=put_parameters 3928 ) 3929 return github.Environment.Environment(self._requester, headers, data, completed=True) 3930 3931 update_environment = create_environment 3932 3933 def delete_environment(self, environment_name: str) -> None: 3934 """ 3935 :calls: `DELETE /repos/{owner}/{repo}/environments/{environment_name} <https://docs.github.com/en/rest/reference/deployments#delete-an-environment>`_ 3936 :param environment_name: string 3937 :rtype: None 3938 """ 3939 assert isinstance(environment_name, str), environment_name 3940 3941 headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/environments/{environment_name}") 3942 3943 def _initAttributes(self) -> None: 3944 self._allow_auto_merge: Attribute[bool] = NotSet 3945 self._allow_forking: Attribute[bool] = NotSet 3946 self._allow_merge_commit: Attribute[bool] = NotSet 3947 self._allow_rebase_merge: Attribute[bool] = NotSet 3948 self._allow_squash_merge: Attribute[bool] = NotSet 3949 self._allow_update_branch: Attribute[bool] = NotSet 3950 self._archived: Attribute[bool] = NotSet 3951 self._archive_url: Attribute[str] = NotSet 3952 self._assignees_url: Attribute[str] = NotSet 3953 self._blobs_url: Attribute[str] = NotSet 3954 self._branches_url: Attribute[str] = NotSet 3955 self._clone_url: Attribute[str] = NotSet 3956 self._collaborators_url: Attribute[str] = NotSet 3957 self._comments_url: Attribute[str] = NotSet 3958 self._commits_url: Attribute[str] = NotSet 3959 self._compare_url: Attribute[str] = NotSet 3960 self._contents_url: Attribute[str] = NotSet 3961 self._contributors_url: Attribute[str] = NotSet 3962 self._created_at: Attribute[datetime] = NotSet 3963 self._default_branch: Attribute[str] = NotSet 3964 self._delete_branch_on_merge: Attribute[bool] = NotSet 3965 self._deployments_url: Attribute[str] = NotSet 3966 self._description: Attribute[str] = NotSet 3967 self._downloads_url: Attribute[str] = NotSet 3968 self._events_url: Attribute[str] = NotSet 3969 self._fork: Attribute[bool] = NotSet 3970 self._forks: Attribute[int] = NotSet 3971 self._forks_count: Attribute[int] = NotSet 3972 self._forks_url: Attribute[str] = NotSet 3973 self._full_name: Attribute[str] = NotSet 3974 self._git_commits_url: Attribute[str] = NotSet 3975 self._git_refs_url: Attribute[str] = NotSet 3976 self._git_tags_url: Attribute[str] = NotSet 3977 self._git_url: Attribute[str] = NotSet 3978 self._has_downloads: Attribute[bool] = NotSet 3979 self._has_issues: Attribute[bool] = NotSet 3980 self._has_pages: Attribute[bool] = NotSet 3981 self._has_projects: Attribute[bool] = NotSet 3982 self._has_wiki: Attribute[bool] = NotSet 3983 self._homepage: Attribute[str] = NotSet 3984 self._hooks_url: Attribute[str] = NotSet 3985 self._html_url: Attribute[str] = NotSet 3986 self._id: Attribute[int] = NotSet 3987 self._is_template: Attribute[bool] = NotSet 3988 self._issue_comment_url: Attribute[str] = NotSet 3989 self._issue_events_url: Attribute[str] = NotSet 3990 self._issues_url: Attribute[str] = NotSet 3991 self._keys_url: Attribute[str] = NotSet 3992 self._labels_url: Attribute[str] = NotSet 3993 self._language: Attribute[str] = NotSet 3994 self._languages_url: Attribute[str] = NotSet 3995 self._license: Attribute[License] = NotSet 3996 self._master_branch: Attribute[str] = NotSet 3997 self._merge_commit_message: Attribute[str] = NotSet 3998 self._merge_commit_title: Attribute[str] = NotSet 3999 self._merges_url: Attribute[str] = NotSet 4000 self._milestones_url: Attribute[str] = NotSet 4001 self._mirror_url: Attribute[str] = NotSet 4002 self._name: Attribute[str] = NotSet 4003 self._network_count: Attribute[int] = NotSet 4004 self._notifications_url: Attribute[str] = NotSet 4005 self._open_issues: Attribute[int] = NotSet 4006 self._open_issues_count: Attribute[int] = NotSet 4007 self._organization: Attribute[Organization] = NotSet 4008 self._owner: Attribute[NamedUser] = NotSet 4009 self._parent: Attribute[Repository] = NotSet 4010 self._permissions: Attribute[Permissions] = NotSet 4011 self._private: Attribute[bool] = NotSet 4012 self._pulls_url: Attribute[str] = NotSet 4013 self._pushed_at: Attribute[datetime] = NotSet 4014 self._releases_url: Attribute[str] = NotSet 4015 self._size: Attribute[int] = NotSet 4016 self._source: Attribute[Repository] = NotSet 4017 self._squash_merge_commit_message: Attribute[str] = NotSet 4018 self._squash_merge_commit_title: Attribute[str] = NotSet 4019 self._ssh_url: Attribute[str] = NotSet 4020 self._stargazers_count: Attribute[int] = NotSet 4021 self._stargazers_url: Attribute[str] = NotSet 4022 self._statuses_url: Attribute[str] = NotSet 4023 self._subscribers_url: Attribute[str] = NotSet 4024 self._subscribers_count: Attribute[int] = NotSet 4025 self._subscription_url: Attribute[str] = NotSet 4026 self._svn_url: Attribute[str] = NotSet 4027 self._tags_url: Attribute[str] = NotSet 4028 self._teams_url: Attribute[str] = NotSet 4029 self._topics: Attribute[list[str]] = NotSet 4030 self._trees_url: Attribute[str] = NotSet 4031 self._updated_at: Attribute[datetime] = NotSet 4032 self._url: Attribute[str] = NotSet 4033 self._use_squash_pr_title_as_default: Attribute[bool] = NotSet 4034 self._visibility: Attribute[str] = NotSet 4035 self._watchers: Attribute[int] = NotSet 4036 self._watchers_count: Attribute[int] = NotSet 4037 self._web_commit_signoff_required: Attribute[bool] = NotSet 4038 4039 def _useAttributes(self, attributes: dict[str, Any]) -> None: 4040 if "allow_auto_merge" in attributes: # pragma no branch 4041 self._allow_auto_merge = self._makeBoolAttribute(attributes["allow_auto_merge"]) 4042 if "allow_forking" in attributes: # pragma no branch 4043 self._allow_forking = self._makeBoolAttribute(attributes["allow_forking"]) 4044 if "allow_merge_commit" in attributes: # pragma no branch 4045 self._allow_merge_commit = self._makeBoolAttribute(attributes["allow_merge_commit"]) 4046 if "allow_rebase_merge" in attributes: # pragma no branch 4047 self._allow_rebase_merge = self._makeBoolAttribute(attributes["allow_rebase_merge"]) 4048 if "allow_squash_merge" in attributes: # pragma no branch 4049 self._allow_squash_merge = self._makeBoolAttribute(attributes["allow_squash_merge"]) 4050 if "allow_update_branch" in attributes: # pragma no branch 4051 self._allow_update_branch = self._makeBoolAttribute(attributes["allow_update_branch"]) 4052 if "archived" in attributes: # pragma no branch 4053 self._archived = self._makeBoolAttribute(attributes["archived"]) 4054 if "archive_url" in attributes: # pragma no branch 4055 self._archive_url = self._makeStringAttribute(attributes["archive_url"]) 4056 if "assignees_url" in attributes: # pragma no branch 4057 self._assignees_url = self._makeStringAttribute(attributes["assignees_url"]) 4058 if "blobs_url" in attributes: # pragma no branch 4059 self._blobs_url = self._makeStringAttribute(attributes["blobs_url"]) 4060 if "branches_url" in attributes: # pragma no branch 4061 self._branches_url = self._makeStringAttribute(attributes["branches_url"]) 4062 if "clone_url" in attributes: # pragma no branch 4063 self._clone_url = self._makeStringAttribute(attributes["clone_url"]) 4064 if "collaborators_url" in attributes: # pragma no branch 4065 self._collaborators_url = self._makeStringAttribute(attributes["collaborators_url"]) 4066 if "comments_url" in attributes: # pragma no branch 4067 self._comments_url = self._makeStringAttribute(attributes["comments_url"]) 4068 if "commits_url" in attributes: # pragma no branch 4069 self._commits_url = self._makeStringAttribute(attributes["commits_url"]) 4070 if "compare_url" in attributes: # pragma no branch 4071 self._compare_url = self._makeStringAttribute(attributes["compare_url"]) 4072 if "contents_url" in attributes: # pragma no branch 4073 self._contents_url = self._makeStringAttribute(attributes["contents_url"]) 4074 if "contributors_url" in attributes: # pragma no branch 4075 self._contributors_url = self._makeStringAttribute(attributes["contributors_url"]) 4076 if "created_at" in attributes: # pragma no branch 4077 self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) 4078 if "default_branch" in attributes: # pragma no branch 4079 self._default_branch = self._makeStringAttribute(attributes["default_branch"]) 4080 if "delete_branch_on_merge" in attributes: # pragma no branch 4081 self._delete_branch_on_merge = self._makeBoolAttribute(attributes["delete_branch_on_merge"]) 4082 if "deployments_url" in attributes: # pragma no branch 4083 self._deployments_url = self._makeStringAttribute(attributes["deployments_url"]) 4084 if "description" in attributes: # pragma no branch 4085 self._description = self._makeStringAttribute(attributes["description"]) 4086 if "downloads_url" in attributes: # pragma no branch 4087 self._downloads_url = self._makeStringAttribute(attributes["downloads_url"]) 4088 if "events_url" in attributes: # pragma no branch 4089 self._events_url = self._makeStringAttribute(attributes["events_url"]) 4090 if "fork" in attributes: # pragma no branch 4091 self._fork = self._makeBoolAttribute(attributes["fork"]) 4092 if "forks" in attributes: # pragma no branch 4093 self._forks = self._makeIntAttribute(attributes["forks"]) 4094 if "forks_count" in attributes: # pragma no branch 4095 self._forks_count = self._makeIntAttribute(attributes["forks_count"]) 4096 if "forks_url" in attributes: # pragma no branch 4097 self._forks_url = self._makeStringAttribute(attributes["forks_url"]) 4098 if "full_name" in attributes: # pragma no branch 4099 self._full_name = self._makeStringAttribute(attributes["full_name"]) 4100 if "git_commits_url" in attributes: # pragma no branch 4101 self._git_commits_url = self._makeStringAttribute(attributes["git_commits_url"]) 4102 if "git_refs_url" in attributes: # pragma no branch 4103 self._git_refs_url = self._makeStringAttribute(attributes["git_refs_url"]) 4104 if "git_tags_url" in attributes: # pragma no branch 4105 self._git_tags_url = self._makeStringAttribute(attributes["git_tags_url"]) 4106 if "git_url" in attributes: # pragma no branch 4107 self._git_url = self._makeStringAttribute(attributes["git_url"]) 4108 if "has_downloads" in attributes: # pragma no branch 4109 self._has_downloads = self._makeBoolAttribute(attributes["has_downloads"]) 4110 if "has_issues" in attributes: # pragma no branch 4111 self._has_issues = self._makeBoolAttribute(attributes["has_issues"]) 4112 if "has_pages" in attributes: # pragma no branch 4113 self._has_pages = self._makeBoolAttribute(attributes["has_pages"]) 4114 if "has_projects" in attributes: # pragma no branch 4115 self._has_projects = self._makeBoolAttribute(attributes["has_projects"]) 4116 if "has_wiki" in attributes: # pragma no branch 4117 self._has_wiki = self._makeBoolAttribute(attributes["has_wiki"]) 4118 if "homepage" in attributes: # pragma no branch 4119 self._homepage = self._makeStringAttribute(attributes["homepage"]) 4120 if "hooks_url" in attributes: # pragma no branch 4121 self._hooks_url = self._makeStringAttribute(attributes["hooks_url"]) 4122 if "html_url" in attributes: # pragma no branch 4123 self._html_url = self._makeStringAttribute(attributes["html_url"]) 4124 if "id" in attributes: # pragma no branch 4125 self._id = self._makeIntAttribute(attributes["id"]) 4126 if "is_template" in attributes: # pragma no branch 4127 self._is_template = self._makeBoolAttribute(attributes["is_template"]) 4128 if "issue_comment_url" in attributes: # pragma no branch 4129 self._issue_comment_url = self._makeStringAttribute(attributes["issue_comment_url"]) 4130 if "issue_events_url" in attributes: # pragma no branch 4131 self._issue_events_url = self._makeStringAttribute(attributes["issue_events_url"]) 4132 if "issues_url" in attributes: # pragma no branch 4133 self._issues_url = self._makeStringAttribute(attributes["issues_url"]) 4134 if "keys_url" in attributes: # pragma no branch 4135 self._keys_url = self._makeStringAttribute(attributes["keys_url"]) 4136 if "labels_url" in attributes: # pragma no branch 4137 self._labels_url = self._makeStringAttribute(attributes["labels_url"]) 4138 if "language" in attributes: # pragma no branch 4139 self._language = self._makeStringAttribute(attributes["language"]) 4140 if "languages_url" in attributes: # pragma no branch 4141 self._languages_url = self._makeStringAttribute(attributes["languages_url"]) 4142 if "license" in attributes: # pragma no branch 4143 self._license = self._makeClassAttribute(github.License.License, attributes["license"]) 4144 if "master_branch" in attributes: # pragma no branch 4145 self._master_branch = self._makeStringAttribute(attributes["master_branch"]) 4146 if "merges_url" in attributes: # pragma no branch 4147 self._merges_url = self._makeStringAttribute(attributes["merges_url"]) 4148 if "merge_commit_message" in attributes: # pragma no branch 4149 self._merge_commit_message = self._makeStringAttribute(attributes["merge_commit_message"]) 4150 if "merge_commit_title" in attributes: # pragma no branch 4151 self._merge_commit_title = self._makeStringAttribute(attributes["merge_commit_title"]) 4152 if "milestones_url" in attributes: # pragma no branch 4153 self._milestones_url = self._makeStringAttribute(attributes["milestones_url"]) 4154 if "mirror_url" in attributes: # pragma no branch 4155 self._mirror_url = self._makeStringAttribute(attributes["mirror_url"]) 4156 if "name" in attributes: # pragma no branch 4157 self._name = self._makeStringAttribute(attributes["name"]) 4158 if "network_count" in attributes: # pragma no branch 4159 self._network_count = self._makeIntAttribute(attributes["network_count"]) 4160 if "notifications_url" in attributes: # pragma no branch 4161 self._notifications_url = self._makeStringAttribute(attributes["notifications_url"]) 4162 if "open_issues" in attributes: # pragma no branch 4163 self._open_issues = self._makeIntAttribute(attributes["open_issues"]) 4164 if "open_issues_count" in attributes: # pragma no branch 4165 self._open_issues_count = self._makeIntAttribute(attributes["open_issues_count"]) 4166 if "organization" in attributes: # pragma no branch 4167 self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"]) 4168 if "owner" in attributes: # pragma no branch 4169 self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"]) 4170 if "parent" in attributes: # pragma no branch 4171 self._parent = self._makeClassAttribute(Repository, attributes["parent"]) 4172 if "permissions" in attributes: # pragma no branch 4173 self._permissions = self._makeClassAttribute(github.Permissions.Permissions, attributes["permissions"]) 4174 if "private" in attributes: # pragma no branch 4175 self._private = self._makeBoolAttribute(attributes["private"]) 4176 if "pulls_url" in attributes: # pragma no branch 4177 self._pulls_url = self._makeStringAttribute(attributes["pulls_url"]) 4178 if "pushed_at" in attributes: # pragma no branch 4179 self._pushed_at = self._makeDatetimeAttribute(attributes["pushed_at"]) 4180 if "releases_url" in attributes: # pragma no branch 4181 self._releases_url = self._makeStringAttribute(attributes["releases_url"]) 4182 if "size" in attributes: # pragma no branch 4183 self._size = self._makeIntAttribute(attributes["size"]) 4184 if "source" in attributes: # pragma no branch 4185 self._source = self._makeClassAttribute(Repository, attributes["source"]) 4186 if "squash_merge_commit_message" in attributes: # pragma no branch 4187 self._squash_merge_commit_message = self._makeStringAttribute(attributes["squash_merge_commit_message"]) 4188 if "squash_merge_commit_title" in attributes: # pragma no branch 4189 self._squash_merge_commit_title = self._makeStringAttribute(attributes["squash_merge_commit_title"]) 4190 if "ssh_url" in attributes: # pragma no branch 4191 self._ssh_url = self._makeStringAttribute(attributes["ssh_url"]) 4192 if "stargazers_count" in attributes: # pragma no branch 4193 self._stargazers_count = self._makeIntAttribute(attributes["stargazers_count"]) 4194 if "stargazers_url" in attributes: # pragma no branch 4195 self._stargazers_url = self._makeStringAttribute(attributes["stargazers_url"]) 4196 if "statuses_url" in attributes: # pragma no branch 4197 self._statuses_url = self._makeStringAttribute(attributes["statuses_url"]) 4198 if "subscribers_url" in attributes: # pragma no branch 4199 self._subscribers_url = self._makeStringAttribute(attributes["subscribers_url"]) 4200 if "subscribers_count" in attributes: # pragma no branch 4201 self._subscribers_count = self._makeIntAttribute(attributes["subscribers_count"]) 4202 if "subscription_url" in attributes: # pragma no branch 4203 self._subscription_url = self._makeStringAttribute(attributes["subscription_url"]) 4204 if "svn_url" in attributes: # pragma no branch 4205 self._svn_url = self._makeStringAttribute(attributes["svn_url"]) 4206 if "tags_url" in attributes: # pragma no branch 4207 self._tags_url = self._makeStringAttribute(attributes["tags_url"]) 4208 if "teams_url" in attributes: # pragma no branch 4209 self._teams_url = self._makeStringAttribute(attributes["teams_url"]) 4210 if "trees_url" in attributes: # pragma no branch 4211 self._trees_url = self._makeStringAttribute(attributes["trees_url"]) 4212 if "topics" in attributes: # pragma no branch 4213 self._topics = self._makeListOfStringsAttribute(attributes["topics"]) 4214 if "updated_at" in attributes: # pragma no branch 4215 self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) 4216 if "url" in attributes: # pragma no branch 4217 self._url = self._makeStringAttribute(attributes["url"]) 4218 if "use_squash_pr_title_as_default" in attributes: # pragma no branch 4219 self._use_squash_pr_title_as_default = self._makeBoolAttribute(attributes["use_squash_pr_title_as_default"]) 4220 if "visibility" in attributes: # pragma no branch 4221 self._visibility = self._makeStringAttribute(attributes["visibility"]) 4222 if "watchers" in attributes: # pragma no branch 4223 self._watchers = self._makeIntAttribute(attributes["watchers"]) 4224 if "watchers_count" in attributes: # pragma no branch 4225 self._watchers_count = self._makeIntAttribute(attributes["watchers_count"]) 4226 if "web_commit_signoff_required" in attributes: # pragma no branch 4227 self._web_commit_signoff_required = self._makeBoolAttribute(attributes["web_commit_signoff_required"])