Skip to content

Commit

Permalink
feat: Add Git Hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmanuelthiel committed Apr 18, 2024
1 parent c679cfb commit 75dac30
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/git-hooks/index.ts
Original file line number Diff line number Diff line change
@@ -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);
27 changes: 27 additions & 0 deletions src/git-hooks/templates/.github/.workflows/style.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/git-hooks/templates/.gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[general]
ignore = body-is-missing
contrib = contrib-title-conventional-commits
26 changes: 26 additions & 0 deletions src/git-hooks/templates/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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']
3 changes: 2 additions & 1 deletion src/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
];
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/project-empty/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 75dac30

Please sign in to comment.