Last active
January 26, 2017 06:41
-
-
Save Joaquin6/e81c55672c87108d3f06c58c60964a2b to your computer and use it in GitHub Desktop.
Git-Hooks Hooks created to enhance work day progress and productivity. Available Features: Take control of the git templates in your project by adding a hidden folder called '.git_template' at the root of your directory. Customize the final commit messages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# add-issue-id-hook version 1.1.0 | |
# | |
# Created by Joaquin Briceno | |
# https://github.com/pbetkier/add-issue-id-hook | |
# customize the final commit message using placeholders: | |
# - {issue_id} replaced with discovered issue id | |
# - {user_message} replaced with message provided by the user | |
commit_message_format = '{issue_id} {user_message}' | |
# you may set this to your custom JIRA project key format | |
# or explicitly specify a single project name, e.g. 'EXAMPLE' | |
project_format = '[A-Z][A-Z]+' | |
# if not using JIRA, set this to your ticket system's issue pattern | |
issue_pattern = '{}-[\d]+'.format(project_format) | |
import subprocess | |
import sys | |
import re | |
def read_current_message(): | |
with open(sys.argv[1], 'r') as f: | |
return f.read() | |
def write_message(message): | |
with open(sys.argv[1], 'w') as f: | |
f.write(message) | |
def contains_message(message): | |
return message and not message.isspace() | |
def remove_editor_help_message(message): | |
return message[:message.find("# Please enter the commit message for your changes.")].rstrip() | |
def read_branch_or_exit(): | |
try: | |
current_ref = subprocess.check_output('git symbolic-ref HEAD', shell=True).decode() | |
return current_ref[len('refs/heads/'):] | |
except subprocess.CalledProcessError: | |
print("add-issue-id-hook: Adding issue id failed. Are you in detached HEAD state?") | |
sys.exit() | |
issue_id_match = re.search(issue_pattern, read_branch_or_exit()) | |
if issue_id_match: | |
found_issue_id = issue_id_match.group() | |
user_message = remove_editor_help_message(read_current_message()) | |
if contains_message(user_message) and found_issue_id not in user_message: | |
write_message(commit_message_format.format(issue_id=found_issue_id, user_message=user_message)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Short description of commit | |
Longer explanation of the motivation for the change | |
Fixes-Bug: Enter bug-id or delete line | |
Implements-Requirement: Enter requirement-id or delete line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Ignore Visual Studio temporary files, build results, and | |
## files generated by popular Visual Studio add-ons. | |
# User-specific files | |
*.suo | |
*.user | |
*.sln.docstates | |
logs/* | |
npm-debug.log.* | |
# Build results | |
[Dd]ebug/ | |
[Dd]ebugPublic/ | |
[Rr]elease/ | |
[Rr]eleases/ | |
x64/ | |
x86/ | |
bld/ | |
[Bb]in/ | |
[Oo]bj/ | |
*.cache/ | |
.DS_Store | |
# WebStorm project files | |
.idea/ | |
# Roslyn cache directories | |
*.ide/ | |
# MSTest test Results | |
[Tt]est[Rr]esult*/ | |
[Bb]uild[Ll]og.* | |
#NUNIT | |
*.VisualState.xml | |
TestResult.xml | |
# Build Results of an ATL Project | |
[Dd]ebugPS/ | |
[Rr]eleasePS/ | |
dlldata.c | |
*_i.c | |
*_p.c | |
*_i.h | |
*.ilk | |
*.meta | |
*.obj | |
*.pch | |
*.pdb | |
*.pgc | |
*.pgd | |
*.rsp | |
*.sbr | |
*.tlb | |
*.tli | |
*.tlh | |
*.tmp | |
*.tmp_proj | |
*.log | |
*.vspscc | |
*.vssscc | |
.builds | |
*.pidb | |
*.svclog | |
*.scc | |
# Chutzpah Test files | |
_Chutzpah* | |
# Visual C++ cache files | |
ipch/ | |
*.aps | |
*.ncb | |
*.opensdf | |
*.sdf | |
*.cachefile | |
# Visual Studio profiler | |
*.psess | |
*.vsp | |
*.vspx | |
# TFS 2012 Local Workspace | |
$tf/ | |
# Guidance Automation Toolkit | |
*.gpState | |
# ReSharper is a .NET coding add-in | |
_ReSharper*/ | |
*.[Rr]e[Ss]harper | |
*.DotSettings.user | |
# JustCode is a .NET coding addin-in | |
.JustCode | |
# TeamCity is a build add-in | |
_TeamCity* | |
# DotCover is a Code Coverage Tool | |
*.dotCover | |
# NCrunch | |
_NCrunch_* | |
.*crunch*.local.xml | |
# MightyMoose | |
*.mm.* | |
AutoTest.Net/ | |
# Web workbench (sass) | |
.sass-cache/ | |
# Installshield output folder | |
[Ee]xpress/ | |
# DocProject is a documentation generator add-in | |
DocProject/buildhelp/ | |
DocProject/Help/*.HxT | |
DocProject/Help/*.HxC | |
DocProject/Help/*.hhc | |
DocProject/Help/*.hhk | |
DocProject/Help/*.hhp | |
DocProject/Help/Html2 | |
DocProject/Help/html | |
# Publish Web Output | |
*.[Pp]ublish.xml | |
*.azurePubxml | |
# TODO: Comment the next line if you want to checkin your web deploy settings | |
# but database connection strings (with potential passwords) will be unencrypted | |
*.pubxml | |
*.publishproj | |
# NuGet Packages | |
*.nupkg | |
# The packages folder can be ignored because of Package Restore | |
**/packages/* | |
# except build/, which is used as an MSBuild target. | |
!**/packages/build/ | |
# If using the old MSBuild-Integrated Package Restore, uncomment this: | |
#!**/packages/repositories.config | |
# Windows Azure Build Output | |
csx/ | |
*.build.csdef | |
# Windows Store server package directory | |
AppPackages/ | |
# Others | |
sql/ | |
*.Cache | |
ClientBin/ | |
[Ss]tyle[Cc]op.* | |
~$* | |
*~ | |
*.dbmdl | |
*.dbproj.schemaview | |
*.pfx | |
*.publishsettings | |
node_modules/ | |
*.project | |
# RIA/Silverlight projects | |
Generated_Code/ | |
# Backup & report files from converting an old project file | |
# to a newer Visual Studio version. Backup files are not needed, | |
# because we have git ;-) | |
_UpgradeReport_Files/ | |
Backup*/ | |
UpgradeLog*.XML | |
UpgradeLog*.htm | |
# SQL Server files | |
*.mdf | |
*.ldf | |
# Business Intelligence projects | |
*.rdl.data | |
*.bim.layout | |
*.bim_*.settings | |
# Microsoft Fakes | |
FakesAssemblies/ | |
# Sublime Text Files | |
*.sublime-project | |
*.sublime-workspace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment