Skip to content

Instantly share code, notes, and snippets.

@ayush--s
Last active June 2, 2020 22:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayush--s/2e2d1ff381baec067958ee4bcfdac79f to your computer and use it in GitHub Desktop.
Save ayush--s/2e2d1ff381baec067958ee4bcfdac79f to your computer and use it in GitHub Desktop.
Clickup commit msg hook
package main
// put this executable as .git/hooks/prepare-commit-msg
import (
"io/ioutil"
"log"
"os"
"strings"
)
// WriteBranch ...
// Appends branch to commit msg file
func WriteBranch(branch string) {
commitMsgFile := os.Args[1]
f, err := os.OpenFile(commitMsgFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 640)
if err != nil {
log.Panic(err)
}
_, err = f.Write([]byte("\n[" + branch + "]"))
if err1 := f.Close(); err != nil {
log.Panic(err1)
}
}
func main() {
dat, err := ioutil.ReadFile("./.git/HEAD")
if err != nil {
log.Panic(err)
}
ref := string(dat)
branch := strings.Split(ref, "/")[2]
branchSplit := strings.Split(branch, "_")
if len(branchSplit) > 1 && strings.HasPrefix(branchSplit[1], "#") {
WriteBranch(branchSplit[1])
}
}
@ayush--s
Copy link
Author

compilation steps:
go build

@ayush--s
Copy link
Author

this will work only if your branch is of the form:
initials_#clickupid_branch_name

eg:
as_#c57sf_reset_alerts

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