Skip to content

Commit

Permalink
- Add doc string to all classes and methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpojer committed Jun 26, 2024
1 parent ed15b1f commit e2876d3
Show file tree
Hide file tree
Showing 13 changed files with 575 additions and 27 deletions.
39 changes: 39 additions & 0 deletions src/github_integration/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@


def singleton(cls):
"""
A decorator for making a class a singleton.
:param cls: The class to make a singleton.
:return: The singleton instance of the class.
"""

instances = {}

def get_instance(*args, **kwargs):
Expand All @@ -18,23 +25,55 @@ def get_instance(*args, **kwargs):
# TODO - review existing method and decide their integration here
@singleton
class GithubManager:
"""
A singleton class used to manage GitHub interactions.
"""

def __init__(self):
"""
Constructs all the necessary attributes for the GithubManager object.
"""
self.repository = None
self.git_release = None

def set_repository(self, repository: Repository):
"""
Sets the repository attribute.
:param repository: The Repository object to set.
"""
self.repository = repository

def set_git_release(self, release: GitRelease):
"""
Sets the git_release attribute.
:param release: The GitRelease object to set.
"""
self.git_release = release

def get_repository(self) -> Optional[Repository]:
"""
Gets the repository attribute.
:return: The Repository object, or None if it is not set.
"""
return self.repository

def get_git_release(self) -> Optional[GitRelease]:
"""
Gets the git_release attribute.
:return: The GitRelease object, or None if it is not set.
"""
return self.git_release

def get_repository_full_name(self) -> Optional[str]:
"""
Gets the full name of the repository.
:return: The full name of the repository as a string, or None if the repository is not set.
"""
if self.repository is not None:
return self.repository.full_name
return None
24 changes: 24 additions & 0 deletions src/github_integration/model/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,41 @@


class Commit:
"""
A class used to represent a commit in GitHub.
"""

def __init__(self, commit: GitCommit):
"""
Constructs all the necessary attributes for the Commit object.
:param commit: The GitCommit object.
"""
self.__commit: GitCommit = commit

@property
def sha(self) -> str:
"""
Gets the SHA of the commit.
:return: The SHA of the commit as a string.
"""
return self.__commit.sha

@property
def message(self) -> str:
"""
Gets the message of the commit.
:return: The message of the commit as a string.
"""
return self.__commit.commit.message

@property
def author(self) -> str:
"""
Gets the author of the commit.
:return: The author of the commit as a string.
"""
return self.__commit.author.login
65 changes: 65 additions & 0 deletions src/github_integration/model/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,122 @@


class Issue:
"""
A class used to represent an issue in GitHub.
"""

ISSUE_STATE_CLOSED = "closed"

def __init__(self, issue: GitIssue):
"""
Constructs all the necessary attributes for the Issue object.
:param issue: The GitIssue object.
"""
self.__issue: GitIssue = issue
self.__labels: Optional[list[str]] = None

@property
def id(self) -> int:
"""
Gets the ID of the issue.
:return: The ID of the issue as an integer.
"""
return self.__issue.id

@property
def number(self) -> int:
"""
Gets the number of the issue.
:return: The number of the issue as an integer.
"""
return self.__issue.number

@property
def title(self) -> str:
"""
Gets the title of the issue.
:return: The title of the issue as a string.
"""
return self.__issue.title

@property
def body(self) -> str:
"""
Gets the body of the issue.
:return: The body of the issue as a string, or an empty string if there is no body.
"""
return self.__issue.body if self.__issue.body else ""

@property
def state(self) -> str:
"""
Gets the state of the issue.
:return: The state of the issue as a string.
"""
return self.__issue.state

@property
def labels(self) -> list[str]:
"""
Gets the labels of the issue.
:return: The labels of the issue as a list of strings.
"""
if self.__labels is None:
self.__labels = [label.name for label in self.__issue.get_labels()]

return self.__labels

@property
def created_at(self) -> datetime:
"""
Gets the creation date of the issue.
:return: The creation date of the issue as a datetime object.
"""
return self.__issue.created_at

@property
def authors(self) -> list[str]:
"""
Gets the authors of the issue.
:return: The authors of the issue as a list of strings.
"""
# TODO
return []

@property
def contributors(self) -> list[str]:
"""
Gets the contributors of the issue.
:return: The contributors of the issue as a list of strings.
"""
# TODO
return []

def is_closed(self) -> bool:
"""
Checks if the issue is closed.
:return: True if the issue is closed, False otherwise.
"""
return self.state == "closed"

def contains_labels(self, labels: list[str]) -> bool:
"""
Checks if the issue contains any of the specified labels.
:param labels: The labels to check for.
:return: True if the issue contains any of the specified labels, False otherwise.
"""
for label in labels:
if label in self.labels:
return True
Expand Down
Loading

0 comments on commit e2876d3

Please sign in to comment.