]> git.mxchange.org Git - friendica.git/commitdiff
Add fix-codestyle.sh
authorPhilipp <admin@philipp.info>
Thu, 2 Jan 2025 00:13:21 +0000 (01:13 +0100)
committerPhilipp <admin@philipp.info>
Thu, 2 Jan 2025 01:01:31 +0000 (02:01 +0100)
.woodpecker/.code_standards_check.yml
bin/dev/fix-codestyle.sh [new file with mode: 0755]

index e6b02c3d7ddd20600286ba74a4fb7ca93cae7bfb..1217ea3f0b0f9a88df5345e93f99ec190be5c6f0 100644 (file)
@@ -39,6 +39,7 @@ steps:
   check:
     image: php:8.3
     commands:
+      - echo "**** Use bin/dev/fix-codestyle.sh in case of errors ****"
       - apt-get update -q
       - DEBIAN_FRONTEND=noninteractive apt-get install -q -y git
       - if [ ! -z "$${CI_COMMIT_PULL_REQUEST}" ]; then
diff --git a/bin/dev/fix-codestyle.sh b/bin/dev/fix-codestyle.sh
new file mode 100755 (executable)
index 0000000..3a66b2e
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+# SPDX-FileCopyrightText: 2010-2025 the Friendica project
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+#
+# this script checks or fixes php-files, based on the php-cs rules
+#
+# You can use the following variables:
+# COMMAND ... the php-cs command to execute (default is "check --diff")
+# TARGET_BRANCH ... set the target branch for the current branch to create a diff between them
+#
+##
+
+COMMAND=${COMMAND:-"check --diff"}
+
+if [ -n "${TARGET_BRANCH}" ]; then
+       CHANGED_FILES="$(git diff --name-only --diff-filter=ACMRTUXB "$(git ls-remote -q | grep refs/heads/"${TARGET_BRANCH}"$ | awk '{print $1}' | xargs git rev-parse )".."$(git rev-parse HEAD)")";
+else
+       CHANGED_FILES="$(git diff --name-only --diff-filter=ACMRTUXB "$(git rev-parse HEAD)")";
+fi
+
+EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}");
+
+./bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer ${COMMAND} --config=.php-cs-fixer.dist.php -v --using-cache=no ${EXTRA_ARGS}