How do you attach a new pull request to an existing issue on github?

前端 未结 10 1891
抹茶落季
抹茶落季 2020-12-04 04:40

I\'m not sure, but I have a vague memory of creating a github pull request with \"Issue 4\" or something in the title, and it automatically attached itself to Issue 4 in the

相关标签:
10条回答
  • 2020-12-04 04:46

    You can create a Pull Request from an existing Issue with the Pull Request API:

    $ curl --user "smparkes" \
           --request POST \
           --data '{"issue": 15, "head": "smparkes:synchrony", "base": "master"}' \
           https://api.github.com/repos/technoweenie/faraday/pulls
    

    This creates a pull request:

    • ask technoweenie at project faraday (https://api.github.com/repos/technoweenie/faraday/pulls)
    • to pull from the synchrony branch in smparkes' fork ("head": "smparkes:synchrony")
    • to the master branch in technoweenie's fork ("base": "master")
    • and attach the pull request to issue 15 ("issue": 15)
    • with the pull request author smparkes (--user "smparkes")
    • you will be prompted for your GitHub password
    0 讨论(0)
  • 2020-12-04 04:46

    Instead of doing that on the client side (with hub, as in Christian Oudard answer), you now (February 2020) can do it on the server side (github.com)

    See "View and link issues and pull requests from the sidebar "

    You can now link issues and pull requests via the sidebar in their respective pages. Connections made here will automatically close issues once a linked pull request is merged.

    Documentation:

    And there is a search API with that feature.

    Find all the open issues in a repository that have closing pull requests references with the linked:pr search qualifier.
    Similarly, locate all the pull requests in a repository that are missing a supporting issue with -linked:issue.

    0 讨论(0)
  • 2020-12-04 04:48

    in case you use 2-factor-auth with github you'll need to provide the authtoken as header in the request:

    curl -u "<your_username>:<your_pw>" \
         --header 'X-GitHub-OTP: <your_authtoken>' \
         --request POST \
         --data '{"issue":"<issue_nr>", "head":"<your_username>:<your_forks_branchname>", "base":"<upstream_branch>"}' \
         https://api.github.com/repos/<upstream_user>/<upstream_repo>/pulls
    
    0 讨论(0)
  • 2020-12-04 04:52

    This other answer explains how to use cURL (curl) to create a Pull Request from an Issue through the GitHub API. Here’s how to do it using HTTPie (http), which produces an easier-to-read and easier-to-edit command:

    $ http --auth "<your-GitHub-username>" \
           POST \
           https://api.github.com/repos/<issue-repo-owner>/<issue-repo-name>/pulls \
           issue=<issue-number> head=<your-GitHub-username>:<your-fork-branch-name> base=<issue-repo-branch-name>
    

    Then type your GitHub password when prompted.

    Explained example

    You have logged into GitHub with username smparkes and password hunter2. You saw technoweenie’s repo faraday, thought of something that should be changed, and made an Issue on that repo for it, Issue #15. Later, you find that nobody else has made your proposed change, and you also have some time to do it yourself. You fork faraday to your own account, then write your changes and push them to your fork under a branch named synchrony. You think technoweenie should pull those changes to the master branch of his repo. This is the command you would write to convert your previous Issue into a Pull Request for this situation:

    $ http --auth "smparkes" \
           POST \
           https://api.github.com/repos/technoweenie/faraday/pulls \
           issue=15 head=smparkes:synchrony base=master
    
    http: password for smparkes@api.github.com: hunter2
    

    Now Issue #15 is a Pull Request.

    0 讨论(0)
  • 2020-12-04 04:54

    The "hub" project can do this:

    https://github.com/defunkt/hub

    In the repository and branch that you want to send a pull request from:

    $ hub pull-request -i 4
    

    This uses the GitHub API, and attaches a pull request for the current branch to the existing issue number 4.


    EDIT: Comment by @atomicules: To expand on the answer by @MichaelMior a full example is:

    $ hub pull-request -i 4 -b USERNAME_OF_UPSTREAM_OWNER:UPSTREAM_BRANCH -h YOUR_USERNAME:YOUR_BRANCH URL_TO_ISSUE
    
    0 讨论(0)
  • 2020-12-04 04:54

    Another possible tool is the Issue2Pr website which turns your issues into Pull Requests.

    It's very simple and effective!

    enter image description here

    Resources:

    • Announcement
    • GitHub repository
    0 讨论(0)
提交回复
热议问题