直接从Emacs创建Pull请求

时间:2015-10-02 17:07:13

标签: git emacs elisp pull-request magit

我喜欢任何普通开发人员应该做的手动,繁琐和重复的任务。最近我意识到 - 在众多git repos上创建拉取请求占用了我太多的时间。大多数时候你必须一遍又一遍地遵循几乎所有的步骤:

  • 登录git提供商的网络客户端 - 我们使用Stash
  • 点击,点击,点击,直到找到"创建拉取请求"按钮,然后单击它
  • 选择一个分支 - 通常它是一个刚被推送的分支
  • 选择一个目标分支 - 大部分时间它都是"开发"
  • 添加评论者 - 大部分时间都是完全相同的人
  • 添加说明 - 可选

在某些时候,我开始想知道如果不使用网络客户端我是否可以做到这一切。而且似乎有可能。 Stash and Bitbucket have an apiGithub has one as well(虽然它不同 - 第一个使用ssh而后者使用http)

现在,这件事可能会简化一些事情,但我觉得它可能会更好。

我使用Emacs(Spacemacs发行版,具体而言)。 现在我想知道是否有人已经构建了与magit集成的任何东西,或者我自己可以做到这一点? 我的意思是它有多难? 脚本应该让你提交然后推送分支,然后使用给定的默认值创建基于该分支的拉取请求#34; develop"有人做过这样的事吗?

你们可以指点一些使用elisp功能的magit插件做同样的事情。也许我能够自己写点东西。

3 个答案:

答案 0 :(得分:5)

我在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

class Shop < ActiveRecord::Base
  include ShopifyApp::Shop
  after_create :init_webhooks

   def self.store(session)
    shop = Shop.where(:shopify_domain => session.url).first_or_create({ shopify_domain: session.url, 
                                      :shopify_token => session.token,
                                      :installed => true})
    shop.id
  end

  def self.retrieve(id)
    shop = Shop.where(:id => id).first
    if shop
      ShopifyAPI::Session.new(shop.shopify_domain, shop.shopify_token)
    else
      nil
    end
  end

答案 1 :(得分:2)

有一个用于处理github pull请求的magit扩展。您可以浏览project here

您还应该通过magit项目的维护人员查看this post

  

所以我担心目前还没有一个能够做到你的方案   想。如果你想自己写,我建议你使用request.el   然后只实现你的Github api的那些部分   实际需要,以避免过度设计它。

答案 2 :(得分:1)

如果(magit-get "remote" (magit-get-remote) "url")返回nil,则已得到改进。

(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 (not repo)
    (setq repo (magit-get "remote" (magit-get-push-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)
  (message repo)
  (browse-url
   (format "https://github.com/%s/pull/new/%s"
       (replace-regexp-in-string
        "\\`.+github\\.com:\\(.+\\)\\(\\.git\\)?\\'" "\\1"
        repo)
       (magit-get-current-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)
  (message repo)
  (browse-url
   (format "https://bitbucket.org/%s/pull-request/new?source=%s&t=1"
       (replace-regexp-in-string
        "\\`.+bitbucket\\.org:\\(.+\\)\\.git\\'" "\\1"
        repo)
       (magit-get-current-branch))))
;; visit PR for github or bitbucket repositories with "v"
(eval-after-load 'magit
  '(define-key magit-mode-map "v"
     #'endless/visit-pull-request-url))
相关问题