From 03577a2ac77f4aec3ca863e66788d6b20e16b306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=86=A0=E4=BC=B6?= Date: Mon, 21 Aug 2023 20:32:00 +0800 Subject: [PATCH 1/4] feat: add pre-commit to format po files --- .pre-commit-config.yaml | 13 +++++++++++++ pre-commit.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100755 pre-commit.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..d1436fa22f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +# Install the pre-commit hooks below with +# 'pre-commit install' + +# Auto-update the version of the hooks with +# 'pre-commit autoupdate' + +repos: +- repo: local + hooks: + - id: format-with-powrap + name: format-with-powrap + entry: ./pre-commit.sh + language: system \ No newline at end of file diff --git a/pre-commit.sh b/pre-commit.sh new file mode 100755 index 0000000000..a5375b7972 --- /dev/null +++ b/pre-commit.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +STAGEDFILES=($(git diff --cached --name-only -- '*.po' --diff-filter=ACM)) +echo "po files: ${STAGEDFILES[@]}" + +NEED_FORMAT_FILES=0 + +# set the error msg color +RED='\033[0;31m' +NC='\033[0m' # No Color + +if [ ${#STAGEDFILES[@]} -gt 0 ]; then + for FILE in "${STAGEDFILES[@]}"; do + powrap --check --quiet "$FILE" + RETURN_CODE=$? + if [ $RETURN_CODE -eq 1 ]; then + powrap "$FILE" + NEED_FORMAT_FILES=1 + fi + done + + if [ $NEED_FORMAT_FILES -eq 1 ]; then + echo -e "${RED}Failed to commit, please add the formatted po file(s) and commit again.${NC}" + exit 1 + fi +else + echo "There's no staged po files to format." +fi + +exit 0 From 08449739f29bcef2413c44b0a7c5a8102302a4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=86=A0=E4=BC=B6?= Date: Sat, 2 Sep 2023 22:18:16 +0800 Subject: [PATCH 2/4] feat: use powrap native pre-commit hook --- .pre-commit-config.yaml | 8 +++----- pre-commit.sh | 30 ------------------------------ 2 files changed, 3 insertions(+), 35 deletions(-) delete mode 100755 pre-commit.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1436fa22f..183f8b934e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,9 +5,7 @@ # 'pre-commit autoupdate' repos: -- repo: local +- repo: https://github.com/AFPy/powrap + rev: v1.0.1 hooks: - - id: format-with-powrap - name: format-with-powrap - entry: ./pre-commit.sh - language: system \ No newline at end of file + - id: powrap \ No newline at end of file diff --git a/pre-commit.sh b/pre-commit.sh deleted file mode 100755 index a5375b7972..0000000000 --- a/pre-commit.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -STAGEDFILES=($(git diff --cached --name-only -- '*.po' --diff-filter=ACM)) -echo "po files: ${STAGEDFILES[@]}" - -NEED_FORMAT_FILES=0 - -# set the error msg color -RED='\033[0;31m' -NC='\033[0m' # No Color - -if [ ${#STAGEDFILES[@]} -gt 0 ]; then - for FILE in "${STAGEDFILES[@]}"; do - powrap --check --quiet "$FILE" - RETURN_CODE=$? - if [ $RETURN_CODE -eq 1 ]; then - powrap "$FILE" - NEED_FORMAT_FILES=1 - fi - done - - if [ $NEED_FORMAT_FILES -eq 1 ]; then - echo -e "${RED}Failed to commit, please add the formatted po file(s) and commit again.${NC}" - exit 1 - fi -else - echo "There's no staged po files to format." -fi - -exit 0 From 157de66fd68cd59042efb16d4606d59819aa4674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=86=A0=E4=BC=B6?= Date: Mon, 4 Sep 2023 18:09:13 +0800 Subject: [PATCH 3/4] PR reviewer suggestions --- .pre-commit-config.yaml | 5 +++-- README.rst | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 183f8b934e..7cf6db96a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,8 @@ # 'pre-commit autoupdate' repos: -- repo: https://github.com/AFPy/powrap - rev: v1.0.1 +- repo: https://git.afpy.org/AFPy/powrap + # there's no release tag in repo, use the latest commit hash id instead + rev: a34a9fed116d24562fbe4bb8d456ade85f056c36 hooks: - id: powrap \ No newline at end of file diff --git a/README.rst b/README.rst index 5725a94190..d5ba179573 100644 --- a/README.rst +++ b/README.rst @@ -89,6 +89,10 @@ the PSF for inclusion in the documentation. brew install gettext brew link gettext --force +- 安裝 pre-commit 自動在 commit 時檢查 ``.po`` 檔格式。 +.. code-block:: bash + + pre-commit install 在進行任何動作以前,你必須在 GitHub 上 fork 此專案(按下右上角的 ``Fork`` 按鈕),這樣會把整個專案複製一份到你的 GitHub 帳號底下,你可以對這個 fork From cc866b175ce1b2c97feca185e77e2b9599f88c7d Mon Sep 17 00:00:00 2001 From: "Wei-Hsiang (Matt) Wang" Date: Mon, 4 Sep 2023 23:46:33 +0800 Subject: [PATCH 4/4] chore(readme): add installation cmd for pre-commit --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index d5ba179573..e6454d97ff 100644 --- a/README.rst +++ b/README.rst @@ -92,6 +92,7 @@ the PSF for inclusion in the documentation. - 安裝 pre-commit 自動在 commit 時檢查 ``.po`` 檔格式。 .. code-block:: bash + pip install pre-commit pre-commit install 在進行任何動作以前,你必須在 GitHub 上 fork 此專案(按下右上角的 ``Fork``