paint-brush
Git Hooks ile Git İş Akışları Nasıl Otomatikleştirilir 🚀ile@smy
Yeni tarih

Git Hooks ile Git İş Akışları Nasıl Otomatikleştirilir 🚀

ile Syed Muhammad Yaseen4m2024/07/30
Read on Terminal Reader

Çok uzun; Okumak

Git kancaları, Git deposunda belirli bir olay meydana geldiğinde otomatik olarak çalışan komut dosyalarıdır. Git'in dahili davranışını özelleştirmenize ve geliştirme yaşam döngüsünün önemli noktalarında özelleştirilebilir eylemleri tetiklemenize olanak tanır. Örneğin, dosyalar işlenmeden önce Lint kontrollerini çalıştırmak istiyorsunuz, bu nedenle ön işleme kancasını kullanıyoruz.
featured image - Git Hooks ile Git İş Akışları Nasıl Otomatikleştirilir 🚀
Syed Muhammad Yaseen HackerNoon profile picture
0-item
1-item

Merhaba!


Umarım harika gidiyorsundur! Bu SMY'dir! 👋 Hemen içeri girelim 🚀


....

Her taahhütte kullanılacak örnek bir taahhüt mesajı kancası oluşturdum


↳ şube adı kuralını kontrol eder, yani [tür]/ABC-[bilet numarası]-[amaç]


↳ taahhüt mesajı kuralını kontrol eder, yani [ABC-bilet numarası] [tür]: amaç


↳ tüylenmeleri, daha güzel olup olmadığını kontrol eder ve birim testlerini çalıştırır


Ana Bağlantı: https://Gist.github.com/smyaseen/17083d60d02a07b2a3122410e2d39b6f

.....

İçindekiler:

  • Wait What?
  • ⚡Ama But Why?
  • ⚡Ama But How?

1️⃣ Ne -


↳ Git kancaları, Git deposunda belirli bir olay meydana geldiğinde otomatik olarak çalışan komut dosyalarıdır.


↳ Git'in dahili davranışını özelleştirmenize ve geliştirme yaşam döngüsünün önemli noktalarında özelleştirilebilir eylemleri tetiklemenize olanak tanır.


↳ Yerel kancalar ve sunucu tarafı kancaları vardır.

↳ Yerel kancalar makinenizde ve uzak depodaki sunucu tarafında çalışır.


yerel kancalar:


↳ taahhüt öncesi ↳ taahhüt mesajı hazırlığı ↳ taahhüt mesajı ↳ taahhüt sonrası ↳ ödeme sonrası ↳ yeniden hazırlama öncesi


sunucu kancaları:


↳ alım öncesi ↳ güncelleme ↳ alım sonrası


2️⃣ Neden -


↳ Örneğin, dosyalar kaydedilmeden önce Lint kontrollerini çalıştırmak istiyorsunuz, bu nedenle ön işleme kancasını kullanıyoruz.


↳ standart şube adını ve taahhüt-msg kuralını uygulamak istediğiniz başka bir örnek, bu nedenle taahhüt-msg kancasını kullanıyoruz.


↳ ve çok daha fazlası...


3️⃣ Nasıl -


↳ Kolay kurulum için bir JavaScript projesinde Husky adında bir kütüphane kurun ve dokümantasyonu takip edin

https://www.npmjs.com/package/husky


↳ Örnek olarak şube adlarını uygulamak, mesaj kurallarını uygulamak ve lint, prettier ve testleri çalıştırmak istiyorum.


↳ Birden fazla kanca kullanabiliriz. Benim durumumda bir taahhüt mesajı kancası ekleyeceğim. Ön-taahhüt'ü seçmememin nedeni, taahhüt edilmeden önce çalıştığı için taahhüt msg'sini kontrol etmemesiydi. Bir geliştiricinin kontroller yapmasını ve taahhüt mesajında başarısız olmasını, düzeltmesini ve tekrar çalıştırmasını istemiyorum. Önce taahhüt mesajını kontrol etmek istiyorum.


↳ Husky'nin belgelerini takip ederek bir taahhüt mesajı kancası oluşturun ve aşağıdaki örneği yapıştırın:


 #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" # Checks for branch name currentBranch=$(git rev-parse --abbrev-ref HEAD) requiredPattern="^(build|chore|feat|docs|refactor|perf|test)/ABC-\d+-.+$" if ! echo "$currentBranch" | grep -qE $requiredPattern; then echo "\nInvalid branch name: $currentBranch" echo "-" echo "Should follow this pattern: build|chore|feat|docs|refactor|perf|test/ABC-ticketnumber-any-text" echo "-" echo "example: docs/ABC-123-update-readme.md" echo "-" echo "Refer to this for convention:" echo "-" echo "build : Changes related to building the code (eg adding npm dependencies or external libraries)." echo "-" echo "chore: Changes that do not affect the external user (eg updating the .gitignore file or .prettierrc file)." echo "-" echo "feat: A new feature." echo "-" echo "fix: A bug fix." echo "-" echo "docs: Documentation a related changes." echo "-" echo "refactor: A code that neither fix bug nor adds a feature." echo "-" echo "perf: A code that improves performance style: A code that is related to styling." echo "-" echo "test: Adding new test or making changes to existing test" echo "-\n" exit 1 # Branch name doesn't match the pattern, exit with error code fi # Checks for commit message commit_message="$(cat "$1")" pattern='^\[ABC-[0-9]+\] (build|chore|feat|docs|refactor|perf|test): .+$' if [[ ! $commit_message =~ $pattern ]]; then echo "\nInvalid commit message: $commit_message" echo "-" echo "Should follow this pattern: [ABC-ticketnumber] build|chore|feat|docs|refactor|perf|test: objective" echo "-" echo "example: [ABC-15] chore: updated .gitignore" echo "-" echo "Refer to this for convention:" echo "-" echo "build : Changes related to building the code (eg adding npm dependencies or external libraries)." echo "-" echo "chore: Changes that do not affect the external user (eg updating the .gitignore file or .prettierrc file)." echo "-" echo "feat: A new feature." echo "-" echo "fix: A bug fix." echo "-" echo "docs: Documentation a related changes." echo "-" echo "refactor: A code that neither fix bug nor adds a feature." echo "-" echo "perf: A code that improves performance style: A code that is related to styling." echo "-" echo "test: Adding new test or making changes to existing test" echo "-\n" exit 1 fi # npx lint-staged -- uncomment when have lint setted up # npm run test -- uncomment when have test setted up


↳ Artık, ne zaman taahhütte bulunsanız, tüy kontrollerini çalıştırmanın yanı sıra şube ve taahhüt adlandırma kuralını da kontrol edecektir. Son olarak, her şey yolunda gittikten sonra testleri gerçekleştirecek.

4️⃣ Sonuç -

✨Tutarlılık.

✨ Standardizasyon.

✨ Önemsiz Şeylerden Uzak Durun.

✨ Otomatikleştirin ve Etkili Olana Odaklanın.


Özet:


Git Hooks ile Geliştirme İş Akışınızı Yükselttik. 🚀


.....


Artık geliştirme iş akışınızı güçlendirebilirsiniz 🚀


İşte bu kadar millet! Umarım sizin için iyi bir okuma olmuştur. Teşekkür ederim! ✨


👉 Beni GitHub ve LinkedIn'de takip edin