fix(ci): infer branch name if only commit given

After migration of github, we only use the commit ID for the
pre-ci-check script. This is problematic, because it checks for merges,
excluding the integration branch (expected to have merges), based on the
branch _name_.

In this commit, if a full SHA is detected as the branch "name", use "git
branch --points-at" to get a branch name, then use that to exclude
integration branches (or not).  If no branch name is found, the branch
name "" is used, which will trigger the normal merge check (because ""
does not match the integration branch name).

Signed-off-by: Robert Schmidt <robert.schmidt@openairinterface.org>
This commit is contained in:
Robert Schmidt
2026-06-10 12:06:36 +02:00
parent 33e09d7e3e
commit 0a9d817d9c

View File

@@ -55,8 +55,17 @@ done
# ----------------------------
# Merged commits
# ----------------------------
mergeCommits=$(git rev-list --merges --abbrev-commit "$TARGET_BRANCH".."$SOURCE_BRANCH")
if [[ ! "$SOURCE_BRANCH" =~ ^(origin/)?integration_[0-9]{4}_w[0-9]{2}$ ]]; then
if [[ "$SOURCE_BRANCH" =~ ^[0-9a-f]{40}$ ]]; then
# note: if no branch could be found, it will result in "" and git rev-list
# will use the commit ID. Exclude "HEAD detached at", then use first branch
# name.
BRANCH_NAME=$(git branch -a --points-at $SOURCE_BRANCH --format='%(refname:short)' | grep -v detached | head -n1)
echo "SHA recognized in $SOURCE_BRANCH, using \"$BRANCH_NAME\" as branch name"
else
BRANCH_NAME="$SOURCE_BRANCH"
fi
if [[ ! "$BRANCH_NAME" =~ ^(origin/)?integration_[0-9]{4}_w[0-9]{2}$ ]]; then
mergeCommits=$(git rev-list --merges --abbrev-commit "$TARGET_BRANCH".."$SOURCE_BRANCH")
if [[ -n "$mergeCommits" ]]; then
message="Error: Following merge commits are found in the source branch history. Please rebase your branch.\n\n"
message+="$(echo "$mergeCommits" | paste -sd ',' | sed 's/,/, /g')\n"