diff --git a/GitHubClient.py b/GitHubClient.py index fa5453b..5513f9d 100644 --- a/GitHubClient.py +++ b/GitHubClient.py @@ -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') diff --git a/LocalClient.py b/LocalClient.py new file mode 100644 index 0000000..9d0b606 --- /dev/null +++ b/LocalClient.py @@ -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 diff --git a/main.py b/main.py index 28d2242..dd1d7c6 100644 --- a/main.py +++ b/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')