Generate line pointer URL into Github Pull Request

三世轮回 提交于 2021-02-04 18:41:05

问题


I am trying to auto-generate a URL that can point to a line number into the GitHub Pull request's file diff view.

Basically, given the URL https://github.com/weppos/whois/pull/90/files I'd like to generate URL like https://github.com/weppos/whois/pull/90/files#diff-ce6bf647d5a531e54ef0502c7fe799deR27 that can point to the line 27 of file in the GitHub pull request. Looking at the URL, seems like it's combination of

https://github.com/weppos/whois/pull/90/ + files/#diff- + ce6bf647d5a531e54ef0502c7fe799de + R27

I am not sure how to retrieve number ce6bf647d5a531e54ef0502c7fe799de given everything else is known. It'd be great if someone can provide some pointers. Thanks!


回答1:


The Github API docs (found here) suggest the following API endpoint:

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

which would result in something similar to the following:

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

The value you are looking for here is the MD5 hash of filename lib/whois/errors.rb which is ce6bf647d5a531e54ef0502c7fe799de.



来源:https://stackoverflow.com/questions/46383301/generate-line-pointer-url-into-github-pull-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!