Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ repos:
rev: 24.10.0
hooks:
- id: black
# FIXME: main.py:109: error: Item "None" of "str | None" has no attribute "split" [union-attr]
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.12.0
# hooks:
# - id: mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.12.0
hooks:
- id: mypy
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:

> [!IMPORTANT]
> `merge-base` is an experimental feature. by default it's disable.
>
>
> To use this feature, you need fetch all history for all branches by setting `fetch-depth: 0` in `actions/checkout`.

### `dry-run`
Expand Down
30 changes: 26 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import subprocess
import re
from github import Github
from github import Github # type: ignore


# Constants for message titles
Expand Down Expand Up @@ -52,7 +52,8 @@ def run_commit_check() -> int:
args = [
arg
for arg, value in zip(
args, [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF, MERGE_BASE]
args,
[MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF, MERGE_BASE],
)
if value == "true"
]
Expand Down Expand Up @@ -104,7 +105,12 @@ def add_pr_comments() -> int:
try:
token = os.getenv("GITHUB_TOKEN")
repo_name = os.getenv("GITHUB_REPOSITORY")
pr_number = os.getenv("GITHUB_REF").split("/")[-2]
pr_number = os.getenv("GITHUB_REF")
if pr_number is not None:
pr_number = pr_number.split("/")[-2]
else:
# Handle the case where GITHUB_REF is not set
raise ValueError("GITHUB_REF environment variable is not set")

# Initialize GitHub client
g = Github(token)
Expand Down Expand Up @@ -157,6 +163,21 @@ def add_pr_comments() -> int:
return 1


def log_error_and_exit(failure_title, result_text, ret_code):
"""
Logs an error message to GitHub Actions and exits with the specified return code.

Args:
failure_title (str): The title of the failure message.
result_text (str): The detailed result text to include in the error message.
ret_code (int): The return code to exit with.
"""
if result_text:
error_message = f"{failure_title}\n```\n{result_text}\n```"
print(f"::error::{error_message}")
sys.exit(ret_code)


def main():
"""Main function to run commit-check, add job summary and post PR comments."""
log_env_vars()
Expand All @@ -169,7 +190,8 @@ def main():
if DRY_RUN == "true":
ret_code = 0

sys.exit(ret_code)
result_text = read_result_file()
log_error_and_exit(FAILURE_TITLE, result_text, ret_code)


if __name__ == "__main__":
Expand Down
Loading