生成行指针URL到Github Pull Request

时间:2017-09-23 19:07:50

标签: git github github-api pull-request

我正在尝试自动生成一个URL,该URL可以指向GitHub Pull请求的文件差异视图中的行号。

基本上,给定URL https://github.com/weppos/whois/pull/90/files我想生成类似https://github.com/weppos/whois/pull/90/files#diff-ce6bf647d5a531e54ef0502c7fe799deR27的URL,它可以指向GitHub拉取请求中文件的第27行。看看网址,似乎是

的组合

https://github.com/weppos/whois/pull/90/ + 文件/#DIFF- + ce6bf647d5a531e54ef0502c7fe799de + R27

我不知道如何获取其他所有已知的数字ce6bf647d5a531e54ef0502c7fe799de。如果有人可以提供一些指示,那就太棒了。谢谢!

1 个答案:

答案 0 :(得分:2)

Github API文档(找到here)建议使用以下API端点:

GET /repos/weppos/whois/pulls/90/files

会产生类似于以下内容的内容:

[
    {
        "blob_url": "https://github.com/weppos/whois/blob/aa16f66c9dca556b7db131b68b0b99d435bc43d8/lib/whois/errors.rb", 
        "filename": "lib/whois/errors.rb", 
        "sha": "beec7aad75671e40a21532044c0e4dc23f7f226a", 
        "status": "modified",
        ...
    }, 
    ...
]

您要查找的值是文件名lib/whois/errors.rb MD5 哈希值ce6bf647d5a531e54ef0502c7fe799de