Skip to content

Commit

Permalink
refactor: remove unused imports (#11)
Browse files Browse the repository at this point in the history
* refactor: remove unused imports

An object has been imported but is not used anywhere in the file.
It should either be used or the import should be removed.

* other fixes

* style: format code with Black and isort

This commit fixes the style issues introduced in f2740df according to the output
from Black and isort.

Details: #11

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Heitor Polidoro <[email protected]>
  • Loading branch information
deepsource-autofix[bot] and heitorpolidoro committed Dec 17, 2023
1 parent b6a5940 commit 17593e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
21 changes: 16 additions & 5 deletions github_app/LazyCompletableGithubObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@


class LazyCompletableGithubObject(CompletableGithubObject):
"""
A lazy CompletableGithubObject that will only initialize when it is accessed.
In the initialization will create a github.Requester.Requester
"""

def __init__(
self,
requester: "Requester" = None,
Expand All @@ -33,7 +38,9 @@ def __init__(
def lazy_requester(self):
if self._lazy_requester is None:
token = (
GithubIntegration(auth=AppAuth(681139, os.getenv("PRIVATE_KEY")))
GithubIntegration(
auth=AppAuth(os.getenv("GITHUB_APP_ID"), os.getenv("PRIVATE_KEY"))
)
.get_access_token(Event.installation_id)
.token
)
Expand All @@ -50,6 +57,7 @@ def lazy_requester(self):
return self._lazy_requester

def __getattribute__(self, item):
"""If the value is None, makes a request to update the object."""
value = super().__getattribute__(item)
if (
not item.startswith("_lazy")
Expand All @@ -66,7 +74,10 @@ def __getattribute__(self, item):
return value

@staticmethod
def get_lazy_instance(cls, attributes):
if LazyCompletableGithubObject not in cls.__bases__:
cls.__bases__ = tuple([LazyCompletableGithubObject] + list(cls.__bases__))
return cls(attributes=attributes)
def get_lazy_instance(clazz, attributes):
"""Makes the clazz a subclass of LazyCompletableGithubObject"""
if LazyCompletableGithubObject not in clazz.__bases__:
clazz.__bases__ = tuple(
[LazyCompletableGithubObject] + list(clazz.__bases__)
)
return clazz(attributes=attributes)
8 changes: 6 additions & 2 deletions github_app/ReleaseEvent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from github.GitRelease import GitRelease
from github.Issue import Issue
from github.IssueComment import IssueComment
from github.NamedUser import NamedUser
from github.Repository import Repository

Expand All @@ -9,6 +7,8 @@


class ReleaseEvent(Event):
"""This class represents a generic release event."""

name = "release"

def __init__(self, release, repository, sender, **kwargs):
Expand All @@ -25,8 +25,12 @@ def __init__(self, release, repository, sender, **kwargs):


class ReleaseReleasedEvent(ReleaseEvent):
"""This class represents an event when a release is released."""

action = "released"


class ReleaseCreatedEvent(ReleaseEvent):
"""This class represents an event when a release is created."""

action = "created"
26 changes: 0 additions & 26 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
import os
import pathlib

import pytest
from cryptography.hazmat.backends import default_backend as crypto_default_backend
from cryptography.hazmat.primitives import serialization as crypto_serialization
from cryptography.hazmat.primitives.asymmetric import rsa


@pytest.fixture(scope="session")
def private_key():
if os.path.exists("private-key.pem"):
return pathlib.Path("private-key.pem").read_text()
key = rsa.generate_private_key(
backend=crypto_default_backend(), public_exponent=65537, key_size=2048
)

return key.private_bytes(
crypto_serialization.Encoding.PEM,
crypto_serialization.PrivateFormat.PKCS8,
crypto_serialization.NoEncryption(),
).decode()


@pytest.fixture(scope="session")
def vcr_cassette_name(request):
return "github_requests.yaml"

0 comments on commit 17593e3

Please sign in to comment.