Module: kamailio
Branch: master
Commit: d062d9a1d5dc1a73c51994ece0703fa759e9afbc
URL: 
https://github.com/kamailio/kamailio/commit/d062d9a1d5dc1a73c51994ece0703fa759e9afbc

Author: Victor Seva <linuxman...@torreviejawireless.org>
Committer: Victor Seva <linuxman...@torreviejawireless.org>
Date: 2025-03-25T16:27:29+01:00

github: check-commit for PR

* minimal checks for prefix in commit subject

---

Added: .github/scripts/check-commit.sh
Modified: .github/workflows/pull_request.yml

---

Diff:  
https://github.com/kamailio/kamailio/commit/d062d9a1d5dc1a73c51994ece0703fa759e9afbc.diff
Patch: 
https://github.com/kamailio/kamailio/commit/d062d9a1d5dc1a73c51994ece0703fa759e9afbc.patch

---

diff --git a/.github/scripts/check-commit.sh b/.github/scripts/check-commit.sh
new file mode 100755
index 00000000000..144d6a4395e
--- /dev/null
+++ b/.github/scripts/check-commit.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+COMMIT_MESSAGE_SUBJECT_FORMAT="%s"
+
+set -eu
+
+res=0
+
+die() { echo "$@" >&2; exit 1; }
+fail() { echo "*** $@ ***" >&2; res=1; }
+
+git_log_format() {
+  local pattern="$1"
+  local reference="$2"
+  git log -1 --pretty=format:"$pattern" "$reference"
+}
+
+check_subject() {
+  local commit="$1"
+  local subject="$2"
+
+  # get the prefix
+  if ! [[ "${subject}" =~ ^([^:]+):.*$ ]] ; then
+    fail "[${commit}] prefix not detected:'${subject}'"
+    return
+  fi
+  prefix="${BASH_REMATCH[1]}"
+  if [ -z "${prefix}" ] ; then
+    fail "[${commit}] commit subject has no prefix:'${subject}'"
+    return
+  fi
+
+  # core or lib
+  if [ -d "src/${prefix}" ] ; then
+    echo "[${commit}] prefix is core or lib, OK[${prefix}]"
+    return
+  fi
+
+  # prefix is a module
+  if [ -d "src/modules/${prefix}" ] ; then
+    echo "[${commit}] prefix is module, OK[${prefix}]"
+    return
+  fi
+
+  # utils?
+  if [ -d "${prefix}" ] ; then
+    echo "[${commit}] prefix is a dir in the repo, OK[${prefix}]"
+    return
+  fi
+
+  # github configs
+  if [[ "${prefix}" =~ ^github$ ]] ; then
+    echo "[${commit}] prefix is github config, OK[${prefix}]"
+    return
+  fi
+
+  fail "[${commit}] unknown prefix:'${prefix}'"
+}
+
+target="${GITHUB_BASE_REF:-master}"
+if [ "${CI:-}" ]; then
+    git rev-parse -q --no-revs --verify "origin/${target}" || \
+        git rev-parse -q --no-revs --verify "${target}" || \
+        git fetch origin --depth=1 "${target}"
+    git rev-parse -q --no-revs --verify "origin/${target}" || \
+        git rev-parse -q --no-revs --verify "${target}" || \
+        git fetch origin --depth=1 tag "${target}"
+    # Ensure that the target revision has some history
+    target_sha=$(git rev-parse -q --verify "origin/${target}" || git rev-parse 
-q --verify "${target}")
+    git fetch -q "--depth=${FETCH_DEPTH:-50}" origin "+${target_sha}"
+else
+    target_sha=$(git rev-parse -q --verify "${target}") || die "fatal: 
couldn't find ref ${target}"
+fi
+
+ref=${ref:-HEAD}
+src_sha=$(git rev-parse -q --verify "${ref}") || die "fatal: couldn't find ref 
${ref}"
+echo "Checking $(git rev-list --count "${src_sha}" "^${target_sha}") commits 
since revision ${target_sha}"
+for commit in $(git rev-list --reverse "${src_sha}" "^${target_sha}"); do
+  COMMIT_MESSAGE_SUBJECT=$(git_log_format "${COMMIT_MESSAGE_SUBJECT_FORMAT}" 
"${commit}")
+  check_subject "${commit}" "${COMMIT_MESSAGE_SUBJECT}"
+done
+
+echo "Result: ${res}"
+exit $res
diff --git a/.github/workflows/pull_request.yml 
b/.github/workflows/pull_request.yml
index 351b0ba9542..dcd44cd72c8 100644
--- a/.github/workflows/pull_request.yml
+++ b/.github/workflows/pull_request.yml
@@ -12,10 +12,24 @@ jobs:
     permissions:
       contents: read # to fetch code (actions/checkout)
     steps:
-      - uses: actions/checkout@v4
+      - name: Check out the repository to the runner
+        uses: actions/checkout@v4
       - uses: wolletd/clang-format-checker@v1.12
         with:
           target-ref: master
+  check-commit:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read # to fetch code (actions/checkout)
+    steps:
+      - name: Check out the repository to the runner
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+      - name: Run scripts/check-commit.sh
+        run: ./.github/scripts/check-commit.sh
+        env:
+          ref: ${{ github.event.pull_request.head.sha }}
   build:
     runs-on: ubuntu-latest
     permissions:
@@ -38,7 +52,8 @@ jobs:
           - distribution: bookworm
             compilier: clang
     steps:
-      - uses: actions/checkout@v4
+      - name: Check out the repository to the runner
+        uses: actions/checkout@v4
       - uses: ammaraskar/gcc-problem-matcher@0.3.0
       - name: build
         run: |

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to