From a38ec79c8830419b8f9905943a541e60af2d19b1 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Mon, 18 May 2020 10:34:14 -0400 Subject: [PATCH] Make blob logger easier to debug --- emacs/init.org | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/emacs/init.org b/emacs/init.org index 8cf797d..fe7c51e 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -5115,8 +5115,8 @@ Syntax highlighting for Dockerfiles: #+BEGIN_SRC emacs-lisp (use-package s3ed :commands (s3ed-mode - s3ed-find-file - s3ed-save-file) + s3ed-find-file + s3ed-save-file) :init (jdormit/define-prefix "fS" "s3") (leader-def-key "fSf" #'s3ed-find-file) @@ -5124,16 +5124,22 @@ Syntax highlighting for Dockerfiles: :config (defun browse-blob-in-emacs (url bufname) (let* ((token (password-store-get "blob-logs-token")) - (buf (generate-new-buffer bufname)) - (blob (shell-command-to-string (concat "curl " - "-s " - "--cookie 'TOKEN=" token "' " - url - " | jq")))) - (with-current-buffer buf - (insert blob) - (json-mode)) - (switch-to-buffer-other-window buf))) + (buf (generate-new-buffer bufname)) + (blob (shell-command-to-string (concat "curl " + "-s " + "--cookie 'TOKEN=" token "' " + url))) + (status + (with-current-buffer buf + (insert blob) + (json-mode) + (format-all-buffer)))) + (if (not (equal status "Formatting error")) + (switch-to-buffer-other-window buf) + (with-current-buffer buf + (set-buffer-modified-p nil) + (kill-buffer)) + (switch-to-buffer-other-window "*format-all-errors*")))) (defun s3ed-open-blob-log (arg) "Opens the blob log at point via the cloudfront proxy. @@ -5141,14 +5147,14 @@ Syntax highlighting for Dockerfiles: If given prefix arg ARG, opens in browser, otherwise opens in Emacs." (interactive "P") (let ((fname-at-point (dired-file-name-at-point))) - (if (string-match - "\\(bloblogs.ops.lola.co[m]*\\)\/blobs\/\\(\\(production\\|dev\\|local\\|smoke\\|staging\\)\/[0-9]+/.*\\)" - fname-at-point) - (let* ((proxy-url (format "https://%s" (match-string 0 fname-at-point)))) - (if arg - (browse-url proxy-url) - (browse-blob-in-emacs proxy-url fname-at-point))) - (error "Not in a blob logs directory")))) + (if (string-match + "\\(bloblogs.ops.lola.co[m]*\\)\/blobs\/\\(\\(production\\|dev\\|local\\|smoke\\|staging\\)\/[0-9]+/.*\\)" + fname-at-point) + (let* ((proxy-url (format "https://%s" (match-string 0 fname-at-point)))) + (if arg + (browse-url proxy-url) + (browse-blob-in-emacs proxy-url fname-at-point))) + (error "Not in a blob logs directory")))) :general ((normal) s3ed-mode-map "B" #'s3ed-open-blob-log)) #+END_SRC