From 916617da6596b853a3731f3a0580f1eba035baff Mon Sep 17 00:00:00 2001 From: Laurent Sorber Date: Sun, 15 Jun 2025 18:00:14 +0200 Subject: [PATCH 1/4] feat: check if PR title conforms to Conventional Commits --- .github/workflows/pr.yml | 19 +++++++++++++++++++ hooks/post_gen_project.py | 3 +++ ...entional_commits %}pr.yml{% endif %}.jinja | 19 +++++++++++++++++++ .../.github/workflows/pr.yml | 19 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 .github/workflows/pr.yml create mode 100644 template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja create mode 100644 {{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..d91ed5ae --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,19 @@ +name: PR + +on: + pull_request: + types: [edited, opened, reopened, synchronize] + +jobs: + title: + runs-on: ubuntu-latest + + name: Check PR title + + steps: + - name: Set up uv + uses: astral-sh/setup-uv@v6 + + - name: Check PR title + run: | + uvx --from=commitizen cz check --message "${{ github.event.pull_request.title }}" diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 91428943..7523c3b5 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -4,6 +4,7 @@ # Read Cookiecutter configuration. project_name = "{{ cookiecutter.__project_name_snake_case }}" development_environment = "{{ cookiecutter.development_environment }}" +with_conventional_commits = int("{{ cookiecutter.with_conventional_commits }}") with_fastapi_api = int("{{ cookiecutter.with_fastapi_api }}") with_typer_cli = int("{{ cookiecutter.with_typer_cli }}") continuous_integration = "{{ cookiecutter.continuous_integration }}" @@ -36,3 +37,5 @@ os.remove(".github/workflows/publish.yml") else: os.remove(".github/workflows/deploy.yml") + if not with_conventional_commits: + os.remove(".github/workflows/pr.yml") diff --git a/template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja b/template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja new file mode 100644 index 00000000..d91ed5ae --- /dev/null +++ b/template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja @@ -0,0 +1,19 @@ +name: PR + +on: + pull_request: + types: [edited, opened, reopened, synchronize] + +jobs: + title: + runs-on: ubuntu-latest + + name: Check PR title + + steps: + - name: Set up uv + uses: astral-sh/setup-uv@v6 + + - name: Check PR title + run: | + uvx --from=commitizen cz check --message "${{ github.event.pull_request.title }}" diff --git a/{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml b/{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml new file mode 100644 index 00000000..d91ed5ae --- /dev/null +++ b/{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml @@ -0,0 +1,19 @@ +name: PR + +on: + pull_request: + types: [edited, opened, reopened, synchronize] + +jobs: + title: + runs-on: ubuntu-latest + + name: Check PR title + + steps: + - name: Set up uv + uses: astral-sh/setup-uv@v6 + + - name: Check PR title + run: | + uvx --from=commitizen cz check --message "${{ github.event.pull_request.title }}" From c18177972c2a058604e5ac38b92d3e6b2290e463 Mon Sep 17 00:00:00 2001 From: Laurent Sorber Date: Sun, 15 Jun 2025 18:08:50 +0200 Subject: [PATCH 2/4] fix: escape braces in jinja template --- .../{% if with_conventional_commits %}pr.yml{% endif %}.jinja | 2 +- .../.github/workflows/pr.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja b/template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja index d91ed5ae..119fe789 100644 --- a/template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja +++ b/template/{% if ci == 'github' %}.github{% endif %}/workflows/{% if with_conventional_commits %}pr.yml{% endif %}.jinja @@ -16,4 +16,4 @@ jobs: - name: Check PR title run: | - uvx --from=commitizen cz check --message "${{ github.event.pull_request.title }}" + uvx --from=commitizen cz check --message "{% raw %}${{ github.event.pull_request.title }}{% endraw %}" diff --git a/{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml b/{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml index d91ed5ae..119fe789 100644 --- a/{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml +++ b/{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/pr.yml @@ -16,4 +16,4 @@ jobs: - name: Check PR title run: | - uvx --from=commitizen cz check --message "${{ github.event.pull_request.title }}" + uvx --from=commitizen cz check --message "{% raw %}${{ github.event.pull_request.title }}{% endraw %}" From c57a21b11ea82dc278cc262643efdf3dccad9e03 Mon Sep 17 00:00:00 2001 From: Laurent Sorber Date: Sun, 15 Jun 2025 18:53:23 +0200 Subject: [PATCH 3/4] feat: add .github/settings.yml --- .github/settings.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/settings.yml diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 00000000..187a1000 --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,19 @@ +repository: + default_branch: main + allow_merge_commit: false + allow_rebase_merge: false + allow_squash_merge: true + squash_merge_commit_title: PR_TITLE + squash_merge_commit_message: PR_BODY + delete_branch_on_merge: true + +branch_protection: + main: + required_pull_request_reviews: + required_approving_review_count: 1 + required_status_checks: + contexts: + - 'PR / Check PR title' + required_conversation_resolution: true + required_signatures: true + required_linear_history: true From 8ce77b1714f259a9cee4ad9595b62f313bf0cb86 Mon Sep 17 00:00:00 2001 From: Laurent Sorber Date: Sun, 15 Jun 2025 19:14:55 +0200 Subject: [PATCH 4/4] fix: remove .github/settings.yml --- .github/settings.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .github/settings.yml diff --git a/.github/settings.yml b/.github/settings.yml deleted file mode 100644 index 187a1000..00000000 --- a/.github/settings.yml +++ /dev/null @@ -1,19 +0,0 @@ -repository: - default_branch: main - allow_merge_commit: false - allow_rebase_merge: false - allow_squash_merge: true - squash_merge_commit_title: PR_TITLE - squash_merge_commit_message: PR_BODY - delete_branch_on_merge: true - -branch_protection: - main: - required_pull_request_reviews: - required_approving_review_count: 1 - required_status_checks: - contexts: - - 'PR / Check PR title' - required_conversation_resolution: true - required_signatures: true - required_linear_history: true