Last active
August 29, 2015 14:01
-
-
Save vargonaut/447e8e03518a3bdc75c5 to your computer and use it in GitHub Desktop.
Get a summary and ticket number from Jira, based on branch name
This file contains hidden or 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
| ;; elisp | |
| (setq jira-base-url "<JIRA BASE URL>" | |
| jira-request-url (concat "https://" jira-base-url "/rest/api/latest/issue/") | |
| jira-username "<USERNAME>" | |
| jira-password "<PASSWORD>" | |
| jira-credentials (base64-encode-string (concat jira-username ":" jira-password)) | |
| ;; this is a regex to trim things off the branch name | |
| ;; as is, removes: dev-, rel-, av-, dev/, rel/, av/ | |
| jira-branch-trim-regex "^\\(dev\\|rel\\|\\av\\)\\(-\\|/\\)" | |
| jira-auth-key (concat jira-base-url ":443")) | |
| (defun jira-issue-url(issue &optional fields) | |
| (concat jira-request-url issue (if fields (concat "?fields=" fields)))) | |
| (setq jira-basic-auth | |
| `((,jira-auth-key ("Jira" . ,jira-credentials)))) | |
| (defun jira-json-buffer(url) | |
| (let ((url-basic-auth-storage 'jira-basic-auth)) | |
| (url-retrieve-synchronously url))) | |
| (defun jira-json-string (url) | |
| (with-current-buffer (jira-json-buffer url) | |
| (search-forward "{" nil t) | |
| (delete-region (point-min) (- (point) 1)) | |
| (buffer-string))) | |
| (defun jira-ticket-summary (json-string) | |
| (unless (string-equal json-string "}") | |
| (let ((json-object-type 'plist)) | |
| (plist-get (plist-get | |
| (json-read-from-string json-string ) | |
| :fields) :summary)))) | |
| (defun jira-summary-for-issue(issue) | |
| (jira-ticket-summary | |
| (jira-json-string | |
| (jira-issue-url issue "summary")))) | |
| (defun git-trimmed-branch() | |
| (replace-regexp-in-string jira-branch-trim-regex "" (upcase (magit-get-current-branch)))) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; This is a snippet | |
| ;; <snippet-dir>/git-commit-mode/bug | |
| #name : bug commit message | |
| #key: bug | |
| # expand-env: ((yas/indent-line nil)) | |
| # -- | |
| $>`(git-trimmed-branch)`: ${1:`(jira-summary-for-issue(git-trimmed-branch))`} | |
| $0 | |
| $>`(concat "https://" jira-base-url "/browse/" (git-trimmed-branch))` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment