mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-22 13:56:44 +00:00
refactor: add common base class to GitHubClient and LocalClient
Enables adding type checking to minimize mypy errors
This commit is contained in:
parent
ef72f61bed
commit
f1f17d8372
12
Client.py
Normal file
12
Client.py
Normal file
@ -0,0 +1,12 @@
|
||||
class Client(object):
|
||||
def get_last_diff(self):
|
||||
return None
|
||||
|
||||
def create_issue(self, issue):
|
||||
return [201, None]
|
||||
|
||||
def close_issue(self, issue):
|
||||
return 200
|
||||
|
||||
def get_issue_url(self, new_issue_number):
|
||||
return "N/A"
|
||||
@ -1,8 +1,9 @@
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
from Client import Client
|
||||
|
||||
class GitHubClient(object):
|
||||
class GitHubClient(Client):
|
||||
"""Basic client for getting the last diff and managing issues."""
|
||||
existing_issues = []
|
||||
milestones = []
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import subprocess
|
||||
import os
|
||||
from Client import Client
|
||||
|
||||
class LocalClient(object):
|
||||
class LocalClient(Client):
|
||||
def __init__(self):
|
||||
self.diff_url = None
|
||||
self.commits = ['placeholder'] # content doesn't matter, just length
|
||||
@ -31,12 +32,3 @@ class LocalClient(object):
|
||||
|
||||
def get_last_diff(self):
|
||||
return subprocess.run(['git', 'diff', f'{self.base_ref}..{self.sha}'], stdout=subprocess.PIPE).stdout.decode('latin-1')
|
||||
|
||||
def create_issue(self, issue):
|
||||
return [201, None]
|
||||
|
||||
def close_issue(self, issue):
|
||||
return 200
|
||||
|
||||
def get_issue_url(self, new_issue_number):
|
||||
return "N/A"
|
||||
|
||||
4
main.py
4
main.py
@ -10,18 +10,20 @@ import operator
|
||||
from collections import defaultdict
|
||||
from TodoParser import TodoParser
|
||||
from LineStatus import LineStatus
|
||||
from Client import Client
|
||||
from LocalClient import LocalClient
|
||||
from GitHubClient import GitHubClient
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
client: Client | None = None
|
||||
# Try to create a basic client for communicating with the remote version control server, automatically initialised with environment variables.
|
||||
try:
|
||||
# try to build a GitHub client
|
||||
client = GitHubClient()
|
||||
except EnvironmentError:
|
||||
# don't immediately give up
|
||||
client = None
|
||||
pass
|
||||
# if needed, fall back to using a local client for testing
|
||||
client = client or LocalClient()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user