Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ reviewers:
- `/retest tox`: run tox
- `/retest build-container`: run build-container
- `/retest python-module-install`: run python-module-install command
- `/retest all`: run all tests
- `/build-and-push-container`: build and push container image (tag will be the pull request number)
- You can add extra args to the Podman build command
- Example: `/build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>`
Expand Down
104 changes: 73 additions & 31 deletions webhook_server_container/libs/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import time
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
from pathlib import Path
from typing import Any, Dict, Generator, List, Optional, Set
from typing import Any, Callable, Dict, Generator, List, Optional, Set
from stringcolor import cs

from github.Branch import Branch
Expand Down Expand Up @@ -149,6 +149,7 @@ def __init__(self, hook_data: Dict[Any, Any], headers: Headers, logger: logging.
self.add_api_users_to_auto_verified_and_merged_users()

self.supported_user_labels_str: str = "".join([f" * {label}\n" for label in USER_LABELS_DICT.keys()])
self.current_pull_request_supported_retest = self._current_pull_request_supported_retest
self.welcome_msg: str = f"""
Report bugs in [Issues](https://github.com/myakove/github-webhook-server/issues)

Expand Down Expand Up @@ -238,6 +239,12 @@ def prepare_retest_wellcome_msg(self) -> str:
if self.pypi:
retest_msg += f" * `/retest {PYTHON_MODULE_INSTALL_STR}`: Retest python-module-install\n"

if self.pre_commit:
retest_msg += f" * `/retest {PRE_COMMIT_STR}`: Retest pre-commit\n"

if retest_msg:
retest_msg += " * `/retest all`: Retest all\n"

return " * This repository does not support retest actions" if not retest_msg else retest_msg

def add_api_users_to_auto_verified_and_merged_users(self) -> None:
Expand Down Expand Up @@ -1850,41 +1857,58 @@ def process_cherry_pick_command(self, issue_comment_id: int, command_args: str,

def process_retest_command(self, issue_comment_id: int, command_args: str) -> None:
_target_tests: List[str] = command_args.split()
for _test in _target_tests:
if _test == TOX_STR:
if not self.tox:
msg: str = f"No {TOX_STR} configured for this repository"
error_msg = f"{self.log_prefix} {msg}."
self.logger.info(error_msg)
self.pull_request.create_issue_comment(msg)
return
_not_supported_retests: List[str] = []
_supported_retests: List[str] = []
_retests_to_func_map: Dict[str, Callable] = {
TOX_STR: self._run_tox,
PRE_COMMIT_STR: self._run_pre_commit,
BUILD_CONTAINER_STR: self._run_build_container,
PYTHON_MODULE_INSTALL_STR: self._run_install_python_module,
}

self.create_comment_reaction(issue_comment_id=issue_comment_id, reaction=REACTIONS.ok)
self._run_tox()
if not _target_tests:
msg = "No test defined to retest"
error_msg = f"{self.log_prefix} {msg}."
self.logger.debug(error_msg)
self.pull_request.create_issue_comment(msg)
return
Comment thread
myakove marked this conversation as resolved.

elif _test == PRE_COMMIT_STR:
self.create_comment_reaction(issue_comment_id=issue_comment_id, reaction=REACTIONS.ok)
self._run_pre_commit()
if "all" in command_args:
Comment thread
myakove marked this conversation as resolved.
if len(command_args) > 1:
msg = "Invalid command. `all` cannot be used with other tests"
error_msg = f"{self.log_prefix} {msg}."
self.logger.debug(error_msg)
self.pull_request.create_issue_comment(msg)
return

else:
_supported_retests = self.current_pull_request_supported_retest

else:
for _test in _target_tests:
if _test in self.current_pull_request_supported_retest:
_supported_retests.append(_test)

elif _test == BUILD_CONTAINER_STR:
if self.build_and_push_container:
self.create_comment_reaction(issue_comment_id=issue_comment_id, reaction=REACTIONS.ok)
self._run_build_container()
else:
msg = f"No {BUILD_CONTAINER_STR} configured for this repository"
error_msg = f"{self.log_prefix} {msg}"
self.logger.info(error_msg)
self.pull_request.create_issue_comment(msg)

elif _test == PYTHON_MODULE_INSTALL_STR:
if not self.pypi:
error_msg = f"{self.log_prefix} No pypi configured"
self.logger.info(error_msg)
self.pull_request.create_issue_comment(error_msg)
return
_not_supported_retests.append(_test)

self.create_comment_reaction(issue_comment_id=issue_comment_id, reaction=REACTIONS.ok)
self._run_install_python_module()
if _not_supported_retests:
msg = f"No {' '.join(_not_supported_retests)} configured for this repository"
error_msg = f"{self.log_prefix} {msg}."
self.logger.debug(error_msg)
self.pull_request.create_issue_comment(msg)

if _supported_retests:
self.create_comment_reaction(issue_comment_id=issue_comment_id, reaction=REACTIONS.ok)

_retest_to_exec: List[Future] = []
with ThreadPoolExecutor() as executor:
for _test in _supported_retests:
_retest_to_exec.append(executor.submit(_retests_to_func_map[_test]))

for result in as_completed(_retest_to_exec):
if _exp := result.exception():
self.logger.error(f"{self.log_prefix} {_exp}")

def remove_labels_when_pull_request_sync(self) -> None:
futures = []
Expand Down Expand Up @@ -2005,3 +2029,21 @@ def set_pull_request_automerge(self) -> None:

except Exception as exp:
self.logger.error(f"{self.log_prefix} Exception while setting auto merge: {exp}")

@property
def _current_pull_request_supported_retest(self) -> List[str]:
current_pull_request_supported_retest: List[str] = []

if self.tox:
current_pull_request_supported_retest.append(TOX_STR)

if self.build_and_push_container:
current_pull_request_supported_retest.append(BUILD_CONTAINER_STR)

if self.pypi:
current_pull_request_supported_retest.append(PYTHON_MODULE_INSTALL_STR)

if self.pre_commit:
current_pull_request_supported_retest.append(PRE_COMMIT_STR)

return current_pull_request_supported_retest