mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-22 22:06:43 +00:00
feat: add Local client
This is just a safe fallback for local testing. If environment variables which activate the creation of the GitHub client aren't set, then the Local client is created. It acts on the most recent commit of the repo in the working directory. Minor edit to GitHubClient so that it raises an EnvironmentError exception if INPUT_GITHUB_URL environment variable is not defined. This allows main to detect the error and fall back to trying to use the Local client
This commit is contained in:
parent
662435d7fc
commit
714153eaf3
@ -9,6 +9,8 @@ class GitHubClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self.github_url = os.getenv('INPUT_GITHUB_URL')
|
||||
if not self.github_url:
|
||||
raise EnvironmentError
|
||||
self.base_url = f'{self.github_url}/'
|
||||
self.repos_url = f'{self.base_url}repos/'
|
||||
self.repo = os.getenv('INPUT_REPO')
|
||||
|
||||
16
LocalClient.py
Normal file
16
LocalClient.py
Normal file
@ -0,0 +1,16 @@
|
||||
import subprocess
|
||||
|
||||
class LocalClient(object):
|
||||
def __init__(self):
|
||||
self.diff_url = None
|
||||
self.commits = ['placeholder'] # content doesn't matter, just length
|
||||
self.insert_issue_urls = False
|
||||
|
||||
def get_last_diff(self):
|
||||
return subprocess.run(['git', 'diff', 'HEAD^..HEAD'], stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||
|
||||
def create_issue(self, issue):
|
||||
return [201, None]
|
||||
|
||||
def close_issue(self, issue):
|
||||
return 200
|
||||
13
main.py
13
main.py
@ -11,12 +11,21 @@ import operator
|
||||
from collections import defaultdict
|
||||
from TodoParser import *
|
||||
from LineStatus import *
|
||||
from LocalClient import *
|
||||
from GitHubClient import *
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create a basic client for communicating with GitHub, automatically initialised with environment variables.
|
||||
client = GitHubClient()
|
||||
# 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
|
||||
# if needed, fall back to using a local client for testing
|
||||
client = client or LocalClient()
|
||||
|
||||
# Check to see if the workflow has been run manually.
|
||||
# If so, adjust the client SHA and diff URL to use the manually supplied inputs.
|
||||
manual_commit_ref = os.getenv('MANUAL_COMMIT_REF')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user