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 project that I was submitting it to. I tried it again recently and it didn't work -- it just created a brand new issue instead. I don't see any options like "Attach to issue" on the new pull request page, nor "Open a new pull request for this issue" on the issue page. Is there any way to do this, to help project owners keep their Issues page clean and avoid duplication?

编辑:澄清一下,我知道创建拉请求总是会产生一个新问题。我想把拉请求附加到一个现有的问题上。


当前回答

你现在(2020年2月)可以在服务器端(github.com)做,而不是在客户端(使用hub,如Christian Oudard的回答)做。

参见“查看和链接问题,并从侧栏提取请求”

您现在可以通过各自页面中的侧边栏链接问题和提取请求。在这里建立的连接将在合并链接的pull请求后自动关闭问题。

文档:

有一个带有这个功能的搜索API。

使用linked:pr搜索限定符查找存储库中具有关闭拉请求引用的所有开放问题。 类似地,使用-linked:issue定位存储库中缺少支持问题的所有拉请求。


Ismoh在评论中提到了讨论:

GitHub Action:拉请求“开发”对象/数据,又名链接问题

Ismosh的Marketplace操作用于查找拉请求的链接问题。

    - name: Find linked issues
      id: find-linked-issues
      uses: Ismoh-Games/find-linked-issues@v0.0.1
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        repository: ${{ github.repository }} # optional
        pull-request-number: ${{ github.event.pull_request.number }} # optional
        copy-issues-labels: true # optional

其他回答

如果你启用了2FA,你可以使用HTTPie传递令牌:

http POST \
    https://api.github.com/repos/<repo-owner>/<repo-name>/pulls \
    issue=2 head=issue_2 base=master
    "Authorization:token PUTAUTHTOKENHERE"

这将使用分支issue_2将问题#2转换为一个拉请求。

您也可以使用Gub为您的问题提交拉请求。

它还可以帮助您使用合适的fork/pull-request样式。

编辑:10/5/2013

为了让Gub提交issue #123的pull-request,你需要运行以下命令:

$ gub start 123

这将创建一个新的分支issue-123。一旦你解决了这个问题,执行:

$ gub finish

拖鞋!

注:我是Gub gem的作者。

你现在(2020年2月)可以在服务器端(github.com)做,而不是在客户端(使用hub,如Christian Oudard的回答)做。

参见“查看和链接问题,并从侧栏提取请求”

您现在可以通过各自页面中的侧边栏链接问题和提取请求。在这里建立的连接将在合并链接的pull请求后自动关闭问题。

文档:

有一个带有这个功能的搜索API。

使用linked:pr搜索限定符查找存储库中具有关闭拉请求引用的所有开放问题。 类似地,使用-linked:issue定位存储库中缺少支持问题的所有拉请求。


Ismoh在评论中提到了讨论:

GitHub Action:拉请求“开发”对象/数据,又名链接问题

Ismosh的Marketplace操作用于查找拉请求的链接问题。

    - name: Find linked issues
      id: find-linked-issues
      uses: Ismoh-Games/find-linked-issues@v0.0.1
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        repository: ${{ github.repository }} # optional
        pull-request-number: ${{ github.event.pull_request.number }} # optional
        copy-issues-labels: true # optional

使用git-hub工具,你可以这样做:

$> git枢纽拉附加123

这将把问题#123转换为拉请求#123,从而将关于该问题的所有讨论保持在一个位置。

如果你在github中使用2-factor-auth,你需要在请求中提供authtoken作为头部:

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