git - 直接从 Emacs 创建 pull 请求

标签 git emacs elisp pull-request magit

我讨厌任何普通开发人员应该做的手动、乏味和重复性的工作。最近我意识到——在大量的 git repos 上创建 pull 请求占用了我太多的时间。大多数时候,您必须一遍又一遍地遵循几乎完全相同的步骤:

  • 登录到 git 提供商的网络客户端——我们使用 Stash
  • 点击,点击,点击直到找到“Create Pull Request”按钮,然后点击它
  • 选择一个分支——通常是刚刚推送的分支
  • 选择一个目标分支——大部分时间是“开发”
  • 添加评论者 - 大多数时候都是同一个人
  • 添加描述 - 可选

在某些时候,我开始怀疑我是否可以在不使用网络客户端的情况下完成所有这些工作。这似乎是可能的。 Stash and Bitbucket have an api , Github has one as well (虽然有所不同——第一个使用ssh,后者使用http)

现在,这个东西可能会简化一些事情,但我觉得它可以做得更好。

我使用 Emacs(具体来说是 Spacemacs 发行版)。 现在我想知道是否有人已经构建了与 magit 集成的任何东西,或者也许我可以自己做? 我的意思是这会有多难? 脚本应该让您提交然后推送分支,然后使用给定的默认值基于该分支针对“开发”创建 pull 请求。有没有人做过这样的事?

你们能给我指点一些 elisp 插件吗,它们利用 magit 的力量来做类似的事情。也许我可以自己写点东西。

最佳答案

我在 github 上找到了这篇关于从 emacs 创建 PR 的原始帖子。 http://endlessparentheses.com/easily-create-github-prs-from-magit.html

这不适用于 bitbucket(存储)。但这对我来说已经足够了 能够拼凑出适合我的解决方案。

https://github.com/flamingbear/emacs-config/blob/master/site-lisp/lisp/mhs-magit.el

(defun endless/visit-pull-request-url ()
  "Visit the current branch's PR on Github."
  (interactive)
  (let ((repo (magit-get "remote" (magit-get-remote) "url")))
    (if (string-match "github\\.com" repo)
    (visit-gh-pull-request repo)
  (visit-bb-pull-request repo))))


(defun visit-gh-pull-request (repo)
  "Visit the current branch's PR on Github."
  (interactive)
  (browse-url
   (format "https://github.com/%s/pull/new/%s"
     (replace-regexp-in-string
      "\\`.+github\\.com:\\(.+\\)\\.git\\'" "\\1"
      repo)
     (cdr (magit-get-remote-branch)))))



;; Bitbucket pull requests are kinda funky, it seems to try to just do the
;; right thing, so there's no branches to include.
;; https://bitbucket.org/<username>/<project>/pull-request/new
(defun visit-bb-pull-request (repo)
  (browse-url
   (format "https://bitbucket.org/%s/pull-request/new"
           (replace-regexp-in-string
            "\\`.+bitbucket\\.org:\\(.+\\)\\.git\\'" "\\1"
            repo))))

;; visit PR for github or bitbucket repositories with "v"
(eval-after-load 'magit
  '(define-key magit-mode-map "v"
     #'endless/visit-pull-request-url))

关于git - 直接从 Emacs 创建 pull 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32912320/

相关文章:

git - SourceTree 终端无法推送,GUI 可以推送

emacs - 在 LispBox 中的 Emacs 中加载 SLIME 编辑命令

Emacs - 找不到关于电子布局模式的信息

小型网络团队的 Git 工作流程

git - 我可以将 git blame 配置为始终忽略某些提交吗?想要一劳永逸地修复 git blame

git - 我遇到了 merge 冲突。如何中止 merge ?

macos - Mac OS X 上的 .emacs 文件在哪里

emacs - 如何在 Emacs 中复制整行?

emacs - 在 .dir-locals.el 中定义新变量

Emacs Lisp - 如何处理函数返回字符串或 nil 的边缘情况?