From 75dac30cea291f7e17216519f4f628bcb91d10da Mon Sep 17 00:00:00 2001 From: Robin-Manuel Thiel Date: Thu, 18 Apr 2024 11:38:31 +0200 Subject: [PATCH] feat: Add Git Hooks --- src/git-hooks/index.ts | 10 +++++++ .../templates/.github/.workflows/style.yaml | 27 +++++++++++++++++++ src/git-hooks/templates/.gitlint | 3 +++ .../templates/.pre-commit-config.yaml | 26 ++++++++++++++++++ src/git/index.ts | 3 ++- src/project-empty/index.ts | 3 +++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/git-hooks/index.ts create mode 100644 src/git-hooks/templates/.github/.workflows/style.yaml create mode 100644 src/git-hooks/templates/.gitlint create mode 100644 src/git-hooks/templates/.pre-commit-config.yaml diff --git a/src/git-hooks/index.ts b/src/git-hooks/index.ts new file mode 100644 index 0000000..8f498b4 --- /dev/null +++ b/src/git-hooks/index.ts @@ -0,0 +1,10 @@ +import BaseTemplateGenerator from '../BaseTemplateGenerator'; +import { resolveGeneratorInheritance } from '../GeneratorResolver'; + +class GitHooksGenerator extends BaseTemplateGenerator { + constructor(args: any, options: any) { + super(args, options); + } +} + +export default resolveGeneratorInheritance(GitHooksGenerator); diff --git a/src/git-hooks/templates/.github/.workflows/style.yaml b/src/git-hooks/templates/.github/.workflows/style.yaml new file mode 100644 index 0000000..bb0c073 --- /dev/null +++ b/src/git-hooks/templates/.github/.workflows/style.yaml @@ -0,0 +1,27 @@ +name: Check Coding Style +on: + workflow_dispatch: + pull_request: + branches: + - main + +jobs: + check-coding-syle: + name: Check Coding Style + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Check EditorConfig + - name: Install eclint + run: sudo npm install -g eclint + - name: Check EditorConfig style + run: eclint check $(git ls-files) + + # Check Commit Messages + - name: Install pre-commit + run: pip install pre-commit + - name: Check commits + run: pre-commit run --hook-stage manual diff --git a/src/git-hooks/templates/.gitlint b/src/git-hooks/templates/.gitlint new file mode 100644 index 0000000..d6714d0 --- /dev/null +++ b/src/git-hooks/templates/.gitlint @@ -0,0 +1,3 @@ +[general] +ignore = body-is-missing +contrib = contrib-title-conventional-commits diff --git a/src/git-hooks/templates/.pre-commit-config.yaml b/src/git-hooks/templates/.pre-commit-config.yaml new file mode 100644 index 0000000..9f59ccb --- /dev/null +++ b/src/git-hooks/templates/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +default_install_hook_types: +- pre-commit +- pre-push +- commit-msg + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - name: Check, that no large files have been committed + id: check-added-large-files + +- repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: '2.7.1' + hooks: + - name: Check EditorConfig + id: editorconfig-checker + alias: ec + +- repo: https://github.com/jorisroovers/gitlint + rev: "v0.19.1" + hooks: + - name: Lint commit messages + id: gitlint + - id: gitlint-ci + args: ['--commits', 'origin/main..HEAD'] diff --git a/src/git/index.ts b/src/git/index.ts index fc02d68..be53aa3 100644 --- a/src/git/index.ts +++ b/src/git/index.ts @@ -9,7 +9,8 @@ class GitSelectionGenerator extends BaseSelectionGenerator { this.generators = this.generators = [ new GeneratorSelection('Fix .gitignore', 'wemogy:git-fix-gitignore'), new GeneratorSelection('Cleanup git branches', 'wemogy:git-cleanup-branches'), - new GeneratorSelection('Add v prefix to branches and tags', 'wemogy:git-prefix') + new GeneratorSelection('Add v prefix to branches and tags', 'wemogy:git-prefix'), + new GeneratorSelection('Add Git Hooks to repo', 'wemogy:git-hooks') ]; } } diff --git a/src/project-empty/index.ts b/src/project-empty/index.ts index 2e77f59..d9a6a31 100644 --- a/src/project-empty/index.ts +++ b/src/project-empty/index.ts @@ -29,6 +29,9 @@ class EmptyProjectGenerator extends BaseTemplateGenerator { // See this issue for more: https://github.com/yeoman/generator/issues/812 this.fs.copy(this.templatePath('gitignore/gitignore-content'), this.destinationPath('.gitignore')); this.copyTemplateToDestination(this.destinationPath(), undefined, this.templatePath('root')); + + // Add Git Hooks + this.composeWith('wemogy:git-hooks'); } // Where installation are run (npm, bower)