Last active
June 2, 2020 22:05
-
-
Save ayush--s/2e2d1ff381baec067958ee4bcfdac79f to your computer and use it in GitHub Desktop.
Clickup commit msg hook
This file contains 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
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]) | |
} | |
} |
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
compilation steps:
go build