Created
February 9, 2016 13:08
-
-
Save davazp/04ec57e9f2674a789ba5 to your computer and use it in GitHub Desktop.
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
;;; magit-stash.el --- Stash integration with Magit -*- lexical-binding: t; -*- | |
;; Copyright (C) 2015 David Vazquez | |
;; Author: David Vazquez <davazp@gmail.com> | |
;; Keywords: tools, vc | |
;; This program is free software; you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation, either version 3 of the License, or | |
;; (at your option) any later version. | |
;; This program is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;; | |
;;; Code: | |
(defvar magit-stash-base-url "http://stash.ctrl.dev") | |
;;; Given a reference, return a list of (PROJECT REPO BRANCHNAME). | |
(defun magit-stash-get-ref (ref) | |
(cl-destructuring-bind (remote branch) | |
(split-string ref "/") | |
(let* ((url (magit-get "remote" remote "url")) | |
(match (string-match "scm/\\([^/]*\\)/\\(.*\\)\\.git$" url))) | |
(list (upcase (match-string 1 url)) | |
(match-string 2 url) | |
branch)))) | |
(defun magit-stash-pull-request (from-branch to-branch) | |
(interactive | |
(let ((from (magit-read-remote-branch "From" nil (magit-get-push-branch)))) | |
(list from | |
(magit-read-remote-branch "To" nil (concat (magit-get-push-remote) "/master"))))) | |
(let ((from-ref (magit-stash-get-ref from-branch)) | |
(to-ref (magit-stash-get-ref to-branch))) | |
(browse-url | |
(format "%s/projects/%s/repos/%s/pull-requests?create&targetBranch=%s&sourceBranch=%s" | |
magit-stash-base-url | |
(car to-ref) | |
(cadr to-ref) | |
(url-hexify-string (concat "refs/heads/" (caddr to-ref))) | |
(url-hexify-string (concat "refs/heads/" (caddr from-ref))))))) | |
(define-key magit-mode-map (kbd "<f5>") 'magit-stash-pull-request) | |
(provide 'magit-stash) | |
;;; magit-stash.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment