Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.env
env/
venv/
git-orca/git-orca.json
git-orca/git-orca.txt
git-orca/helpers/__pycache__
test.py
dist/
dist/
__pycache__
1 change: 1 addition & 0 deletions git-orca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from git_orca import GitOrca
49 changes: 49 additions & 0 deletions git-orca/git_orca.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import requests
from helpers.types import Selection, SelectionState


class GitOrca:
"""
Git-Orca
"""
def __init__(self, github_access_token: str = None):
"""
Initialize git-orca with github access token
"""
self.github_access_token = github_access_token

def get_issues(self, repo_name: str, repo_owner: str, state: SelectionState = 'open', per_page: int = 20, page : int = 1):
"""
Get issues
"""
response = requests.get(f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues",
headers={
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": f"Bearer {self.github_access_token}"
},
params={
"state": f"{state}",
"per_page": f"{per_page}",
"page": f"{page}"
}
)
return response.json()

def get_prs(self, repo_name: str, repo_owner: str, state: SelectionState = 'open', per_page: int = 20, page : int = 1):
"""
Get pull requests
"""
response = requests.get(f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls",
headers={
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": f"Bearer {self.github_access_token}"
},
params={
"state": f"{state}",
"per_page": f"{per_page}",
"page": f"{page}"
}
)
return response.json()
1 change: 1 addition & 0 deletions git-orca/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from git_orca import GitOrca
28 changes: 12 additions & 16 deletions git-orca/helpers/commands.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3

import requests, os, json
from .creator import write_json_issues, write_txt_issues, write_json_pr, write_txt_pr
from . import GitOrca


def ask_question(question, type):
pass


def CLI(token, args):
print("\n<==> git-orca <==>\n")

Expand Down Expand Up @@ -42,12 +43,16 @@ def CLI(token, args):
page = int(input("\nWhat page do you want to view?\n"))
if page < 1:
page = "1"
else:
page = args['p']

per_page = None
if args["pp"] == 0:
per_page = int(input("\nHow many per page?\n"))
if per_page < 1:
per_page = "30"
else:
per_page = args['pp']

file_format = None
if not args["json"] and not args["txt"]:
Expand All @@ -57,19 +62,10 @@ def CLI(token, args):

print("\nFetching...\n")

r = requests.get(f"https://api.github.com/repos/{owner}/{repo}/issues",
headers={
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": f"Bearer {token}"
},
params={
"state": f"{state}",
"per_page": f"{per_page}",
"page": f"{page}"
}
)
r = r.json()
if selection == 'issues':
r = GitOrca(token).get_issues(repo, owner, state, per_page, page)
else:
r = GitOrca(token).get_prs(repo, owner, state, per_page, page)

print("\nDone fetching")

Expand Down Expand Up @@ -102,4 +98,4 @@ def CLI(token, args):
print(f"Found no {selection}'s here")

if __name__ == "__main__":
CLI()
CLI()
4 changes: 4 additions & 0 deletions git-orca/helpers/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Literal

Selection = Literal['issue', 'pr']
SelectionState = Literal['open', 'closed', 'all']
2 changes: 1 addition & 1 deletion git-orca/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ def get_args(
main(os.getenv("TOKEN"), args_store)

if __name__ == "__main__":
typer.run(get_args)
typer.run(get_args)