From 8341430bc90ff2bcab802a779449cffe7e1ac1ec Mon Sep 17 00:00:00 2001 From: Linlang <30293408+SunsetWolf@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:22:50 +0800 Subject: [PATCH] fix: fix command injection (#421) * fix command injection * fix command injection * fix command injection * fix command injection * fix command injection * delete check repo * fix command injection * fix command injection * add comments * add comments * add comments * add comments * delete chinese comments * limit title length --- .commitlintrc.js | 21 ++++++++++++++++++++ .github/workflows/pr.yml | 41 ++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 .commitlintrc.js diff --git a/.commitlintrc.js b/.commitlintrc.js new file mode 100644 index 00000000..0a4c1ac2 --- /dev/null +++ b/.commitlintrc.js @@ -0,0 +1,21 @@ +module.exports = { + extends: ["@commitlint/config-conventional"], + rules: { + // Configuration Format: [level, applicability, value] + // level: Error level, usually expressed as a number: + // 0 - disable rule + // 1 - Warning (does not prevent commits) + // 2 - Error (will block the commit) + // applicability: the conditions under which the rule applies, commonly used values: + // “always” - always apply the rule + // “never” - never apply the rule + // value: the specific value of the rule, e.g. a maximum length of 100. + // Refs: https://commitlint.js.org/reference/rules-configuration.html + "header-max-length": [2, "always", 100], + "type-enum": [ + 2, + "always", + ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "Release-As"] + ] + } + }; diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 55038afe..e60c791d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,18 +1,5 @@ -concurrency: - cancel-in-progress: true - group: ${{ github.workflow }}-${{ github.ref }} -jobs: - lint-title: - runs-on: ubuntu-latest - steps: - - name: Check PR Title for Conventional Commit Format - run: | - if ! echo "${{ github.event.pull_request.title }}" | grep -Pq '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|Release-As)(\(\w+\))?!?:\s.*'; then - echo 'The title does not conform to the Conventional Commit.' - echo 'Please refer to "https://www.conventionalcommits.org/"' - exit 1 - fi name: Lint pull request title + on: pull_request: types: @@ -20,3 +7,29 @@ on: - synchronize - reopened - edited + +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + lint-title: + runs-on: ubuntu-latest + steps: + # This step is necessary because the lint title uses the .commitlintrc.js file in the project root directory. + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' + + - name: Install commitlint + run: npm install --save-dev @commitlint/{config-conventional,cli} + + - name: Validate PR Title with commitlint + env: + BODY: ${{ github.event.pull_request.title }} + run: | + echo "$BODY" | npx commitlint --config .commitlintrc.js