This is a simple tool that tracks commits across all your git repositories and logs them to an Azure Storage Queue as json.
From here you can hook it up to functions, logicapps, local apps or something else to store or process elsewhere.
It was made to help me track what I am working on.
It works by installing a global git hook that will be called after each commit and will HTTP post some commit details to the Azure Storage Queue using a Secure Access Signature (SAS). The credentials are long lived - 5 years as default - and stored in an environment variable.
- will ignore commits on
HEAD
branches - will ignore rebase commits
The format of the json is quite simple.
{
"commit_hash": "093b25400dd5cf56c95bf0000022fe7063a073c8",
"repository": "[email protected]:dalager/commitlogger.git",
"branch": "main",
"author": "Christian Dalager",
"commit_message": "Updating readme"
}
And it ends up in the queue like this
There is two steps to the installation.
- Setup Azure infrastructure
- Install git hook
Using only the Azure CLI and Powershell, this will create the following resources
- Resource group
commitlogger-rg
- Storage account, Standard LRS,
commitloggerstorage<+RandomInt>
- Storage queue
commitqueue
- Access policy "addcommits" with only add permissions to the queue
- An Secure Access Signature (SAS) token that can be used to post to the queue
This is a VERY simple and almost free setup. The storage account is the only thing that will cost you money, and it will cost you almost nothing. Unless you are an insane commit machine, of course. Which you are not. Right?
- Powershell
- Azure subscription
- Install of Azure CLI
If you have not already setup your Azure CLI, run the following commands to login and set the subscription
>az login
>az account set --subscription <subscription id>
And then run the following command to create the azure resources and the environment variable
>.\iac\create_resources.ps1
Sets up a global git hook that will be called after each commit and will post the commit to the azure queue.
Any local post-commit
hook will be called after the global hook.
>.\hooks\install_global_hook.ps1
Take a look at the post-commit hook to see what it does.
- The resource group
commitlogger-rg
contains the storage account and the queue with the logs - The environment variable
COMMITLOGGER_QUEUE_URL
contains the authorized post url to the queue - There is a global
post-commit
hook installed in~/.git-hooks
that will post to the queue after each commit - If you have a local
post-commit
hook in your repository, it will be called after the global hook
With VS code and the restclient extension you can test the endpoint by opening the push_test_message_to_endpoint.http file and sending the request.
Then open the storage queue in either the Azure portal or with the Azure Storage Explorer.
Run the following commands to clean up the resources
>.\iac\drop_resources.ps1
Will delete the resource group and all resources in it and the environment variable COMMITLOGGER_QUEUE_URL
>.\hooks\uninstall_global_hook.ps1
Will uninstall the global git hook
On windows with gitui
(https://github.com/extrawurst/gitui) the global hook is not called due to som issue with rust and hook path resolution/environment. I think.
This means that as of now gitui cannot be used. Issue #2
Lazygit works like a charm, though: https://github.com/jesseduffield/lazygit