-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up all previous GitAuto comments when starting except its trigg…
…er comment
- Loading branch information
1 parent
a63171b
commit c229aa9
Showing
6 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CLICK_THE_CHECKBOX = "Click the checkbox below to generate a PR!" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from requests import delete, get | ||
from config import GITHUB_API_URL, TIMEOUT | ||
from constants.messages import CLICK_THE_CHECKBOX | ||
from services.github.create_headers import create_headers | ||
from services.github.github_types import BaseArgs | ||
from utils.handle_exceptions import handle_exceptions | ||
|
||
|
||
@handle_exceptions(default_return_value=None, raise_on_error=False) | ||
def delete_a_comment(base_args: BaseArgs, comment_id: str): | ||
"""https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#delete-an-issue-comment""" | ||
owner, repo, token = (base_args["owner"], base_args["repo"], base_args["token"]) | ||
url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues/comments/{comment_id}" | ||
headers: dict[str, str] = create_headers(token=token) | ||
response = delete(url=url, headers=headers, timeout=TIMEOUT) | ||
response.raise_for_status() | ||
|
||
|
||
@handle_exceptions(default_return_value=None, raise_on_error=False) | ||
def get_all_comments(base_args: BaseArgs): | ||
"""https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments""" | ||
owner, repo, issue_number, token = ( | ||
base_args["owner"], | ||
base_args["repo"], | ||
base_args["issue_number"], | ||
base_args["token"], | ||
) | ||
url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues/{issue_number}/comments" | ||
headers: dict[str, str] = create_headers(token=token) | ||
response = get(url=url, headers=headers, timeout=TIMEOUT) | ||
response.raise_for_status() | ||
comments: list[dict] = response.json() | ||
# print(f"All comments: {dumps(obj=comments, indent=2)}") | ||
return comments | ||
|
||
|
||
def filter_my_comments(comments: list[dict]): | ||
"""Filter out comments made by GitAuto except the one with the checkbox""" | ||
return [ | ||
comment for comment in comments if CLICK_THE_CHECKBOX not in comment["body"] | ||
] | ||
|
||
|
||
def delete_my_comments(base_args: BaseArgs): | ||
"""Delete all comments made by GitAuto except the one with the checkbox""" | ||
comments = get_all_comments(base_args) | ||
my_comments = filter_my_comments(comments) | ||
# print(f"My comments: {dumps(obj=my_comments, indent=2)}") | ||
for comment in my_comments: | ||
delete_a_comment(base_args=base_args, comment_id=comment["id"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters