Create a GitHub PR via a link

20 Mar 2019

It’s possible to auto-populate a PR with parameters in a link, like you can with a mailto: link.

Parameters

https://github.com/[account]/[repo]/new/master \
  ?filename=filename \
  &value=file contents \
  &message=PR title \
  &description=PR description \
  &quick_pull=base-branch-name \
  &target_branch=new-branch-name

Demo

Try it out. Open a test PR.

GitHub Pull Request UI, pre-populated

Ruby Helper

    def link_to_test_pr(project:, options: {})
      hostname = "https://www.github.com/"
      url_params = File.join(project, *%w(new master))
      uri = URI.join(hostname, url_params)
      query_params = %w(
        filename=accesslint-test.html
        value=<img\ src="logo.png"\ />
        message=[DO\ NOT\ MERGE]\ Testing\ AccessLint
        description=Expect\ comments\ from\ AccessLint
        quick_pull=master
        target_branch=accesslint-test
      ).join("&")
      uri.query = query_params

      link_to(t(".test"), uri.to_s, class: options[:class])
    end

Background

I uncovered this while building AccessLint GitHub App, to open demo PR to test the build integration.