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
2 changes: 2 additions & 0 deletions example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ repositories:
epic: <EPIC KEY> # Optional
user-mapping:
<GITHUB USER>: <JIRA USER> # if github user is not the same as jira

conventional-title: "ci,docs,feat,fix,refactor,test,release" # Check PR title start with any of these words + :
2 changes: 2 additions & 0 deletions webhook_server_container/config/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,5 @@ properties:
jira-tracking:
type: boolean
default: true

conventional-title: string
39 changes: 39 additions & 0 deletions webhook_server_container/libs/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
COMMAND_CHERRY_PICK_STR,
COMMAND_RETEST_STR,
COMMENTED_BY_LABEL_PREFIX,
CONVENTIONAL_TITLE_STR,
DELETE_STR,
DYNAMIC_LABELS_DICT,
FAILURE_STR,
Expand Down Expand Up @@ -427,6 +428,9 @@ def _repo_data_from_config(self) -> None:
key="can-be-merged-required-labels",
return_on_none=[],
)
self.conventional_title: str = get_value_from_dicts(
primary_dict=repo_data, secondary_dict=config_data, key="conventional-title"
)

def _get_pull_request(self, number: Optional[int] = None) -> PullRequest:
if number:
Expand Down Expand Up @@ -743,6 +747,18 @@ def set_python_module_install_success(self, output: Dict[str, Any]) -> None:
def set_python_module_install_failure(self, output: Dict[str, Any]) -> None:
return self.set_check_run_status(check_run=PYTHON_MODULE_INSTALL_STR, conclusion=FAILURE_STR, output=output)

def set_conventional_title_queued(self) -> None:
return self.set_check_run_status(check_run=CONVENTIONAL_TITLE_STR, status=QUEUED_STR)

def set_conventional_title_in_progress(self) -> None:
return self.set_check_run_status(check_run=CONVENTIONAL_TITLE_STR, status=IN_PROGRESS_STR)

def set_conventional_title_success(self, output: Dict[str, Any]) -> None:
return self.set_check_run_status(check_run=CONVENTIONAL_TITLE_STR, conclusion=SUCCESS_STR, output=output)

def set_conventional_title_failure(self, output: Dict[str, Any]) -> None:
return self.set_check_run_status(check_run=CONVENTIONAL_TITLE_STR, conclusion=FAILURE_STR, output=output)

def set_cherry_pick_in_progress(self) -> None:
return self.set_check_run_status(check_run=CHERRY_PICKED_LABEL_PREFIX, status=IN_PROGRESS_STR)

Expand Down Expand Up @@ -849,6 +865,8 @@ def process_pull_request_webhook_data(self) -> None:
pull_request_data: Dict[str, Any] = self.hook_data["pull_request"]
self.parent_committer = pull_request_data["user"]["login"]
self.pull_request_branch = pull_request_data["base"]["ref"]
self.set_conventional_title_queued()
self.conventional_title_check()

if hook_action == "edited":
self.set_wip_label_based_on_title()
Expand Down Expand Up @@ -1706,6 +1724,9 @@ def get_all_required_status_checks(self) -> List[str]:
if self.pypi:
all_required_status_checks.append(PYTHON_MODULE_INSTALL_STR)

if self.conventional_title:
all_required_status_checks.append(CONVENTIONAL_TITLE_STR)

_all_required_status_checks = branch_required_status_checks + all_required_status_checks
self.logger.debug(f"{self.log_prefix} All required status checks: {_all_required_status_checks}")
return _all_required_status_checks
Expand Down Expand Up @@ -2228,3 +2249,21 @@ def _add_reviewer_by_user_comment(self, reviewer: str) -> None:
_err = f"not adding reviewer {reviewer} by user comment, {reviewer} is not part of contributers"
self.logger.debug(f"{self.log_prefix} {_err}")
self.pull_request.create_issue_comment(_err)

def conventional_title_check(self) -> None:
if self.conventional_title:
output: Dict[str, str] = {
Comment thread
myakove marked this conversation as resolved.
"title": "Conventional Title",
"summary": "",
"text": "",
}
self.set_conventional_title_in_progress()
allowed_names = self.conventional_title.split(",")
title = self.pull_request.title
if any([title.startswith(f"{_name}:") for _name in allowed_names]):
self.set_conventional_title_success(output=output)
else:
output["summary"] = "Failed"
output["text"] = f"Pull request title must starts with allowed title: {': ,'.join(allowed_names)}"

self.set_conventional_title_failure(output=output)
2 changes: 1 addition & 1 deletion webhook_server_container/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Dict


OTHER_MAIN_BRANCH: str = "master"
TOX_STR: str = "tox"
PRE_COMMIT_STR: str = "pre-commit"
Expand All @@ -14,6 +13,7 @@
CAN_BE_MERGED_STR: str = "can-be-merged"
BUILD_CONTAINER_STR: str = "build-container"
PYTHON_MODULE_INSTALL_STR: str = "python-module-install"
CONVENTIONAL_TITLE_STR: str = "conventional-title"
WIP_STR: str = "wip"
LGTM_STR: str = "lgtm"
CHERRY_PICK_LABEL_PREFIX: str = "cherry-pick-"
Expand Down