Skip to content

Commit

Permalink
CI: check PR title (bloomberg#429)
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeny Malygin <[email protected]>
  • Loading branch information
678098 authored and alexander-e1off committed Oct 24, 2024
1 parent a0d78ec commit 35599b8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ext/check_pr_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Script for checking PR title.
The script expects PR_TITLE environment variable to be set as an input parameter.
Usage:
export PR_TITLE="<...>"
python3 check_pr_title.py
"""
import os


def check_pr_title():
title = os.environ.get("PR_TITLE")
if title is None or len(title) == 0:
raise RuntimeError(
"This script expects a non-empty environment variable PR_TITLE set"
)
title = title.lower()
valid_prefixes = [
"fix",
"feat",
"perf",
"ci",
"build",
"revert",
"ut",
"it",
"doc",
"refactor",
"misc",
"test",
]
if not any(title.startswith(prefix.lower()) for prefix in valid_prefixes):
raise RuntimeError(
'PR title "{}" doesn\'t start with a valid prefix, allowed prefixes: {}'.format(
title, " ".join(valid_prefixes)
)
)


if __name__ == "__main__":
check_pr_title()
25 changes: 25 additions & 0 deletions .github/workflows/pr-title-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PR title check

on:
pull_request:
types:
- "opened"
- "reopened"
- "synchronize"
- "labeled"
- "unlabeled"
- "edited"

jobs:
pr_title_check:
runs-on: ubuntu-latest
name: PR Title Check
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: pr title check
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
python3 ${{ github.workspace }}/.github/workflows/ext/check_pr_title.py

0 comments on commit 35599b8

Please sign in to comment.