Skip to content

Commit

Permalink
authenticate() method refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
lnxpy committed Apr 15, 2024
1 parent c7925f0 commit f76bc6a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 25 deletions.
2 changes: 0 additions & 2 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ steps:
Now, to serialize the issue data coming from the workflow, we have to use `Auth` and `IssueForm` classes.

```py title="your-action/main.py"
from pyaction.auth import Auth
from pyaction.issues import IssueForm
Expand All @@ -185,7 +184,6 @@ from pyaction import io
def main():
auth = Auth(token=io.read("github_token"))
auth.authenticate()
repo = auth.github.get_repo(io.read("repository"))
user_input = IssueForm(repo=repo, number=int(io.read("issue_number"))).render()
Expand Down
20 changes: 1 addition & 19 deletions pyaction/auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import github.Auth
from github import Github
from github.GithubException import BadCredentialsException

from pyaction.exceptions import BrokenToken


class Auth:
Expand All @@ -12,21 +9,6 @@ def __init__(self, token: str) -> None:
Args:
token (str): the `GITHUB_TOKEN` value
"""
self.auth: github.Auth = github.Auth.Token(token)

self.auth: github.Auth = github.Auth.Token(token)
self.github: Github = Github(auth=self.auth)
self.is_authenticated: bool = False

def authenticate(self) -> None:
"""authenticator
Raises:
BrokenToken: if the `token` is broken or not valid
"""
try:
# _ = self.github.get_user().login
self.is_authenticated = True
except BadCredentialsException:
raise BrokenToken(
"`GITHUB_TOKEN` value is either not defiend in `action.yml` or not valid."
)
4 changes: 0 additions & 4 deletions pyaction/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
class WorkflowParameterNotFound(Exception):
pass


class BrokenToken(Exception):
pass

0 comments on commit f76bc6a

Please sign in to comment.