6 # The following approach was shamelessly copied from ci-fairy
7 # https://gitlab.freedesktop.org/freedesktop/ci-templates/-/blob/master/tools/ci_fairy.py
8 # CHANGES: Swap CI for CI_MERGE_REQUEST_ID, add CI_COMMIT_BRANCH.
9 if [[ ${CI_MERGE_REQUEST_ID-} ]]; then
10 upstream
="${FDO_UPSTREAM_REPO-}"
11 if [[ ! "$upstream" ]]; then
12 echo "$FDO_UPSTREAM_REPO not set, using local branches to compare"
13 upstream
="${CI_PROJECT_PATH}"
15 host="${CI_SERVER_HOST}"
16 token
="${CI_JOB_TOKEN}"
17 url
="https://gitlab-ci-token:$token@$host/$upstream"
20 if ! git remote |
grep -qw "$remote"; then
21 git remote add
"$remote" "$url"
25 # There are two types of MRs apparently
26 if [[ ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-} ]]; then
27 echo "Using CI_MERGE_REQUEST_SOURCE_BRANCH_SHA"
28 commit
=$CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
29 elif [[ ${CI_MERGE_REQUEST_DIFF_BASE_SHA-} ]]; then
30 echo "Using CI_MERGE_REQUEST_DIFF_BASE_SHA"
31 commit
=$CI_MERGE_REQUEST_DIFF_BASE_SHA
33 echo "Looking like a MR, but CI variables are not set."
34 echo "Using the default branch \"$CI_DEFAULT_BRANCH\"."
35 commit
="$remote/$CI_DEFAULT_BRANCH"
37 elif [[ ${CI_COMMIT_BRANCH-} ]]; then
38 echo "Using CI_COMMIT_BEFORE_SHA"
39 commit
=$CI_COMMIT_BEFORE_SHA
44 # End of the shameless copy
46 # Older versions of clang-format like 6 and 7 print an annoying message.
47 # "no modified files to format". Newer ones like 12 (earlier?), do not.
48 formatting_changes
=$
(git-clang-format
--commit "$commit" -q --diff |
grep -v "no modified files to format" || true
)
49 [[ "$formatting_changes" ]] ||
exit 0
51 echo "ERROR: Formatting issues detected"
53 echo "Update the codebase as indicated or disable clang-format locally."
55 echo "Formatting suggestion:"
57 echo -e "------------\n$formatting_changes\n------------"