From 4dc0bf4a2904965fc26907a4ed7d27d678cf7f40 Mon Sep 17 00:00:00 2001 From: "wjak56@gmail.com" Date: Sun, 16 Aug 2015 00:35:25 -0400 Subject: [PATCH] Ability to get commit message in post-commit hook --- api.rkt | 22 +++++++++++++++++++++- commit.rkt | 4 +++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/api.rkt b/api.rkt index e88ebab..fd19063 100644 --- a/api.rkt +++ b/api.rkt @@ -10,11 +10,14 @@ (define (create-config path ex) (let ([password (readline "Your wordpress password? ")] [username (readline "Your wordpress username? ")] + [blog-location (readline "Where is the blog directory? ")] [conf (open-output-file path)]) (displayln (format "password = ~a" password) conf) (displayln (format "username = ~a" username) conf) + (displayln + (format "blog-location = ~a" blog-location) conf) (close-output-port conf) (new-config path))) @@ -60,6 +63,15 @@ (curry hash-ref config)))) +(define (in-blog?) + (equal? + (string-trim + (system-result "pwd")) + (path->string + (path->directory-path + (string->path + (your-config 'blog-location)))))) + ; The current list of commits (as a dynamically scoped name) (define current-commits (make-parameter (list))) @@ -206,6 +218,13 @@ "git status --short | grep -E '\\.post$'"))) "\n"))) +; Returns the latest commit message +; Intended to run in the post-commit hook +; since you have to actually write the commit msg first +(define (get-commit-msg) + (system-result + "git log -1 HEAD | tail -n 1 | sed s/^[[:space:]]*// | tr -d '\\n'")) + ; Parses a post file and returns the components (define (parse-post categories text) (let ([lines (string-split text "\n")]) @@ -338,4 +357,5 @@ your-config password username - xstring) \ No newline at end of file + xstring + in-blog?) \ No newline at end of file diff --git a/commit.rkt b/commit.rkt index d065350..0bb41b8 100755 --- a/commit.rkt +++ b/commit.rkt @@ -2,7 +2,9 @@ #lang racket (require "api.rkt") -(parameterize ([current-commits (get-commits)] +(if (in-blog?) + (parameterize ([current-commits (get-commits)] [password (xstring (your-config 'password))] [username (xstring (your-config 'username))]) (commit-posts)) + (displayln "Not in the blog directory right now so quitting.")) \ No newline at end of file