Skip to content

Instantly share code, notes, and snippets.

@williscool
Created January 26, 2013 20:43
Show Gist options
  • Save williscool/4644509 to your computer and use it in GitHub Desktop.
Save williscool/4644509 to your computer and use it in GitHub Desktop.
Git lab references post commit hook
#!/bin/sh
PRIVATE_TOKEN="YOU_SECRET_TOKEN"
GITLAB_URL="http://gitlab.example.com/"
URL=`git config --get remote.origin.url`
PROJECT=`basename ${URL} .git | cut -d':' -f2`
COMMIT_MSG="git log -1 HEAD"
COMMIT_HASH_MSG=`git log -1 HEAD | head -1`
for issue_id in `${COMMIT_MSG} | grep -o -e "\(closes\|fixes\) #[0-9]\+" | cut -d'#' -f2`; do
curl -X POST -d "body=fixed in ${COMMIT_HASH_MSG}" \
${GITLAB_URL}api/v3/projects/${PROJECT}/issues/${issue_id}/notes/?private_token=${PRIVATE_TOKEN}
done
for issue_id in `${COMMIT_MSG} | grep -o -e "\(re\|refs\) #[0-9]\+" | cut -d'#' -f2`; do
curl -X POST -d "body=refenced in ${COMMIT_HASH_MSG}" \
${GITLAB_URL}api/v3/projects/${PROJECT}/issues/${issue_id}/notes/?private_token=${PRIVATE_TOKEN}
done
@williscool
Copy link
Author

Dont forget to make it executable with

chmod +x .git/hooks/post-commit

@williscool
Copy link
Author

Moral of the story backtick placement is important

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment