Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AAriam committed Aug 22, 2024
1 parent 9e24b35 commit 59e0296
Show file tree
Hide file tree
Showing 33 changed files with 298 additions and 296 deletions.
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ namespaces = true


# ----------------------------------------- Project Metadata -------------------------------------
#
[project]
version = "0.0.0.dev6"
version = "0.0.0.dev7"
name = "GitHub-Contexts"
requires-python = ">=3.9"

requires-python = ">=3.10"
7 changes: 6 additions & 1 deletion src/github_contexts/github/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from github_contexts.github.context import GitHubContext
from github_contexts.github import enums, payloads
from github_contexts.github import enum, payload


def create(context: dict) -> GitHubContext:
"""Create a GitHub context object from the given dictionary."""
return GitHubContext(context)
19 changes: 9 additions & 10 deletions src/github_contexts/github/context.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from ruamel.yaml import YAML

from github_contexts.github.enums import RefType, SecretSource

from github_contexts.github.payloads.base import Payload
from github_contexts.github.payloads.issue_comment import IssueCommentPayload
from github_contexts.github.payloads.issues import IssuesPayload
from github_contexts.github.payloads.pull_request import PullRequestPayload
from github_contexts.github.payloads.push import PushPayload
from github_contexts.github.payloads.schedule import SchedulePayload
from github_contexts.github.payloads.workflow_dispatch import WorkflowDispatchPayload
from github_contexts.github.enums import EventType, ActionType
from github_contexts.github.enum import RefType, SecretSource, EventType, ActionType

from github_contexts.github.payload.base import Payload
from github_contexts.github.payload.issue_comment import IssueCommentPayload
from github_contexts.github.payload.issues import IssuesPayload
from github_contexts.github.payload.pull_request import PullRequestPayload
from github_contexts.github.payload.push import PushPayload
from github_contexts.github.payload.schedule import SchedulePayload
from github_contexts.github.payload.workflow_dispatch import WorkflowDispatchPayload


class GitHubContext:
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions src/github_contexts/github/payload/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from github_contexts.github.payload import object
from github_contexts.github.payload.base import Payload
from github_contexts.github.payload.issue_comment import IssueCommentPayload
from github_contexts.github.payload.issues import IssuesPayload
from github_contexts.github.payload.pull_request import PullRequestPayload
from github_contexts.github.payload.push import PushPayload
from github_contexts.github.payload.schedule import SchedulePayload
from github_contexts.github.payload.workflow_dispatch import WorkflowDispatchPayload
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from ruamel.yaml import YAML

from github_contexts.github.payloads.objects.user import UserObject
from github_contexts.github.payloads.objects.repository import RepositoryObject
from github_contexts.github.payload.object.user import User
from github_contexts.github.payload.object.repository import Repository


class Payload:
Expand Down Expand Up @@ -50,14 +50,14 @@ def organization(self) -> dict | None:
return self._payload.get("organization")

@property
def repository(self) -> RepositoryObject | None:
def repository(self) -> Repository | None:
"""The repository on GitHub where the event occurred.
This is only available when the event occurs from activity in the repository.
"""
return RepositoryObject(self._payload["repository"]) if "repository" in self._payload else None
return Repository(self._payload["repository"]) if "repository" in self._payload else None

@property
def sender(self) -> UserObject:
def sender(self) -> User:
"""The GitHub user that triggered the event."""
return UserObject(self._payload["sender"])
return User(self._payload["sender"])
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from github_contexts.github.payloads.base import Payload
from github_contexts.github.enums import ActionType
from github_contexts.github.payloads.objects.comment import CommentObject
from github_contexts.github.payloads.objects.issue import IssueObject
from github_contexts.github.payloads.objects.changes import IssueCommentEditedChangesObject
from github_contexts.github.payload.base import Payload
from github_contexts.github.enum import ActionType
from github_contexts.github.payload.object.comment import Comment
from github_contexts.github.payload.object.issue import Issue
from github_contexts.github.payload.object.changes import IssueCommentEditedChanges


class IssueCommentPayload(Payload):
Expand All @@ -18,23 +18,23 @@ def action(self) -> ActionType:
return ActionType(self._payload["action"])

@property
def comment(self) -> CommentObject:
def comment(self) -> Comment:
"""Comment data."""
return CommentObject(self._payload["comment"])
return Comment(self._payload["comment"])

@property
def issue(self) -> IssueObject:
def issue(self) -> Issue:
"""Issue data."""
return IssueObject(self._payload["issue"])
return Issue(self._payload["issue"])

@property
def is_on_pull(self) -> bool:
"""Whether the comment is on a pull request (True) or an issue (False)."""
return bool(self.issue.pull_request)

@property
def changes(self) -> IssueCommentEditedChangesObject | None:
def changes(self) -> IssueCommentEditedChanges | None:
"""The changes to the comment if the action was 'edited'."""
if self.action == ActionType.EDITED:
return IssueCommentEditedChangesObject(self._payload["changes"])
return IssueCommentEditedChanges(self._payload["changes"])
return
68 changes: 68 additions & 0 deletions src/github_contexts/github/payload/issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""GitHub Webhook Issues Payload."""


from github_contexts.github.payload.base import Payload
from github_contexts.github.enum import ActionType
from github_contexts.github.payload.object.issue import Issue
from github_contexts.github.payload.object.user import User
from github_contexts.github.payload.object.milestone import Milestone
from github_contexts.github.payload.object.label import Label
from github_contexts.github.payload.object.changes import (
IssueOpenedChanges, IssueEditedChanges, IssueTransferredChanges
)


class IssuesPayload(Payload):

def __init__(self, payload: dict):
super().__init__(payload=payload)
return

@property
def action(self) -> ActionType:
return ActionType(self._payload["action"])

@property
def issue(self) -> Issue:
"""The issue data.
References
----------
- [GitHub API Docs](https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue)
"""
return Issue(self._payload["issue"])

@property
def assignee(self) -> User | None:
"""The user that was assigned or unassigned from the issue.
This is only available for the 'assigned' and 'unassigned' events.
"""
return User(self._payload.get("assignee"))

@property
def changes(self) -> IssueOpenedChanges | IssueEditedChanges | IssueTransferredChanges | None:
"""The changes to the issue if the action was 'edited'."""
if self.action == ActionType.EDITED:
return IssueEditedChanges(self._payload["changes"])
if self.action == ActionType.OPENED:
return IssueOpenedChanges(self._payload["changes"])
if self.action == ActionType.TRANSFERRED:
return IssueTransferredChanges(self._payload["changes"])
return

@property
def label(self) -> Label | None:
"""The label that was added or removed from the issue.
This is only available for the 'labeled' and 'unlabeled' events.
"""
return Label(self._payload["label"]) if self._payload.get("label") else None

@property
def milestone(self) -> Milestone | None:
"""The milestone that was added to or removed from the issue.
This is only available for the 'milestoned' and 'demilestoned' events.
"""
return Milestone(self._payload.get("milestone"))
23 changes: 23 additions & 0 deletions src/github_contexts/github/payload/object/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from github_contexts.github.payload.object.auto_merge import AutoMerge
from github_contexts.github.payload.object.changes import (
IssueOpenedChanges,
IssueTransferredChanges,
IssueEditedChanges,
PullRequestEditedChanges,
IssueCommentEditedChanges,
)
from github_contexts.github.payload.object.comment import Comment
from github_contexts.github.payload.object.commit import Commit
from github_contexts.github.payload.object.commit_author import CommitAuthor
from github_contexts.github.payload.object.head_base import HeadBase
from github_contexts.github.payload.object.issue import Issue
from github_contexts.github.payload.object.label import Label
from github_contexts.github.payload.object.license import License
from github_contexts.github.payload.object.milestone import Milestone
from github_contexts.github.payload.object.performed_via_github_app import PerformedViaGitHubApp
from github_contexts.github.payload.object.permissions import Permissions
from github_contexts.github.payload.object.pull_request import PullRequest
from github_contexts.github.payload.object.reactions import Reactions
from github_contexts.github.payload.object.repository import Repository
from github_contexts.github.payload.object.team import Team
from github_contexts.github.payload.object.user import User
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from github_contexts.github.payloads.objects.user import UserObject
from github_contexts.github.enums import MergeMethod
from github_contexts.github.payload.object.user import User
from github_contexts.github.enum import MergeMethod


class AutoMergeObject:
class AutoMerge:
"""The status of auto merging a pull request."""

def __init__(self, auto_merge: dict):
Expand All @@ -26,9 +26,9 @@ def commit_title(self) -> str | None:
return self._auto_merge.get("commit_title")

@property
def enabled_by(self) -> UserObject | None:
def enabled_by(self) -> User | None:
"""The user who enabled auto merging."""
return UserObject(self._auto_merge["enabled_by"]) if self._auto_merge.get("enabled_by") else None
return User(self._auto_merge["enabled_by"]) if self._auto_merge.get("enabled_by") else None

@property
def merge_method(self) -> MergeMethod:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
from github_contexts.github.payloads.objects.issue import IssueObject
from github_contexts.github.payloads.objects.repository import RepositoryObject
from github_contexts.github.payload.object.issue import Issue
from github_contexts.github.payload.object.repository import Repository


class IssueOpenedChangesObject:
class IssueOpenedChanges:

def __init__(self, changes: dict):
self._changes = changes
return

@property
def old_issue(self) -> IssueObject | None:
return IssueObject(self._changes["old_issue"]) if self._changes.get("old_issue") else None
def old_issue(self) -> Issue | None:
return Issue(self._changes["old_issue"]) if self._changes.get("old_issue") else None

@property
def old_repository(self) -> RepositoryObject:
return RepositoryObject(self._changes["old_repository"])
def old_repository(self) -> Repository:
return Repository(self._changes["old_repository"])


class IssueTransferredChangesObject:
class IssueTransferredChanges:

def __init__(self, changes: dict):
self._changes = changes
return

@property
def new_issue(self) -> IssueObject:
return IssueObject(self._changes["new_issue"])
def new_issue(self) -> Issue:
return Issue(self._changes["new_issue"])

@property
def new_repository(self) -> RepositoryObject:
return RepositoryObject(self._changes["new_repository"])
def new_repository(self) -> Repository:
return Repository(self._changes["new_repository"])


class IssueEditedChangesObject:
class IssueEditedChanges:

def __init__(self, changes: dict):
self._changes = changes
Expand All @@ -47,7 +47,7 @@ def title(self) -> dict | None:
return self._changes.get("title")


class PullRequestEditedChangesObject:
class PullRequestEditedChanges:

def __init__(self, changes: dict):
self._changes = changes
Expand All @@ -72,7 +72,7 @@ def title(self) -> dict | None:
return self._changes.get("title", {}).get("from")


class IssueCommentEditedChangesObject:
class IssueCommentEditedChanges:

def __init__(self, changes: dict):
self._changes = changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from github_contexts.github.enums import AuthorAssociation
from github_contexts.github.payloads.objects.user import UserObject
from github_contexts.github.payloads.objects.performed_via_github_app import PerformedViaGitHubAppObject
from github_contexts.github.payloads.objects.reactions import ReactionsObject
from github_contexts.github.enum import AuthorAssociation
from github_contexts.github.payload.object.user import User
from github_contexts.github.payload.object.performed_via_github_app import PerformedViaGitHubApp
from github_contexts.github.payload.object.reactions import Reactions


class CommentObject:
class Comment:

def __init__(self, comment: dict):
self._comment = comment
Expand Down Expand Up @@ -45,14 +45,14 @@ def node_id(self) -> str:
return self._comment["node_id"]

@property
def performed_via_github_app(self) -> PerformedViaGitHubAppObject | None:
def performed_via_github_app(self) -> PerformedViaGitHubApp | None:
"""GitHub App that performed the comment."""
return PerformedViaGitHubAppObject(self._comment["performed_via_github_app"]) if self._comment.get("performed_via_github_app") else None
return PerformedViaGitHubApp(self._comment["performed_via_github_app"]) if self._comment.get("performed_via_github_app") else None

@property
def reactions(self) -> ReactionsObject:
def reactions(self) -> Reactions:
"""Reactions to the comment."""
return ReactionsObject(self._comment["reactions"])
return Reactions(self._comment["reactions"])

@property
def updated_at(self) -> str:
Expand All @@ -65,6 +65,6 @@ def url(self) -> str:
return self._comment["url"]

@property
def user(self) -> UserObject | None:
def user(self) -> User | None:
"""User who created the comment."""
return UserObject(self._comment["user"]) if self._comment.get("user") else None
return User(self._comment["user"]) if self._comment.get("user") else None
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from github_contexts.github.payloads.objects.commit_author import CommitAuthorObject
from github_contexts.github.payload.object.commit_author import CommitAuthor


class CommitObject:
class Commit:

def __init__(self, commit: dict):
self._commit = commit
Expand All @@ -13,14 +13,14 @@ def added(self) -> list[str]:
return self._commit.get("added", [])

@property
def author(self) -> CommitAuthorObject:
def author(self) -> CommitAuthor:
"""Git author information."""
return CommitAuthorObject(self._commit["author"])
return CommitAuthor(self._commit["author"])

@property
def committer(self) -> CommitAuthorObject:
def committer(self) -> CommitAuthor:
"""Git committer information."""
return CommitAuthorObject(self._commit["committer"])
return CommitAuthor(self._commit["committer"])

@property
def distinct(self) -> bool:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class CommitAuthorObject:
class CommitAuthor:

def __init__(self, author: dict):
self._author = author
Expand Down
Loading

0 comments on commit 59e0296

Please sign in to comment.