From 1ab8377c687393a441c2a953413925398cbd28fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 01:22:54 +0200 Subject: [PATCH 1/3] chore(deps): bump commit-check from 0.9.1 to 0.9.2 (#88) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e13f4c3..fdcf08c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Install commit-check CLI # For details please see: https://github.com/commit-check/commit-check -commit-check==0.9.1 +commit-check==0.9.2 # Interact with the GitHub API. PyGithub==2.5.0 From 4a509ea5098fa2e24945649d9198e1aece898733 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 1 Dec 2024 21:18:21 +0200 Subject: [PATCH 2/3] docs: update readme.md (#89) --- README.md | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a25d56f..e96d3d3 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,15 @@ A Github Action for checking commit message formatting, branch naming, committer name, email, commit signoff and more. +## Table of Contents + +* [Usage](#usage) +* [Optional Inputs](#optional-inputs) +* [GitHub Action Job Summary](#github-action-job-summary) +* [GitHub Pull Request Comments](#github-pull-request-comments) +* [Badging Your Repository](#badging-your-repository) +* [Versioning](#versioning) + ## Usage Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows/commit-check.yml](.github/workflows/commit-check.yml) @@ -51,33 +60,33 @@ jobs: - **Description**: check commit message formatting convention. - By default the rule follows [conventional commits](https://www.conventionalcommits.org/). -- Default: 'true' +- Default: `true` ### `branch` - **Description**: check git branch naming convention. - By default follow bitbucket [conventional branch](https://conventional-branch.github.io/). -- Default: 'true' +- Default: `true` ### `author-name` - **Description**: check committer author name. -- Default: 'true' +- Default: `true` ### `author-email` - **Description**: check committer author email. -- Default: 'true' +- Default: `true` ### `commit-signoff` - **Description**: check committer commit signature. -- Default: 'true' +- Default: `true` ### `merge-base` - **Description**: check current branch is rebased onto target branch. -- Default: 'false' +- Default: `false` > [!IMPORTANT] > `merge-base` is an experimental feature. by default it's disable. @@ -87,17 +96,17 @@ jobs: ### `dry-run` - **Description**: run checks without failing. exit code is 0 otherwise is 1. -- Default: 'false' +- Default: `false` ### `job-summary` - **Description**: display job summary to the workflow run. -- Default: 'true' +- Default: `true` ### `pr-comments` - **Description**: post results to the pull request comments. -- Default: 'false' +- Default: `false` > [!IMPORTANT] > `pr-comments` is an experimental feature. by default it's disable. To use it you need to set `GITHUB_TOKEN` in the GitHub Action. @@ -106,29 +115,29 @@ jobs: Note: the default rule of above inputs is following [this configuration](https://github.com/commit-check/commit-check/blob/main/.commit-check.yml), if you want to customize just add your `.commit-check.yml` config file under your repository root directory. -## GitHub Action job summary +## GitHub Action Job Summary By default, commit-check-action results are shown on the job summary page of the workflow. -### Success job summary +### Success Job Summary ![Success job summary](https://github.com/commit-check/.github/blob/main/screenshot/success-job-summary.png) -### Failure job summary +### Failure Job Summary ![Failure job summary](https://github.com/commit-check/.github/blob/main/screenshot/failure-job-summary.png) -## GitHub Pull Request comments +## GitHub Pull Request Comments -### Success pull request comment +### Success Pull Request Comment ![Success pull request comment](https://github.com/commit-check/.github/blob/main/screenshot/success-pr-comments.png) -### Failure pull request comment +### Failure Pull Request Comment ![Failure pull request comment](https://github.com/commit-check/.github/blob/main/screenshot/failure-pr-comments.png) -## Badging your repository +## Badging Your Repository You can add a badge to your repository to show your contributors/users that you use commit-check! From cd614c1cb08de72a55a5ec4aaab7f30ca9ba4d69 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 8 Dec 2024 22:23:12 +0200 Subject: [PATCH 3/3] feat: print error log in github action (#91) * feat: print error log in github action * feat: add pre-commit.yml * chore: add type to function --- .github/workflows/pre-commit.yml | 10 ++++++++++ .pre-commit-config.yaml | 9 ++++----- README.md | 2 +- main.py | 32 ++++++++++++++++++++++++++++---- 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..7ee1b19 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,10 @@ +name: Run pre-commit + +on: + push: + pull_request: + types: opened + +jobs: + pre-commit: + uses: commit-check/.github/.github/workflows/pre-commit.yml@main diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b45ec09..571d5ee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/README.md b/README.md index e96d3d3..5bd3919 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/main.py b/main.py index 91d2246..87434ec 100755 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import sys import subprocess import re -from github import Github +from github import Github # type: ignore # Constants for message titles @@ -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" ] @@ -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) @@ -157,6 +163,23 @@ def add_pr_comments() -> int: return 1 +def log_error_and_exit( + failure_title: str, result_text: str | None, ret_code: int +) -> None: + """ + 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() @@ -169,7 +192,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__": pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy