Merge Milestone type stub back to source (#2682)

This commit is contained in:
Trim21
2023-08-31 11:06:32 +02:00
committed by GitHub
parent b3837cc70c
commit 3d63e222dc
2 changed files with 55 additions and 149 deletions
+55 -100
View File
@@ -27,193 +27,148 @@
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
from __future__ import annotations
from datetime import date
from typing import Any, Dict
from datetime import date, datetime
from typing import Any
import github.GithubObject
import github.Label
import github.NamedUser
import github.PaginatedList
from github.GithubObject import Attribute, CompletableGithubObject, NotSet, Opt, is_defined
from github.PaginatedList import PaginatedList
class Milestone(github.GithubObject.CompletableGithubObject):
class Milestone(CompletableGithubObject):
"""
This class represents Milestones. The reference can be found here https://docs.github.com/en/rest/reference/issues#milestones
"""
def __repr__(self):
def _initAttributes(self) -> None:
self._closed_issues: Attribute[int] = NotSet
self._created_at: Attribute[datetime] = NotSet
self._creator: Attribute[github.NamedUser.NamedUser] = NotSet
self._description: Attribute[str] = NotSet
self._due_on: Attribute[datetime] = NotSet
self._id: Attribute[int] = NotSet
self._labels_url: Attribute[str] = NotSet
self._number: Attribute[int] = NotSet
self._open_issues: Attribute[int] = NotSet
self._state: Attribute[str] = NotSet
self._title: Attribute[str] = NotSet
self._updated_at: Attribute[datetime] = NotSet
self._url: Attribute[str] = NotSet
def __repr__(self) -> str:
return self.get__repr__({"number": self._number.value, "title": self._title.value})
@property
def closed_issues(self):
"""
:type: integer
"""
def closed_issues(self) -> int:
self._completeIfNotSet(self._closed_issues)
return self._closed_issues.value
@property
def created_at(self):
"""
:type: datetime
"""
def created_at(self) -> datetime:
self._completeIfNotSet(self._created_at)
return self._created_at.value
@property
def creator(self):
"""
:type: :class:`github.NamedUser.NamedUser`
"""
def creator(self) -> github.NamedUser.NamedUser:
self._completeIfNotSet(self._creator)
return self._creator.value
@property
def description(self):
"""
:type: string
"""
def description(self) -> str:
self._completeIfNotSet(self._description)
return self._description.value
@property
def due_on(self):
"""
:type: datetime
"""
def due_on(self) -> datetime | None:
self._completeIfNotSet(self._due_on)
return self._due_on.value
@property
def id(self):
"""
:type: integer
"""
def id(self) -> int:
self._completeIfNotSet(self._id)
return self._id.value
@property
def labels_url(self):
"""
:type: string
"""
def labels_url(self) -> str:
self._completeIfNotSet(self._labels_url)
return self._labels_url.value
@property
def number(self):
"""
:type: integer
"""
def number(self) -> int:
self._completeIfNotSet(self._number)
return self._number.value
@property
def open_issues(self):
"""
:type: integer
"""
def open_issues(self) -> int:
self._completeIfNotSet(self._open_issues)
return self._open_issues.value
@property
def state(self):
"""
:type: string
"""
def state(self) -> str:
self._completeIfNotSet(self._state)
return self._state.value
@property
def title(self):
"""
:type: string
"""
def title(self) -> str:
self._completeIfNotSet(self._title)
return self._title.value
@property
def updated_at(self):
"""
:type: datetime
"""
def updated_at(self) -> datetime:
self._completeIfNotSet(self._updated_at)
return self._updated_at.value
@property
def url(self):
"""
:type: string
"""
def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value
def delete(self):
def delete(self) -> None:
"""
:calls: `DELETE /repos/{owner}/{repo}/milestones/{number} <https://docs.github.com/en/rest/reference/issues#milestones>`_
:rtype: None
"""
headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
def edit(
self,
title,
state=github.GithubObject.NotSet,
description=github.GithubObject.NotSet,
due_on=github.GithubObject.NotSet,
):
self, title: str, state: Opt[str] = NotSet, description: Opt[str] = NotSet, due_on: Opt[date] = NotSet
) -> None:
"""
:calls: `PATCH /repos/{owner}/{repo}/milestones/{number} <https://docs.github.com/en/rest/reference/issues#milestones>`_
:param title: string
:param state: string
:param description: string
:param due_on: date
:rtype: None
"""
assert isinstance(title, str), title
assert state is github.GithubObject.NotSet or isinstance(state, str), state
assert description is github.GithubObject.NotSet or isinstance(description, str), description
assert due_on is github.GithubObject.NotSet or isinstance(due_on, date), due_on
post_parameters = {
"title": title,
}
if state is not github.GithubObject.NotSet:
post_parameters["state"] = state
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if due_on is not github.GithubObject.NotSet:
assert state is NotSet or isinstance(state, str), state
assert description is NotSet or isinstance(description, str), description
assert due_on is NotSet or isinstance(due_on, date), due_on
post_parameters = NotSet.remove_unset_items(
{
"title": title,
"state": state,
"description": description,
}
)
if is_defined(due_on):
post_parameters["due_on"] = due_on.strftime("%Y-%m-%d")
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_labels(self):
def get_labels(self) -> PaginatedList[github.Label.Label]:
"""
:calls: `GET /repos/{owner}/{repo}/milestones/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label`
"""
return github.PaginatedList.PaginatedList(github.Label.Label, self._requester, f"{self.url}/labels", None)
return PaginatedList(github.Label.Label, self._requester, f"{self.url}/labels", None)
@property
def _identity(self):
def _identity(self) -> int:
return self.number
def _initAttributes(self) -> None:
self._closed_issues = github.GithubObject.NotSet
self._created_at = github.GithubObject.NotSet
self._creator = github.GithubObject.NotSet
self._description = github.GithubObject.NotSet
self._due_on = github.GithubObject.NotSet
self._id = github.GithubObject.NotSet
self._labels_url = github.GithubObject.NotSet
self._number = github.GithubObject.NotSet
self._open_issues = github.GithubObject.NotSet
self._state = github.GithubObject.NotSet
self._title = github.GithubObject.NotSet
self._updated_at = github.GithubObject.NotSet
self._url = github.GithubObject.NotSet
def _useAttributes(self, attributes: Dict[str, Any]) -> None:
def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "closed_issues" in attributes: # pragma no branch
self._closed_issues = self._makeIntAttribute(attributes["closed_issues"])
if "created_at" in attributes: # pragma no branch
-49
View File
@@ -1,49 +0,0 @@
from datetime import date, datetime
from typing import Any, Dict, Optional, Union
from github.GithubObject import CompletableGithubObject, _NotSetType
from github.Label import Label
from github.NamedUser import NamedUser
from github.PaginatedList import PaginatedList
class Milestone(CompletableGithubObject):
def __repr__(self) -> str: ...
@property
def _identity(self) -> int: ...
def _initAttributes(self) -> None: ...
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
@property
def closed_issues(self) -> int: ...
@property
def created_at(self) -> datetime: ...
@property
def creator(self) -> NamedUser: ...
def delete(self) -> None: ...
@property
def description(self) -> str: ...
@property
def due_on(self) -> Optional[datetime]: ...
def edit(
self,
title: str,
state: Union[_NotSetType, str] = ...,
description: Union[_NotSetType, str] = ...,
due_on: Union[date, _NotSetType] = ...,
) -> None: ...
def get_labels(self) -> PaginatedList[Label]: ...
@property
def id(self) -> int: ...
@property
def labels_url(self) -> str: ...
@property
def number(self) -> int: ...
@property
def open_issues(self) -> int: ...
@property
def state(self) -> str: ...
@property
def title(self) -> str: ...
@property
def updated_at(self) -> datetime: ...
@property
def url(self) -> str: ...