SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Git hooks
hebinbin.herokuapp.com
2013/05/10
Why ?
Problem: Some guys forgot to log their working time.
Therefore, for teamleaders, they can not know
how this ticket going.
Solution: After you git commit, open browser to
log your working time.
How ?
Git has one function named as
hooks. ( http://git-scm.com/book )
In my words, Hooks like event trigger
After you did git operation, it will trigger some events.
Examples
Git checkout ----------> you want to check whether all
gems have been installed.
Git push ----------> you want to trigger jenkins server to
run rspec to check you code.
Place
• Git hooks is in .git/hooks
• You can use shell script or ruby or python
• But remember to use chmod +x filename
Types
There has two types:
Client side (In your local PC)
Server side (In remote server like Stash)
• applypatch-msg
• post-update
• pre-rebase
• commit-msg
• pre-applypatch
• update
• post-commit
• pre-commit
• post-receive
• prepare-commit-msg
Git Commit
When you use git commit :
pre-commit
↓
prepare-commit-msg
↓
commit-msg
↓
post-commit
No Ticket, No Commit
In the future, when you look back to the code,
you want to know why this guy changed this code ?
Such as: “Fixed rspec error”
“Refactored the code”
---- > “GI-12345: Fixed rspec error”
“GI-54321: Refactored the code”
Pre-commit -1
Before commit, this hook can check something for you.
For example, in my pc, I will check where the code has “binding.pry” or not.
Place: .git/hooks/pre-commit
Code:
#!/usr/bin/env ruby
require 'colorize'
# check for rails debugger
rails_result = `grep -rlsn "binding.pry" --exclude-dir=".git" .`
if rails_result != ""
puts "[Error] you put binding.pry in your filesn".red
puts rails_result
exit(1)
end
Pre-commit -2
Prepare-commit-msg -1
• Means giving commit-msg a template
For example:
Now you are working at pr-GI-12345-2.5-id
Every time, when you commit, you want to add ticket
number to your commit message.
commit message here
↓
Ticket #GI-12345 commit message here.
Prepare-commit-msg -2
• #!/usr/bin/env ruby
•
• TICKET_REGEXP = /[A-Z]+-d+/ # WEB-12345
•
• TICKET_REF_FORMAT = 'Ticket #%s # ' # JIRA Ticket reference syntax.
•
• branch_name = `git branch --no-color 2> /dev/null`[/^* (.+)/, 1]
• msg_filename = ARGV[0]
•
• if ticket_in_branch = branch_name.match(TICKET_REGEXP)
• ticket_ref = TICKET_REF_FORMAT % ticket_in_branch.to_s
• old_msg = File.read msg_filename
•
• unless old_msg.match ticket_ref
• File.open msg_filename, 'w' do |new_msg|
• new_msg.write ticket_ref + old_msg
• end
• end
• end
•
• exit 0
Prepare-commit-msg -3
Commit-msg -1
• We can this hook to check whether your commit message has ticket number or not.
• #!/usr/bin/env ruby
•
• require 'colorize'
•
• TICKET_REGEXP = /[A-Z]+-d+/ # WEB-12345
•
• commit_message = File.open ARGV[0], 'r' { |f| f.read }
•
• unless commit_message.match(TICKET_REGEXP)
• puts "[ERROR] commit-message-format: JIRA ticket number is not existed.".red
• exit(1)
• end
Commit-msg -2
Post-commit -1
If everything goes well, then we can open firefox to log your time.
• #!/usr/bin/env ruby
•
• require 'colorize'
•
• TICKET_REGEXP = /[A-Z]+-d+/ # WEB-12345
•
• LINK = "https://*****.atlassian.net/browse/"
•
• puts "[Warning] log time: Please do not forget to log your time".red
•
• commit_message = %x{git log -1 --abbrev-commit}.split("n").last.strip
•
• jira_ticket = commit_message.match(TICKET_REGEXP)
• puts "please visit #{LINK}#{jira_ticket.to_s} to log time".green
•
• exec("firefox #{LINK}#{jira_ticket.to_s}")
Post-commit -2
Server side (git push)
• pre-receive
• update
• post-receive
Thanks
https://github.com/hebinbin/git-hooks-jira

Weitere ähnliche Inhalte

Was ist angesagt?

Deployment made easy with Git
Deployment made easy with GitDeployment made easy with Git
Deployment made easy with GitIgor Santos
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CILingvokot
 
Workflows using Git GitHub | Edureka
Workflows using Git GitHub | EdurekaWorkflows using Git GitHub | Edureka
Workflows using Git GitHub | EdurekaEdureka!
 
Puppet Camp Atlanta 2014: r10k Puppet Workflow
Puppet Camp Atlanta 2014: r10k Puppet WorkflowPuppet Camp Atlanta 2014: r10k Puppet Workflow
Puppet Camp Atlanta 2014: r10k Puppet WorkflowPuppet
 
Jenkins vs GitLab CI
Jenkins vs GitLab CIJenkins vs GitLab CI
Jenkins vs GitLab CICEE-SEC(R)
 
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubNick Quaranto
 
SCM Gitlab Advanced
SCM Gitlab AdvancedSCM Gitlab Advanced
SCM Gitlab AdvancedAman Patial
 
Webinar - Automated Puppet Code Deployment with R10K
Webinar - Automated Puppet Code Deployment with R10KWebinar - Automated Puppet Code Deployment with R10K
Webinar - Automated Puppet Code Deployment with R10KOlinData
 
CI/CD with Rancher CLI + Jenkins
CI/CD with Rancher CLI + JenkinsCI/CD with Rancher CLI + Jenkins
CI/CD with Rancher CLI + JenkinsGo Chiba
 
Webinar - Continuous Integration with GitLab
Webinar - Continuous Integration with GitLabWebinar - Continuous Integration with GitLab
Webinar - Continuous Integration with GitLabOlinData
 
Devops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at GitlabDevops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at GitlabFilipa Lacerda
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 
Enjoy privacy on Gitlab
Enjoy privacy on GitlabEnjoy privacy on Gitlab
Enjoy privacy on GitlabMaxis Kao
 
Brief tutorial on Git
Brief tutorial on GitBrief tutorial on Git
Brief tutorial on Git聖文 鄭
 
Gorush: A push notification server written in Go
Gorush: A push notification server written in GoGorush: A push notification server written in Go
Gorush: A push notification server written in GoBo-Yi Wu
 
Swift Argument Parser
Swift Argument ParserSwift Argument Parser
Swift Argument Parser碩彥 王
 

Was ist angesagt? (20)

Deployment made easy with Git
Deployment made easy with GitDeployment made easy with Git
Deployment made easy with Git
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CI
 
Workflows using Git GitHub | Edureka
Workflows using Git GitHub | EdurekaWorkflows using Git GitHub | Edureka
Workflows using Git GitHub | Edureka
 
Puppet Camp Atlanta 2014: r10k Puppet Workflow
Puppet Camp Atlanta 2014: r10k Puppet WorkflowPuppet Camp Atlanta 2014: r10k Puppet Workflow
Puppet Camp Atlanta 2014: r10k Puppet Workflow
 
Jenkins vs GitLab CI
Jenkins vs GitLab CIJenkins vs GitLab CI
Jenkins vs GitLab CI
 
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
 
SCM Gitlab Advanced
SCM Gitlab AdvancedSCM Gitlab Advanced
SCM Gitlab Advanced
 
Webinar - Automated Puppet Code Deployment with R10K
Webinar - Automated Puppet Code Deployment with R10KWebinar - Automated Puppet Code Deployment with R10K
Webinar - Automated Puppet Code Deployment with R10K
 
CI/CD with Rancher CLI + Jenkins
CI/CD with Rancher CLI + JenkinsCI/CD with Rancher CLI + Jenkins
CI/CD with Rancher CLI + Jenkins
 
Git advanced
Git advancedGit advanced
Git advanced
 
Webinar - Continuous Integration with GitLab
Webinar - Continuous Integration with GitLabWebinar - Continuous Integration with GitLab
Webinar - Continuous Integration with GitLab
 
Devops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at GitlabDevops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at Gitlab
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Enjoy privacy on Gitlab
Enjoy privacy on GitlabEnjoy privacy on Gitlab
Enjoy privacy on Gitlab
 
Brief tutorial on Git
Brief tutorial on GitBrief tutorial on Git
Brief tutorial on Git
 
Gorush: A push notification server written in Go
Gorush: A push notification server written in GoGorush: A push notification server written in Go
Gorush: A push notification server written in Go
 
Git & Github
Git & GithubGit & Github
Git & Github
 
Swift Argument Parser
Swift Argument ParserSwift Argument Parser
Swift Argument Parser
 
Git
GitGit
Git
 

Ähnlich wie Git hooks

Developing with the Go client for Apache Kafka
Developing with the Go client for Apache KafkaDeveloping with the Go client for Apache Kafka
Developing with the Go client for Apache KafkaJoe Stein
 
Server Development Workflow For PicCollage
Server Development Workflow For PicCollageServer Development Workflow For PicCollage
Server Development Workflow For PicCollageLin Jen-Shin
 
SECON'2017, Цаль-Цалко Иван, Go на практике
SECON'2017, Цаль-Цалко Иван, Go на практикеSECON'2017, Цаль-Цалко Иван, Go на практике
SECON'2017, Цаль-Цалко Иван, Go на практикеSECON
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control SystemVictor Wong
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductortimyates
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for GitJan Krag
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in UnityRifauddin Tsalitsy
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Chu-Siang Lai
 
Год в Github bugbounty, опыт участия
Год в Github bugbounty, опыт участияГод в Github bugbounty, опыт участия
Год в Github bugbounty, опыт участияdefcon_kz
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2PgTraining
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)Carlos Duarte do Nascimento
 

Ähnlich wie Git hooks (20)

Developing with the Go client for Apache Kafka
Developing with the Go client for Apache KafkaDeveloping with the Go client for Apache Kafka
Developing with the Go client for Apache Kafka
 
Server Development Workflow For PicCollage
Server Development Workflow For PicCollageServer Development Workflow For PicCollage
Server Development Workflow For PicCollage
 
SECON'2017, Цаль-Цалко Иван, Go на практике
SECON'2017, Цаль-Цалко Иван, Go на практикеSECON'2017, Цаль-Цалко Иван, Go на практике
SECON'2017, Цаль-Цалко Иван, Go на практике
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductor
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Jedi Mind Tricks in Git
Jedi Mind Tricks in GitJedi Mind Tricks in Git
Jedi Mind Tricks in Git
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for Git
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in Unity
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
 
Git basics 2
Git basics 2Git basics 2
Git basics 2
 
Год в Github bugbounty, опыт участия
Год в Github bugbounty, опыт участияГод в Github bugbounty, опыт участия
Год в Github bugbounty, опыт участия
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
 
Git
GitGit
Git
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Switching to Git
Switching to GitSwitching to Git
Switching to Git
 

Kürzlich hochgeladen

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 

Kürzlich hochgeladen (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

Git hooks

  • 2. Why ? Problem: Some guys forgot to log their working time. Therefore, for teamleaders, they can not know how this ticket going. Solution: After you git commit, open browser to log your working time.
  • 3. How ? Git has one function named as hooks. ( http://git-scm.com/book ) In my words, Hooks like event trigger After you did git operation, it will trigger some events.
  • 4. Examples Git checkout ----------> you want to check whether all gems have been installed. Git push ----------> you want to trigger jenkins server to run rspec to check you code.
  • 5. Place • Git hooks is in .git/hooks • You can use shell script or ruby or python • But remember to use chmod +x filename
  • 6. Types There has two types: Client side (In your local PC) Server side (In remote server like Stash) • applypatch-msg • post-update • pre-rebase • commit-msg • pre-applypatch • update • post-commit • pre-commit • post-receive • prepare-commit-msg
  • 7. Git Commit When you use git commit : pre-commit ↓ prepare-commit-msg ↓ commit-msg ↓ post-commit
  • 8. No Ticket, No Commit In the future, when you look back to the code, you want to know why this guy changed this code ? Such as: “Fixed rspec error” “Refactored the code” ---- > “GI-12345: Fixed rspec error” “GI-54321: Refactored the code”
  • 9. Pre-commit -1 Before commit, this hook can check something for you. For example, in my pc, I will check where the code has “binding.pry” or not. Place: .git/hooks/pre-commit Code: #!/usr/bin/env ruby require 'colorize' # check for rails debugger rails_result = `grep -rlsn "binding.pry" --exclude-dir=".git" .` if rails_result != "" puts "[Error] you put binding.pry in your filesn".red puts rails_result exit(1) end
  • 11. Prepare-commit-msg -1 • Means giving commit-msg a template For example: Now you are working at pr-GI-12345-2.5-id Every time, when you commit, you want to add ticket number to your commit message. commit message here ↓ Ticket #GI-12345 commit message here.
  • 12. Prepare-commit-msg -2 • #!/usr/bin/env ruby • • TICKET_REGEXP = /[A-Z]+-d+/ # WEB-12345 • • TICKET_REF_FORMAT = 'Ticket #%s # ' # JIRA Ticket reference syntax. • • branch_name = `git branch --no-color 2> /dev/null`[/^* (.+)/, 1] • msg_filename = ARGV[0] • • if ticket_in_branch = branch_name.match(TICKET_REGEXP) • ticket_ref = TICKET_REF_FORMAT % ticket_in_branch.to_s • old_msg = File.read msg_filename • • unless old_msg.match ticket_ref • File.open msg_filename, 'w' do |new_msg| • new_msg.write ticket_ref + old_msg • end • end • end • • exit 0
  • 14. Commit-msg -1 • We can this hook to check whether your commit message has ticket number or not. • #!/usr/bin/env ruby • • require 'colorize' • • TICKET_REGEXP = /[A-Z]+-d+/ # WEB-12345 • • commit_message = File.open ARGV[0], 'r' { |f| f.read } • • unless commit_message.match(TICKET_REGEXP) • puts "[ERROR] commit-message-format: JIRA ticket number is not existed.".red • exit(1) • end
  • 16. Post-commit -1 If everything goes well, then we can open firefox to log your time. • #!/usr/bin/env ruby • • require 'colorize' • • TICKET_REGEXP = /[A-Z]+-d+/ # WEB-12345 • • LINK = "https://*****.atlassian.net/browse/" • • puts "[Warning] log time: Please do not forget to log your time".red • • commit_message = %x{git log -1 --abbrev-commit}.split("n").last.strip • • jira_ticket = commit_message.match(TICKET_REGEXP) • puts "please visit #{LINK}#{jira_ticket.to_s} to log time".green • • exec("firefox #{LINK}#{jira_ticket.to_s}")
  • 18. Server side (git push) • pre-receive • update • post-receive