From bbb0909595f7d73ee1731b73253ec0cc94f5b5e9 Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 10:19:34 -0400 Subject: [PATCH 01/13] Add gitignore and requirements.txt for local development --- .gitignore | 2 ++ requirements.txt | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82195aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv +.idea \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e5cf445 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests==2.26.0 +ruamel.yaml==0.17.16 \ No newline at end of file From dd21bd0164d7abeba4c579b1b7e56cdaa3cda471 Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 10:22:32 -0400 Subject: [PATCH 02/13] Display github client information --- main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.py b/main.py index 5327578..3e2ccba 100644 --- a/main.py +++ b/main.py @@ -62,6 +62,10 @@ class GitHubClient(object): # Retrieve the existing repo issues now so we can easily check them later. self._get_existing_issues() + def __repr__(self): + formatted_commits = json.dumps(self.commits, indent=2) + return f"GitHubClient(repo={self.repo}, before={self.before}, sha={self.sha}, commits={formatted_commits})" + def get_timestamp(self, commit): return commit.get('timestamp') @@ -618,6 +622,7 @@ class TodoParser(object): if __name__ == "__main__": # Create a basic client for communicating with GitHub, automatically initialised with environment variables. client = GitHubClient() + print(f"Instantiated {client}") if len(client.commits) != 0: # Get the diff from the last pushed commit. last_diff = StringIO(client.get_last_diff()) From 6cef54738154e3a1f1a68e4ba8f6ca1333d84da3 Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 10:27:09 -0400 Subject: [PATCH 03/13] Add some temporary debugging prints to understand flow --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index 3e2ccba..9ea2215 100644 --- a/main.py +++ b/main.py @@ -86,6 +86,7 @@ class GitHubClient(object): 'Accept': 'application/vnd.github.v3.diff', 'Authorization': f'token {self.token}' } + print(f"Requesting {diff_url} to get changes") diff_request = requests.get(url=diff_url, headers=diff_headers) if diff_request.status_code == 200: return diff_request.text @@ -626,8 +627,10 @@ if __name__ == "__main__": if len(client.commits) != 0: # Get the diff from the last pushed commit. last_diff = StringIO(client.get_last_diff()) + print(f"Got changes: {last_diff}") # Parse the diff for TODOs and create an Issue object for each. raw_issues = TodoParser().parse(last_diff) + print(f"Got raw issues: {raw_issues}") # This is a simple, non-perfect check to filter out any TODOs that have just been moved. # It looks for items that appear in the diff as both an addition and deletion. # It is based on the assumption that TODOs will not have identical titles in identical files. From 9867ed27cdbc9224f2240e1c8d50afde533ba95b Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 10:52:41 -0400 Subject: [PATCH 04/13] Try to support diff url from pull request --- action.yml | 4 ++++ main.py | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 65cdf02..00bb8fd 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,10 @@ inputs: description: "An array of commit objects describing the pushed commits" required: true default: "${{ toJSON(github.event.commits) }}" + DIFF_URL: + description: "The URL to use to get the diff (automatically set)" + required: true + default: "${{ github.event.pull_request?.diff_url }}" SHA: description: "The SHA of the latest commit (automatically set)" required: true diff --git a/main.py b/main.py index 9ea2215..d5b571d 100644 --- a/main.py +++ b/main.py @@ -51,6 +51,7 @@ class GitHubClient(object): self.before = os.getenv('INPUT_BEFORE') self.sha = os.getenv('INPUT_SHA') self.commits = json.loads(os.getenv('INPUT_COMMITS')) + self.diff_url = os.getenv('DIFF_URL') self.token = os.getenv('INPUT_TOKEN') self.issues_url = f'{self.repos_url}{self.repo}/issues' self.issue_headers = { @@ -64,14 +65,17 @@ class GitHubClient(object): def __repr__(self): formatted_commits = json.dumps(self.commits, indent=2) - return f"GitHubClient(repo={self.repo}, before={self.before}, sha={self.sha}, commits={formatted_commits})" + return f"GitHubClient(repo={self.repo}, before={self.before}, sha={self.sha}, diff_url={self.diff_url}, commits={formatted_commits})" def get_timestamp(self, commit): return commit.get('timestamp') def get_last_diff(self): """Get the last diff.""" - if self.before != '0000000000000000000000000000000000000000': + if self.diff_url: + # Diff url was directly passed in config, likely due to this being a PR + diff_url = self.diff_url + elif self.before != '0000000000000000000000000000000000000000': # There is a valid before SHA to compare with, or this is a release being created diff_url = f'{self.repos_url}{self.repo}/compare/{self.before}...{self.sha}' elif len(self.commits) == 1: @@ -89,7 +93,9 @@ class GitHubClient(object): print(f"Requesting {diff_url} to get changes") diff_request = requests.get(url=diff_url, headers=diff_headers) if diff_request.status_code == 200: - return diff_request.text + text = diff_request.text + print("Diff text:\n{text}") + return text raise Exception('Could not retrieve diff. Operation will abort.') def _get_existing_issues(self, page=1): @@ -624,10 +630,9 @@ if __name__ == "__main__": # Create a basic client for communicating with GitHub, automatically initialised with environment variables. client = GitHubClient() print(f"Instantiated {client}") - if len(client.commits) != 0: + if client.diff_url or len(client.commits) != 0: # Get the diff from the last pushed commit. last_diff = StringIO(client.get_last_diff()) - print(f"Got changes: {last_diff}") # Parse the diff for TODOs and create an Issue object for each. raw_issues = TodoParser().parse(last_diff) print(f"Got raw issues: {raw_issues}") From 550a8c0d96daeee96abc9430c500bc43e1fdc4f8 Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 11:01:51 -0400 Subject: [PATCH 05/13] Remove optional chain as it is not supported --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 00bb8fd..89b02a8 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: DIFF_URL: description: "The URL to use to get the diff (automatically set)" required: true - default: "${{ github.event.pull_request?.diff_url }}" + default: "${{ github.event.pull_request.diff_url }}" SHA: description: "The SHA of the latest commit (automatically set)" required: true From 2c95e88a49fea34262a526df3fed025c2661a0cf Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 11:15:36 -0400 Subject: [PATCH 06/13] Fix debug statement --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index d5b571d..bdef4c0 100644 --- a/main.py +++ b/main.py @@ -94,7 +94,7 @@ class GitHubClient(object): diff_request = requests.get(url=diff_url, headers=diff_headers) if diff_request.status_code == 200: text = diff_request.text - print("Diff text:\n{text}") + print(f"Diff text:\n{text}") return text raise Exception('Could not retrieve diff. Operation will abort.') From 308708439ce77e3cd2852c20000be6e33c40dbbd Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 11:25:19 -0400 Subject: [PATCH 07/13] Use correct environment variable for diff url --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index bdef4c0..aa1607a 100644 --- a/main.py +++ b/main.py @@ -51,7 +51,7 @@ class GitHubClient(object): self.before = os.getenv('INPUT_BEFORE') self.sha = os.getenv('INPUT_SHA') self.commits = json.loads(os.getenv('INPUT_COMMITS')) - self.diff_url = os.getenv('DIFF_URL') + self.diff_url = os.getenv('INPUT_DIFF_URL') self.token = os.getenv('INPUT_TOKEN') self.issues_url = f'{self.repos_url}{self.repo}/issues' self.issue_headers = { From ed9392d2521654cd09afa26c8577664cafb7e27b Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 12:15:32 -0400 Subject: [PATCH 08/13] Remove debugging prints --- main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/main.py b/main.py index aa1607a..6c057db 100644 --- a/main.py +++ b/main.py @@ -90,12 +90,9 @@ class GitHubClient(object): 'Accept': 'application/vnd.github.v3.diff', 'Authorization': f'token {self.token}' } - print(f"Requesting {diff_url} to get changes") diff_request = requests.get(url=diff_url, headers=diff_headers) if diff_request.status_code == 200: - text = diff_request.text - print(f"Diff text:\n{text}") - return text + return diff_request.text raise Exception('Could not retrieve diff. Operation will abort.') def _get_existing_issues(self, page=1): @@ -635,7 +632,6 @@ if __name__ == "__main__": last_diff = StringIO(client.get_last_diff()) # Parse the diff for TODOs and create an Issue object for each. raw_issues = TodoParser().parse(last_diff) - print(f"Got raw issues: {raw_issues}") # This is a simple, non-perfect check to filter out any TODOs that have just been moved. # It looks for items that appear in the diff as both an addition and deletion. # It is based on the assumption that TODOs will not have identical titles in identical files. From d419ec1f17abd08015ba71b0435f82bf1c1e6996 Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 12:17:36 -0400 Subject: [PATCH 09/13] Try automatically setting base ref for PRs --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 89b02a8..3cb5b70 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,7 @@ inputs: BEFORE: description: "The SHA of the last pushed commit (automatically set)" required: true - default: "${{ github.event.before }}" + default: "${{ github.event.before || github.base_ref }}" COMMITS: description: "An array of commit objects describing the pushed commits" required: true From 578030b505d116bdec314447c23adf99181216a0 Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 12:15:32 -0400 Subject: [PATCH 10/13] Revert "Remove debugging prints" This reverts commit ed9392d2521654cd09afa26c8577664cafb7e27b. --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 6c057db..aa1607a 100644 --- a/main.py +++ b/main.py @@ -90,9 +90,12 @@ class GitHubClient(object): 'Accept': 'application/vnd.github.v3.diff', 'Authorization': f'token {self.token}' } + print(f"Requesting {diff_url} to get changes") diff_request = requests.get(url=diff_url, headers=diff_headers) if diff_request.status_code == 200: - return diff_request.text + text = diff_request.text + print(f"Diff text:\n{text}") + return text raise Exception('Could not retrieve diff. Operation will abort.') def _get_existing_issues(self, page=1): @@ -632,6 +635,7 @@ if __name__ == "__main__": last_diff = StringIO(client.get_last_diff()) # Parse the diff for TODOs and create an Issue object for each. raw_issues = TodoParser().parse(last_diff) + print(f"Got raw issues: {raw_issues}") # This is a simple, non-perfect check to filter out any TODOs that have just been moved. # It looks for items that appear in the diff as both an addition and deletion. # It is based on the assumption that TODOs will not have identical titles in identical files. From 313d5e4ec89efabe667d122a567bee0817c4471c Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 12:15:32 -0400 Subject: [PATCH 11/13] Revert "Revert "Remove debugging prints"" This reverts commit 578030b505d116bdec314447c23adf99181216a0. --- main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/main.py b/main.py index aa1607a..6c057db 100644 --- a/main.py +++ b/main.py @@ -90,12 +90,9 @@ class GitHubClient(object): 'Accept': 'application/vnd.github.v3.diff', 'Authorization': f'token {self.token}' } - print(f"Requesting {diff_url} to get changes") diff_request = requests.get(url=diff_url, headers=diff_headers) if diff_request.status_code == 200: - text = diff_request.text - print(f"Diff text:\n{text}") - return text + return diff_request.text raise Exception('Could not retrieve diff. Operation will abort.') def _get_existing_issues(self, page=1): @@ -635,7 +632,6 @@ if __name__ == "__main__": last_diff = StringIO(client.get_last_diff()) # Parse the diff for TODOs and create an Issue object for each. raw_issues = TodoParser().parse(last_diff) - print(f"Got raw issues: {raw_issues}") # This is a simple, non-perfect check to filter out any TODOs that have just been moved. # It looks for items that appear in the diff as both an addition and deletion. # It is based on the assumption that TODOs will not have identical titles in identical files. From ae75d8bae4f4d51a42b15974de58354c11047f4d Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 12:27:53 -0400 Subject: [PATCH 12/13] Revert "Display github client information" This reverts commit dd21bd0164d7abeba4c579b1b7e56cdaa3cda471. --- main.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.py b/main.py index 6c057db..45f9946 100644 --- a/main.py +++ b/main.py @@ -63,10 +63,6 @@ class GitHubClient(object): # Retrieve the existing repo issues now so we can easily check them later. self._get_existing_issues() - def __repr__(self): - formatted_commits = json.dumps(self.commits, indent=2) - return f"GitHubClient(repo={self.repo}, before={self.before}, sha={self.sha}, diff_url={self.diff_url}, commits={formatted_commits})" - def get_timestamp(self, commit): return commit.get('timestamp') @@ -626,7 +622,6 @@ class TodoParser(object): if __name__ == "__main__": # Create a basic client for communicating with GitHub, automatically initialised with environment variables. client = GitHubClient() - print(f"Instantiated {client}") if client.diff_url or len(client.commits) != 0: # Get the diff from the last pushed commit. last_diff = StringIO(client.get_last_diff()) From e39632954a0a57753663c8fa967e2ef24560e453 Mon Sep 17 00:00:00 2001 From: Nick DeRobertis Date: Sun, 24 Oct 2021 10:19:34 -0400 Subject: [PATCH 13/13] Revert "Add gitignore and requirements.txt for local development" This reverts commit bbb0909595f7d73ee1731b73253ec0cc94f5b5e9. --- .gitignore | 2 -- requirements.txt | 2 -- 2 files changed, 4 deletions(-) delete mode 100644 .gitignore delete mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 82195aa..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -venv -.idea \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e5cf445..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -requests==2.26.0 -ruamel.yaml==0.17.16 \ No newline at end of file