From 4a3929ef92766f679149cec616e13f369eaa7327 Mon Sep 17 00:00:00 2001 From: Sakib Ahmed Date: Sun, 28 Jul 2024 14:08:27 +0600 Subject: [PATCH 1/3] various changes (#208) * test vue * new error added * doc indiv new page added * major update on doc page * husky removed * some minor issue fix * code clean up + code optimize for color * new doc added * new post added + folder rename + minor changes --- docs/git_hooks_automating_your_workflow.md | 123 ++++++++++++++++++ docs/index.json | 11 ++ .../mastering_git_branching_strategies.md | 4 +- .../pull_request_tutorial_for_beginners.md | 4 +- posts/index.json | 4 - src/pages/Doc/index.jsx | 5 +- src/pages/Doc/single doc/index.jsx | 2 +- 7 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 docs/git_hooks_automating_your_workflow.md create mode 100644 docs/index.json rename posts/_a_guide_for_effective_collaboration.md => docs/mastering_git_branching_strategies.md (97%) rename {posts => docs}/pull_request_tutorial_for_beginners.md (98%) delete mode 100644 posts/index.json diff --git a/docs/git_hooks_automating_your_workflow.md b/docs/git_hooks_automating_your_workflow.md new file mode 100644 index 0000000..6dd73df --- /dev/null +++ b/docs/git_hooks_automating_your_workflow.md @@ -0,0 +1,123 @@ +# git-hooks-automating-your-workflow + +Git hooks are powerful scripts that can automate various aspects of your development workflow. They allow you to execute custom scripts before or after important Git events, such as committing, pushing, or merging. This post will introduce you to Git hooks and show you how to leverage them effectively. + +## What Are Git Hooks? + +Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. They reside in the `.git/hooks` directory of every Git repository and can be written in any scripting language. + +## Types of Git Hooks + +Git hooks can be categorized into client-side and server-side hooks: + +### Client-side Hooks + +1. **pre-commit**: Runs before a commit is created +2. **prepare-commit-msg**: Runs before the commit message editor is fired up +3. **commit-msg**: Runs after the commit message is saved +4. **post-commit**: Runs after the commit is created +5. **pre-push**: Runs before a push is executed + +### Server-side Hooks + +1. **pre-receive**: Runs when the server receives a push +2. **update**: Similar to pre-receive, but runs once for each branch +3. **post-receive**: Runs after a push has been accepted + +## Setting Up a Git Hook + +1. Navigate to your repository's `.git/hooks` directory. +2. Create a new file with the name of the hook you want to implement (e.g., `pre-commit`). +3. Remove the `.sample` extension if it exists. +4. Make the file executable: + + ```bash + chmod +x .git/hooks/pre-commit + ``` + +5. Edit the file with your desired script. + +## Example: A Simple pre-commit Hook + +Here's a simple pre-commit hook that checks for debugging statements: + +```bash +#!/bin/sh + +if git diff --cached | grep -E '(console.log|debugger)' > /dev/null; then + echo "Error: Debugging statements detected. Please remove them before committing." + exit 1 +fi +``` + +This script checks for `console.log` or `debugger` statements in your staged changes and prevents the commit if any are found. + +## Best Practices for Using Git Hooks + +1. **Keep hooks simple**: Complex hooks can slow down Git operations. +2. **Use hooks consistently**: Ensure all team members use the same hooks. +3. **Version control your hooks**: Store hooks in your repository and symlink them. +4. **Make hooks configurable**: Allow developers to bypass hooks when necessary. +5. **Document your hooks**: Ensure team members understand what each hook does. + +## Sharing Hooks with Your Team + +To share hooks with your team: + +1. Create a `hooks` directory in your repository. +2. Add your hook scripts to this directory. +3. Create a setup script that symlinks these hooks to `.git/hooks`. +4. Add instructions for running the setup script to your README. + +## Advanced Git Hook Usage + +### Linting + +Use a pre-commit hook to run linters: + +```bash +#!/bin/sh + +if ! npm run lint; then + echo "Linting failed. Please fix errors before committing." + exit 1 +fi +``` + +### Automatic Formatting + +Use a pre-commit hook to automatically format code: + +```bash +#!/bin/sh + +if ! npm run format; then + echo "Formatting failed. Please run formatting manually and try again." + exit 1 +fi +``` + +### Preventing Commits to Specific Branches + +Use a pre-commit hook to prevent direct commits to protected branches: + +```bash +#!/bin/sh + +branch="$(git rev-parse --abbrev-ref HEAD)" + +if [ "$branch" = "main" ]; then + echo "You can't commit directly to main branch" + exit 1 +fi +``` + +## Conclusion + +Git hooks are a powerful tool for automating and enforcing development workflows. By implementing appropriate hooks, you can improve code quality, enforce coding standards, and streamline your development process. + +Remember, while hooks are powerful, they should be used judiciously. Overly restrictive hooks can hinder productivity, so strike a balance between automation and flexibility. + +Happy coding, and may your Git hooks serve you well! + +> Written by **Sakib Ahmed** | [GitHub](https://github.com/devvsakib) \ No newline at end of file diff --git a/docs/index.json b/docs/index.json new file mode 100644 index 0000000..dc30852 --- /dev/null +++ b/docs/index.json @@ -0,0 +1,11 @@ +[ + { + "title": "pull_request_tutorial_for_beginners" + }, + { + "title": "mastering_git_branching_strategies" + }, + { + "title": "git_hooks_automating_your_workflow" + } +] \ No newline at end of file diff --git a/posts/_a_guide_for_effective_collaboration.md b/docs/mastering_git_branching_strategies.md similarity index 97% rename from posts/_a_guide_for_effective_collaboration.md rename to docs/mastering_git_branching_strategies.md index 0b31ace..f59fb83 100644 --- a/posts/_a_guide_for_effective_collaboration.md +++ b/docs/mastering_git_branching_strategies.md @@ -92,4 +92,6 @@ A well-implemented Git branching strategy can significantly improve your team's Remember, the best strategy is one that your team can follow effectively. Start with a basic approach and evolve it as your project and team grow. -Happy branching! \ No newline at end of file +Happy branching! + +> Written by **Sakib Ahmed** | [GitHub](https://github.com/devvsakib) \ No newline at end of file diff --git a/posts/pull_request_tutorial_for_beginners.md b/docs/pull_request_tutorial_for_beginners.md similarity index 98% rename from posts/pull_request_tutorial_for_beginners.md rename to docs/pull_request_tutorial_for_beginners.md index 579a08e..5d9404e 100644 --- a/posts/pull_request_tutorial_for_beginners.md +++ b/docs/pull_request_tutorial_for_beginners.md @@ -119,4 +119,6 @@ You may also delete the branch from your fork on GitHub. Congratulations! You've successfully created and merged a pull request. This process helps maintain code quality and encourages collaboration among developers. -This tutorial covers the basics of creating a pull request and includes best practices to help beginners understand the process. \ No newline at end of file +This tutorial covers the basics of creating a pull request and includes best practices to help beginners understand the process. + +> Written by **Sakib Ahmed** | [GitHub](https://github.com/devvsakib) \ No newline at end of file diff --git a/posts/index.json b/posts/index.json deleted file mode 100644 index 1897909..0000000 --- a/posts/index.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "pull_request_tutorial_for_beginners", - "mastering_git_branching_strategies:_a_guide_for_effective_collaboration" -] \ No newline at end of file diff --git a/src/pages/Doc/index.jsx b/src/pages/Doc/index.jsx index 452bf50..05aa084 100644 --- a/src/pages/Doc/index.jsx +++ b/src/pages/Doc/index.jsx @@ -11,8 +11,7 @@ const DocList = () => { useEffect(() => { const fetchDocs = async () => { try { - // const response = await fetch('/posts/index.json'); - const response = await fetch('https://github-error-solve.vercel.app/posts/index.json'); + const response = await fetch('https://github-error-solve.vercel.app/docs/index.json'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } @@ -41,7 +40,7 @@ const DocList = () => { diff --git a/src/pages/Doc/single doc/index.jsx b/src/pages/Doc/single doc/index.jsx index 3f0d22c..fbbefbb 100644 --- a/src/pages/Doc/single doc/index.jsx +++ b/src/pages/Doc/single doc/index.jsx @@ -31,7 +31,7 @@ const DocDetail = () => { useEffect(() => { const fetchContent = async () => { try { - const response = await fetch(`/posts/${slug}.md`); + const response = await fetch(`/docs/${slug}.md`); if (!response.ok) { throw new Error(`Failed to fetch content: ${response.statusText}`); } From 15778d19b0db478a0422c444ad5e5840711e30b8 Mon Sep 17 00:00:00 2001 From: Sakib Ahmed Date: Sun, 28 Jul 2024 14:21:13 +0600 Subject: [PATCH 2/3] background color dark increased (#209) * test vue * new error added * doc indiv new page added * major update on doc page * husky removed * some minor issue fix * code clean up + code optimize for color * new doc added * new post added + folder rename + minor changes * background color darker --- src/index.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.css b/src/index.css index 26d940e..4263213 100644 --- a/src/index.css +++ b/src/index.css @@ -9,7 +9,7 @@ @layer base { body { - @apply bg-white text-dark dark:bg-dark dark:text-white; + @apply bg-white text-dark dark:bg-[#02000e] dark:text-white; } } From abdbc2c182f693b1a853f2a30f85c19aa4d70ebe Mon Sep 17 00:00:00 2001 From: Suresh Pradhana Date: Sun, 28 Jul 2024 17:06:19 +0530 Subject: [PATCH 3/3] fix: model text visibility in light theme (#210) --- src/components/Error/ErrorSolutions.jsx | 2 +- src/components/Error/ErrorType.jsx | 2 +- src/components/Error/ModalSolutions.jsx | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/Error/ErrorSolutions.jsx b/src/components/Error/ErrorSolutions.jsx index e4d53fb..321af18 100644 --- a/src/components/Error/ErrorSolutions.jsx +++ b/src/components/Error/ErrorSolutions.jsx @@ -15,7 +15,7 @@ function ErrorSolutions({ solutions }) { return (
    {solutions.split("<").map((solution, index) => ( -
  • +
  • {solution}
  • ))} diff --git a/src/components/Error/ErrorType.jsx b/src/components/Error/ErrorType.jsx index 6370afc..f3a199d 100644 --- a/src/components/Error/ErrorType.jsx +++ b/src/components/Error/ErrorType.jsx @@ -6,7 +6,7 @@ function ErrorType({ type }) { - {type} + {type} ); } diff --git a/src/components/Error/ModalSolutions.jsx b/src/components/Error/ModalSolutions.jsx index 2e1a185..d56eab4 100644 --- a/src/components/Error/ModalSolutions.jsx +++ b/src/components/Error/ModalSolutions.jsx @@ -1,15 +1,20 @@ -import React from "react"; +import React,{ useContext } from "react"; import { MdKeyboardArrowLeft, MdContentCopy } from "react-icons/md"; import ErrorSolutions from "./ErrorSolutions"; import useColorBorderBox from "../../hooks/useColorBorderBox"; import ErrorType from "./ErrorType"; import Modal from "react-modal"; import toast from "react-hot-toast"; +import { ThemeContext } from '../../context/ThemeContext'; Modal.setAppElement("#root"); const ModalSolutions = ({ isOpen, setOpenModal, error }) => { const { errorTypeColor } = useColorBorderBox(error.type); + const { theme } = useContext(ThemeContext); + const overlayBackgroundColor = theme === 'dark' + ? 'rgba(0, 0, 0, 0.6)' + : 'rgba(0, 0, 0, 0.2)'; return ( { id="main-div" style={{ overlay: { - backgroundColor: "rgba(0, 0 ,0, .6)", + backgroundColor: overlayBackgroundColor, }, content: { position: "fixed",