From 05b94060b4d4c2047c50636c10d15a9821c5f6af Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Fri, 12 Apr 2024 04:48:41 +0300 Subject: [PATCH 1/9] Initial setup, open repo and read head --- go.mod | 29 ++++++++++++ go.sum | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 34 +++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..78d1f94 --- /dev/null +++ b/go.mod @@ -0,0 +1,29 @@ +module github.com/artem-y/commit + +go 1.21.4 + +require github.com/go-git/go-git/v5 v5.12.0 + +require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ProtonMail/go-crypto v1.0.0 // indirect + github.com/cloudflare/circl v1.3.7 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/skeema/knownhosts v1.2.2 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.22.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/tools v0.13.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d7b8453 --- /dev/null +++ b/go.sum @@ -0,0 +1,145 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= +github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= +github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= +github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= +github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= +github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..dfeca4b --- /dev/null +++ b/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "os" + + "github.com/go-git/go-git/v5" +) + +func main() { + // Open the repository in the current directory + repo, err := git.PlainOpen(".") + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to open repository: %v\n", err) + os.Exit(1) + } + + // Get current HEAD + ref, err := repo.Head() + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to read current HEAD: %v\n", err) + os.Exit(1) + } + + // Output branch name or HEAD + if ref.Name().IsBranch() { + fmt.Printf("%v\n", ref.Name().Short()) + } else if ref.Name().IsTag() { + fmt.Printf("HEAD is a tag: %v\n", ref.Name().Short()) + } else { + fmt.Printf("Detached HEAD at %v\n", ref.Hash()) + } +} + From 766bf977ddc33f7f387626357da6e300e0c4388d Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:30:54 +0300 Subject: [PATCH 2/9] Ignore build artifact --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3b735ec..7a6548b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.dll *.so *.dylib +commit # Test binary, built with `go test -c` *.test From b663ea9662ebd9d2b6b51825bae11f9680299c59 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:32:34 +0300 Subject: [PATCH 3/9] Form commit message with hard coded issue type --- main.go | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index dfeca4b..55afc29 100644 --- a/main.go +++ b/main.go @@ -3,28 +3,59 @@ package main import ( "fmt" "os" + "regexp" + "strings" "github.com/go-git/go-git/v5" ) func main() { + args := os.Args[1:] + if len(args) < 1 { + fmt.Fprintln(os.Stderr, red("Commit message cannot be empty")) + os.Exit(1) + } + + var commitMessage string + commitMessage = args[0] + // Open the repository in the current directory repo, err := git.PlainOpen(".") if err != nil { - fmt.Fprintf(os.Stderr, "Failed to open repository: %v\n", err) - os.Exit(1) + fmt.Fprintf(os.Stderr, red("Failed to open repository: %v\n"), err) + os.Exit(1) } // Get current HEAD ref, err := repo.Head() if err != nil { - fmt.Fprintf(os.Stderr, "Failed to read current HEAD: %v\n", err) + fmt.Fprintf(os.Stderr, red("Failed to read current HEAD: %v\n"), err) os.Exit(1) } // Output branch name or HEAD if ref.Name().IsBranch() { - fmt.Printf("%v\n", ref.Name().Short()) + + branchName := ref.Name().Short() + fmt.Printf("branch: %v\n", branchName) + + rgxp := regexp.MustCompile(`#[0-9]+`) + matches := rgxp.FindAllStringSubmatch(branchName, -1) + matchesArray := []string{} + + for _, match := range matches { + for _, matchItem := range match { + matchesArray = append(matchesArray, matchItem) + } + } + + if len(matchesArray) > 0 { + joinedIssues := strings.Join(matchesArray, ", ") + commitMessage = fmt.Sprintf("[%s]: %s", joinedIssues, commitMessage) + } + + fmt.Println(commitMessage) + } else if ref.Name().IsTag() { fmt.Printf("HEAD is a tag: %v\n", ref.Name().Short()) } else { @@ -32,3 +63,6 @@ func main() { } } +func red(msg string) string { + return fmt.Sprintf("\033[31m%s\033[0m", msg) +} From ce0538a8c9906282ab253d02a8009e3372bf5610 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sun, 14 Apr 2024 02:12:27 +0300 Subject: [PATCH 4/9] Perform the actual commit, adding info from current user --- main.go | 132 ++++++++++++++++++++++++++++++++++++-------------------- user.go | 45 +++++++++++++++++++ 2 files changed, 130 insertions(+), 47 deletions(-) create mode 100644 user.go diff --git a/main.go b/main.go index 55afc29..f9df3d3 100644 --- a/main.go +++ b/main.go @@ -3,66 +3,104 @@ package main import ( "fmt" "os" - "regexp" - "strings" + "regexp" + "strings" + "time" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/object" ) func main() { - args := os.Args[1:] - if len(args) < 1 { - fmt.Fprintln(os.Stderr, red("Commit message cannot be empty")) - os.Exit(1) - } + args := os.Args[1:] + if len(args) < 1 { + fmt.Fprintln(os.Stderr, red("Commit message cannot be empty")) + os.Exit(1) + } - var commitMessage string - commitMessage = args[0] + var commitMessage string + commitMessage = args[0] // Open the repository in the current directory repo, err := git.PlainOpen(".") if err != nil { fmt.Fprintf(os.Stderr, red("Failed to open repository: %v\n"), err) - os.Exit(1) + os.Exit(1) + } + + // Get current HEAD + ref, err := repo.Head() + if err != nil { + fmt.Fprintf(os.Stderr, red("Failed to read current HEAD: %v\n"), err) + os.Exit(1) + } + + // Read branch name or HEAD + if ref.Name().IsBranch() { + + branchName := ref.Name().Short() + + // TODO: Add support for custom regex + matchesArray := findIssueNumbersInBranch(`#[0-9]+`, branchName) + + if len(matchesArray) > 0 { + joinedIssues := strings.Join(matchesArray, ", ") + commitMessage = fmt.Sprintf("[%s]: %s", joinedIssues, commitMessage) + } + + worktree, err := repo.Worktree() + if err != nil { + fmt.Fprintf(os.Stderr, red("Failed to open worktree: %v\n"), err) + os.Exit(1) + } + + usr := getUser(*repo) + commitOptions := makeCommitOptions(usr) + + _, err = worktree.Commit(commitMessage, &commitOptions) + if err != nil { + fmt.Fprintf(os.Stderr, red("Failed to commit: %v\n"), err) + os.Exit(1) + } + + fmt.Println(commitMessage) + + } else if ref.Name().IsTag() { + fmt.Printf("HEAD is a tag: %v\n", ref.Name().Short()) + } else { + fmt.Printf("Detached HEAD at %v\n", ref.Hash()) } - - // Get current HEAD - ref, err := repo.Head() - if err != nil { - fmt.Fprintf(os.Stderr, red("Failed to read current HEAD: %v\n"), err) - os.Exit(1) - } - - // Output branch name or HEAD - if ref.Name().IsBranch() { - - branchName := ref.Name().Short() - fmt.Printf("branch: %v\n", branchName) - - rgxp := regexp.MustCompile(`#[0-9]+`) - matches := rgxp.FindAllStringSubmatch(branchName, -1) - matchesArray := []string{} - - for _, match := range matches { - for _, matchItem := range match { - matchesArray = append(matchesArray, matchItem) - } - } - - if len(matchesArray) > 0 { - joinedIssues := strings.Join(matchesArray, ", ") - commitMessage = fmt.Sprintf("[%s]: %s", joinedIssues, commitMessage) - } - - fmt.Println(commitMessage) - - } else if ref.Name().IsTag() { - fmt.Printf("HEAD is a tag: %v\n", ref.Name().Short()) - } else { - fmt.Printf("Detached HEAD at %v\n", ref.Hash()) - } } +// Wraps the message string in red color func red(msg string) string { - return fmt.Sprintf("\033[31m%s\033[0m", msg) + return fmt.Sprintf("\033[31m%s\033[0m", msg) +} + +// Searches the branch name for issue numbers matching the given regex +func findIssueNumbersInBranch(rgxRaw string, branchName string) []string { + // TODO: Don't use MustCompile, handle errors + rgx := regexp.MustCompile(rgxRaw) + + matches := rgx.FindAllStringSubmatch(branchName, -1) + matchesArray := []string{} + + for _, match := range matches { + matchesArray = append(matchesArray, match...) + } + + return matchesArray +} + +// Creates commit options with the author information +func makeCommitOptions(usr user) git.CommitOptions { + return git.CommitOptions{ + Author: &object.Signature{ + Name: usr.name, + Email: usr.email, + When: time.Now(), + }, + AllowEmptyCommits: false, + Amend: false, + } } diff --git a/user.go b/user.go new file mode 100644 index 0000000..2a0ce11 --- /dev/null +++ b/user.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "os" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/config" +) + +// Simple representation of a git user +type user struct { + name string + email string +} + +// Returns the user name and email from the local repository or the global git config +func getUser(repo git.Repository) user { + cfg, err := repo.Config() + if err != nil { + fmt.Fprintf(os.Stderr, red("Error loading local config: %v\n"), err) + os.Exit(1) + } + + usr := user{ + name: cfg.User.Name, + email: cfg.User.Email, + } + + globalCfg, err := config.LoadConfig(config.GlobalScope) + if err != nil { + fmt.Fprintf(os.Stderr, red("Error loading global config: %v\n"), err) + os.Exit(1) + } + + if usr.email == "" { + usr.email = globalCfg.User.Email + } + + if usr.name == "" { + usr.name = globalCfg.User.Name + } + + return usr +} From 995e76e3f9f5a6099204f8a6c6b5e0138249a612 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sun, 14 Apr 2024 03:53:02 +0300 Subject: [PATCH 5/9] Read issue regex from config file, split main func --- .commit.json | 3 ++ config.go | 37 ++++++++++++++++ go.mod | 5 ++- go.sum | 2 + main.go | 123 ++++++++++++++++++++++++++++++++------------------- 5 files changed, 124 insertions(+), 46 deletions(-) create mode 100644 .commit.json create mode 100644 config.go diff --git a/.commit.json b/.commit.json new file mode 100644 index 0000000..00b0502 --- /dev/null +++ b/.commit.json @@ -0,0 +1,3 @@ +{ + "issueRegex": "#[0-9]+" +} \ No newline at end of file diff --git a/config.go b/config.go new file mode 100644 index 0000000..9637b6f --- /dev/null +++ b/config.go @@ -0,0 +1,37 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" +) + +type commitConfig struct { + IssueRegex string `json:"issueRegex"` +} + +// Reads .commit.json file from current directory and unmarshals it into commitConfig struct +func readCommitConfig() commitConfig { + + configFileName := ".commit.json" + + _, err := os.Stat(configFileName) + if os.IsNotExist(err) { + return commitConfig{} + } + + file, err := os.ReadFile(configFileName) + if err != nil { + fmt.Fprintf(os.Stderr, red("Error reading %s file: %v\n"), err, configFileName) + os.Exit(1) + } + + var cfg commitConfig + err = json.Unmarshal(file, &cfg) + if err != nil { + fmt.Fprintf(os.Stderr, red("Error unmarshalling %s file: %v\n"), err, configFileName) + os.Exit(1) + } + + return cfg +} diff --git a/go.mod b/go.mod index 78d1f94..dc8dd65 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module github.com/artem-y/commit go 1.21.4 -require github.com/go-git/go-git/v5 v5.12.0 +require ( + github.com/go-git/go-git v4.7.0+incompatible + github.com/go-git/go-git/v5 v5.12.0 +) require ( dario.cat/mergo v1.0.0 // indirect diff --git a/go.sum b/go.sum index d7b8453..e131b3d 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,8 @@ github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66D github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA= +github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= diff --git a/main.go b/main.go index f9df3d3..5a878ac 100644 --- a/main.go +++ b/main.go @@ -8,68 +8,89 @@ import ( "time" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" ) +const ( + default_issue_regex = "#[0-9]+" +) + func main() { + commitMessage := getCommitMessage() + + issueRegex := default_issue_regex + + commitCfg := readCommitConfig() + if commitCfg.IssueRegex != "" { + issueRegex = commitCfg.IssueRegex + } + + repo := openRepo() + headRef := getCurrentHead(repo) + + // Read branch name or HEAD + if headRef.Name().IsBranch() { + + branchName := headRef.Name().Short() + + matches := findIssueNumbersInBranch(issueRegex, branchName) + + if len(matches) > 0 { + joinedIssues := strings.Join(matches, ", ") + commitMessage = fmt.Sprintf("[%s]: %s", joinedIssues, commitMessage) + } + + commitChanges(repo, commitMessage) + + fmt.Println(commitMessage) + + } else if headRef.Name().IsTag() { + fmt.Printf("HEAD is a tag: %v\n", headRef.Name().Short()) + } else { + fmt.Printf("Detached HEAD at %v\n", headRef.Hash()) + } +} + +// Reads commit message from command line arguments +func getCommitMessage() string { args := os.Args[1:] if len(args) < 1 { fmt.Fprintln(os.Stderr, red("Commit message cannot be empty")) os.Exit(1) } - var commitMessage string - commitMessage = args[0] + return args[0] +} - // Open the repository in the current directory +// Opens the repository in current directory +func openRepo() *git.Repository { repo, err := git.PlainOpen(".") if err != nil { fmt.Fprintf(os.Stderr, red("Failed to open repository: %v\n"), err) os.Exit(1) } + return repo +} - // Get current HEAD - ref, err := repo.Head() +// Reads the current HEAD reference +func getCurrentHead(repo *git.Repository) *plumbing.Reference { + headRef, err := repo.Head() if err != nil { fmt.Fprintf(os.Stderr, red("Failed to read current HEAD: %v\n"), err) os.Exit(1) } + return headRef +} - // Read branch name or HEAD - if ref.Name().IsBranch() { - - branchName := ref.Name().Short() - - // TODO: Add support for custom regex - matchesArray := findIssueNumbersInBranch(`#[0-9]+`, branchName) - - if len(matchesArray) > 0 { - joinedIssues := strings.Join(matchesArray, ", ") - commitMessage = fmt.Sprintf("[%s]: %s", joinedIssues, commitMessage) - } - - worktree, err := repo.Worktree() - if err != nil { - fmt.Fprintf(os.Stderr, red("Failed to open worktree: %v\n"), err) - os.Exit(1) - } - - usr := getUser(*repo) - commitOptions := makeCommitOptions(usr) - - _, err = worktree.Commit(commitMessage, &commitOptions) - if err != nil { - fmt.Fprintf(os.Stderr, red("Failed to commit: %v\n"), err) - os.Exit(1) - } - - fmt.Println(commitMessage) - - } else if ref.Name().IsTag() { - fmt.Printf("HEAD is a tag: %v\n", ref.Name().Short()) - } else { - fmt.Printf("Detached HEAD at %v\n", ref.Hash()) +// Opens worktree +func openWorktree(repo *git.Repository) *git.Worktree { + worktree, err := repo.Worktree() + if err != nil { + fmt.Fprintf(os.Stderr, red("Failed to open worktree: %v\n"), err) + os.Exit(1) } + return worktree } // Wraps the message string in red color @@ -79,17 +100,16 @@ func red(msg string) string { // Searches the branch name for issue numbers matching the given regex func findIssueNumbersInBranch(rgxRaw string, branchName string) []string { - // TODO: Don't use MustCompile, handle errors rgx := regexp.MustCompile(rgxRaw) - matches := rgx.FindAllStringSubmatch(branchName, -1) - matchesArray := []string{} + allSubmatches := rgx.FindAllStringSubmatch(branchName, -1) - for _, match := range matches { - matchesArray = append(matchesArray, match...) + matches := []string{} + for _, submatches := range allSubmatches { + matches = append(matches, submatches[0]) } - return matchesArray + return matches } // Creates commit options with the author information @@ -104,3 +124,16 @@ func makeCommitOptions(usr user) git.CommitOptions { Amend: false, } } + +// Commits changes with provided message +func commitChanges(repo *git.Repository, commitMessage string) { + worktree := openWorktree(repo) + usr := getUser(*repo) + commitOptions := makeCommitOptions(usr) + + _, err := worktree.Commit(commitMessage, &commitOptions) + if err != nil { + fmt.Fprintf(os.Stderr, red("Failed to commit: %v\n"), err) + os.Exit(1) + } +} From 8f12a58121819d857321bf0a6fb92970ca798ba4 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sun, 14 Apr 2024 03:58:41 +0300 Subject: [PATCH 6/9] Move constants out of main file --- constants.go | 5 +++++ main.go | 9 ++------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 constants.go diff --git a/constants.go b/constants.go new file mode 100644 index 0000000..46c4615 --- /dev/null +++ b/constants.go @@ -0,0 +1,5 @@ +package main + +const ( + default_issue_regex = "#[0-9]+" +) diff --git a/main.go b/main.go index 5a878ac..ff9903d 100644 --- a/main.go +++ b/main.go @@ -12,10 +12,6 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" ) -const ( - default_issue_regex = "#[0-9]+" -) - func main() { commitMessage := getCommitMessage() @@ -33,8 +29,7 @@ func main() { if headRef.Name().IsBranch() { branchName := headRef.Name().Short() - - matches := findIssueNumbersInBranch(issueRegex, branchName) + matches := findIssueMatchesInBranch(issueRegex, branchName) if len(matches) > 0 { joinedIssues := strings.Join(matches, ", ") @@ -99,7 +94,7 @@ func red(msg string) string { } // Searches the branch name for issue numbers matching the given regex -func findIssueNumbersInBranch(rgxRaw string, branchName string) []string { +func findIssueMatchesInBranch(rgxRaw string, branchName string) []string { rgx := regexp.MustCompile(rgxRaw) allSubmatches := rgx.FindAllStringSubmatch(branchName, -1) From 55bf7182c9faba7cf7fc59d91a7e0594c1bdb00a Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:00:05 +0300 Subject: [PATCH 7/9] Remove redundant dependency --- go.mod | 5 +---- go.sum | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/go.mod b/go.mod index dc8dd65..78d1f94 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,7 @@ module github.com/artem-y/commit go 1.21.4 -require ( - github.com/go-git/go-git v4.7.0+incompatible - github.com/go-git/go-git/v5 v5.12.0 -) +require github.com/go-git/go-git/v5 v5.12.0 require ( dario.cat/mergo v1.0.0 // indirect diff --git a/go.sum b/go.sum index e131b3d..d7b8453 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,6 @@ github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66D github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= -github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA= -github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= From ddb326de9f12fef3a4bde161955f132623397646 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:14:57 +0300 Subject: [PATCH 8/9] Move default config path into constants --- config.go | 10 +++++----- constants.go | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index 9637b6f..42ca433 100644 --- a/config.go +++ b/config.go @@ -13,23 +13,23 @@ type commitConfig struct { // Reads .commit.json file from current directory and unmarshals it into commitConfig struct func readCommitConfig() commitConfig { - configFileName := ".commit.json" + configFilePath := default_config_file_path - _, err := os.Stat(configFileName) + _, err := os.Stat(configFilePath) if os.IsNotExist(err) { return commitConfig{} } - file, err := os.ReadFile(configFileName) + file, err := os.ReadFile(configFilePath) if err != nil { - fmt.Fprintf(os.Stderr, red("Error reading %s file: %v\n"), err, configFileName) + fmt.Fprintf(os.Stderr, red("Error reading %s file: %v\n"), err, configFilePath) os.Exit(1) } var cfg commitConfig err = json.Unmarshal(file, &cfg) if err != nil { - fmt.Fprintf(os.Stderr, red("Error unmarshalling %s file: %v\n"), err, configFileName) + fmt.Fprintf(os.Stderr, red("Error unmarshalling %s file: %v\n"), err, configFilePath) os.Exit(1) } diff --git a/constants.go b/constants.go index 46c4615..29f035b 100644 --- a/constants.go +++ b/constants.go @@ -1,5 +1,6 @@ package main const ( - default_issue_regex = "#[0-9]+" + default_config_file_path = ".commit.json" + default_issue_regex = "#[0-9]+" ) From 712ecd8fce127241eb1ef3551c4b857a9291dd29 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:27:49 +0300 Subject: [PATCH 9/9] Move readme and license to docs folder --- LICENSE => docs/LICENSE | 0 README.md => docs/README.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename LICENSE => docs/LICENSE (100%) rename README.md => docs/README.md (100%) diff --git a/LICENSE b/docs/LICENSE similarity index 100% rename from LICENSE rename to docs/LICENSE diff --git a/README.md b/docs/README.md similarity index 100% rename from README.md rename to docs/README.md