Skip to content

Commit d863986

Browse files
feat(ref: no-ref): pre-commit msg
* feat(ref: no-ref): pre-commit msg * feat(ref: no-ref): pre-commit msg
1 parent a57d8b1 commit d863986

File tree

18 files changed

+316
-133
lines changed

18 files changed

+316
-133
lines changed

.github/hooks/commit-msg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
commit_msg=$(cat .git/COMMIT_EDITMSG)
6+
echo "$commit_msg" | dart run commitlint_cli --edit "$1"

.github/hooks/pre-commit

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# To avoid running this pre-commit simply write your commit like:
2+
# git commit -m "test commit" --no-verify
3+
# with the --no-verify flag being the operative addition
4+
5+
printf "\e[33;1m%s\e[0m\n" 'Pre-Commit'
6+
7+
# Undo the stash of the files
8+
pop_stash_files () {
9+
if [ -n "$hasChanges" ]; then
10+
printf "\e[33;1m%s\e[0m\n" '=== Applying git stash changes ==='
11+
git stash pop
12+
fi
13+
}
14+
15+
# Stash unstaged files
16+
hasChanges=$(git diff)
17+
if [ -n "$hasChanges" ]; then
18+
printf "\e[33;1m%s\e[0m\n" 'Stashing unstaged changes'
19+
git stash push --keep-index
20+
fi
21+
22+
# Flutter import sorter
23+
printf "\e[33;1m%s\e[0m\n" '=== Running Dart import sorter ==='
24+
dart run import_sorter:main
25+
hasNewFilesSorted=$(git diff)
26+
if [ -n "$hasNewFilesSorted" ]; then
27+
git add .
28+
printf "\e[33;1m%s\e[0m\n" 'Sorted imports added to git stage'
29+
fi
30+
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter import sorter'
31+
printf '%s\n' "${avar}"
32+
33+
# Dart fix
34+
printf "\e[33;1m%s\e[0m\n" '=== Running Dart fix ==='
35+
dart fix --apply
36+
hasNewFilesFixed=$(git diff)
37+
if [ -n "$hasNewFilesFixed" ]; then
38+
git add .
39+
printf "\e[33;1m%s\e[0m\n" 'Dart fix files added to git stage'
40+
fi
41+
printf "\e[33;1m%s\e[0m\n" 'Finished running Dart fix'
42+
printf '%s\n' "${avar}"
43+
44+
# Dart formatter
45+
printf "\e[33;1m%s\e[0m\n" '=== Running Dart formatter ==='
46+
dart format .
47+
48+
hasNewFilesFormatted=$(git diff)
49+
if [ -n "$hasNewFilesFormatted" ]; then
50+
git add .
51+
printf "\e[33;1m%s\e[0m\n" 'Formatted files added to git stage'
52+
fi
53+
printf "\e[33;1m%s\e[0m\n" 'Finished running Dart Formatter'
54+
printf '%s\n' "${avar}"
55+
56+
# Flutter Analyzer
57+
printf "\e[33;1m%s\e[0m\n" '=== Running Flutter analyzer ==='
58+
flutter analyze
59+
60+
if [ $? -ne 0 ]; then
61+
printf "\e[31;1m%s\e[0m\n" '=== Flutter analyzer error ==='
62+
pop_stash_files
63+
exit 1
64+
fi
65+
66+
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter analyzer'
67+
printf '%s\n' "${avar}"
68+
69+
70+
# Unit tests
71+
# printf "\e[33;1m%s\e[0m\n" '=== Running Unit Tests ==='
72+
# flutter test -r expanded
73+
74+
# if [ $? -ne 0 ]; then
75+
# printf "\e[31;1m%s\e[0m\n" '=== Unit tests error ==='
76+
# pop_stash_files
77+
# exit 1
78+
# fi
79+
80+
# printf "\e[33;1m%s\e[0m\n" 'Finished running Unit Tests'
81+
# printf '%s\n' "${avar}"
82+
83+
pop_stash_files
84+
85+
printf "\e[33;1m%s\e[0m\n" 'Finished all tasks'

.github/scripts/setup_hooks.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Define the directory containing sample hooks
4+
SAMPLE_HOOKS_DIR=".github/hooks"
5+
6+
# Define the target directory for Git hooks
7+
GIT_HOOKS_DIR=".git/hooks"
8+
9+
# Function to copy or replace hooks
10+
copy_or_replace_hooks() {
11+
for hook in "$SAMPLE_HOOKS_DIR"/*; do
12+
hook_name=$(basename "$hook")
13+
target_hook="$GIT_HOOKS_DIR/"
14+
if [ -f "$target_hook" ]; then
15+
echo "Replacing existing hook: $hook_name"
16+
else
17+
echo "Copying new hook: $hook_name"
18+
fi
19+
if [ -L "$target_hook$hook_name" ]; then
20+
rm -r $target_hook$hook_name
21+
fi
22+
23+
cp $hook $target_hook
24+
chmod +x $target_hook$hook_name # Ensure executable permission is set
25+
done
26+
27+
git config --unset core.hooksPath
28+
}
29+
30+
# Main function
31+
main() {
32+
# Check if .git/hooks directory exists
33+
if [ ! -d "$GIT_HOOKS_DIR" ]; then
34+
echo "Error: .git/hooks directory not found. Are you in a Git repository?"
35+
exit 1
36+
fi
37+
38+
# Copy or replace hooks
39+
copy_or_replace_hooks
40+
41+
echo "Git hooks setup complete."
42+
}
43+
44+
# Run the main function
45+
main

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ A few resources to get you started if this is your first Flutter project:
1414
For help getting started with Flutter development, view the
1515
[online documentation](https://docs.flutter.dev/), which offers tutorials,
1616
samples, guidance on mobile development, and a full API reference.
17+
18+
19+
# Getting Started
20+
21+
To run the project, simply execute the following command:
22+
23+
flutter run
24+
25+
# Setup hooks:
26+
27+
chmod +x .github/scripts/* && .github/scripts/setup_hooks.sh

commitlint.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include: package:commitlint_cli/commitlint.yaml
2+
3+
rules:
4+
scope-empty:
5+
- 2
6+
- never
7+
scope-enum:
8+
- 0
9+
- never

lib/common/button/button.widget.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import 'package:flutter/material.dart';
22

33
class ButtonWidget extends StatelessWidget {
44
const ButtonWidget(
5-
{
6-
required this.title,
7-
required this.onTap,
8-
this.isActive = false,
9-
super.key});
5+
{required this.title,
6+
required this.onTap,
7+
this.isActive = false,
8+
super.key});
109

1110
final String title;
1211
final bool isActive;
@@ -21,17 +20,15 @@ class ButtonWidget extends StatelessWidget {
2120
padding: const EdgeInsets.symmetric(horizontal: 8),
2221
decoration: BoxDecoration(
2322
border: Border.all(
24-
color: isActive ? Colors.red : Colors.transparent,
25-
width: 2,
23+
color: isActive ? Colors.red : Colors.transparent,
24+
width: 2,
2625
),
2726
borderRadius: BorderRadius.circular(14)),
2827
child: Center(
29-
child: Text(title,
30-
style: const TextStyle(
31-
fontSize: 14,
32-
),
33-
)
34-
)
35-
)
36-
);
37-
}
28+
child: Text(
29+
title,
30+
style: const TextStyle(
31+
fontSize: 14,
32+
),
33+
))));
34+
}

lib/common/input/input.widget.dart

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,34 @@ class InputWidget extends StatelessWidget {
88
this.hintText = '',
99
super.key,
1010
});
11-
11+
1212
final TextEditingController textController;
1313
final FocusNode focusNode;
1414
final String hintText;
1515
final Function(String) onSubmitted;
16-
1716

1817
@override
1918
Widget build(BuildContext context) => TextField(
20-
controller: textController,
21-
focusNode: focusNode,
22-
decoration: InputDecoration(
23-
hintText: hintText,
24-
hintStyle: const TextStyle(
25-
fontSize: 18,
26-
fontStyle: FontStyle.italic,
27-
color: Colors.grey,
28-
),
29-
border: InputBorder.none,
30-
contentPadding:
31-
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
32-
focusedBorder: const OutlineInputBorder(
33-
borderSide: BorderSide(color: Colors.red, width: 2),
19+
controller: textController,
20+
focusNode: focusNode,
21+
decoration: InputDecoration(
22+
hintText: hintText,
23+
hintStyle: const TextStyle(
24+
fontSize: 18,
25+
fontStyle: FontStyle.italic,
26+
color: Colors.grey,
27+
),
28+
border: InputBorder.none,
29+
contentPadding:
30+
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
31+
focusedBorder: const OutlineInputBorder(
32+
borderSide: BorderSide(color: Colors.red, width: 2),
33+
),
3434
),
35-
),
36-
style: const TextStyle(fontSize: 18),
37-
onSubmitted: onSubmitted,
38-
onTapOutside: (PointerDownEvent event) {
39-
focusNode.unfocus();
40-
},
41-
);
35+
style: const TextStyle(fontSize: 18),
36+
onSubmitted: onSubmitted,
37+
onTapOutside: (PointerDownEvent event) {
38+
focusNode.unfocus();
39+
},
40+
);
4241
}

lib/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MyApp extends StatelessWidget {
1212

1313
@override
1414
Widget build(BuildContext context) => GetMaterialApp(
15-
initialBinding: HomeBinding(),
16-
home: const HomeScreen(),
17-
);
15+
initialBinding: HomeBinding(),
16+
home: const HomeScreen(),
17+
);
1818
}

lib/screens/home/home.binding.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class HomeBinding extends Bindings {
88
@override
99
Future<void> dependencies() async {
1010
Get
11-
..lazyPut(TodoService.new)
12-
..lazyPut(() => AddTaskController(Get.find()))
13-
..lazyPut(() => FilterPanelController(Get.find()))
14-
..lazyPut(() => TaskListItemController(Get.find(), Get.find()));
11+
..lazyPut(TodoService.new)
12+
..lazyPut(() => AddTaskController(Get.find()))
13+
..lazyPut(() => FilterPanelController(Get.find()))
14+
..lazyPut(() => TaskListItemController(Get.find(), Get.find()));
1515
}
1616
}

lib/screens/home/title/title.widget.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ class TitleWidget extends StatelessWidget {
55

66
@override
77
Widget build(BuildContext context) => const Padding(
8-
padding: EdgeInsets.only(top: 50, bottom: 20),
9-
child: Text(
10-
'todos',
11-
style: TextStyle(
12-
fontSize: 80,
13-
fontWeight: FontWeight.w300,
14-
color: Colors.red,
8+
padding: EdgeInsets.only(top: 50, bottom: 20),
9+
child: Text(
10+
'todos',
11+
style: TextStyle(
12+
fontSize: 80,
13+
fontWeight: FontWeight.w300,
14+
color: Colors.red,
15+
),
1516
),
16-
),
17-
);
18-
}
17+
);
18+
}

0 commit comments

Comments
 (0)