4

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!

  • I am not sure if GitHub provides this endpoint. It might be good to mail this question to GitHub support. they are very responsive. – Poonacha Sep 24 '17 at 21:35
  • @vishrut if my answer below worked for you, please mark it as the best answer http://i.stack.imgur.com/QpogP.png if not feel free to comment and I can help you debug this. – mostafazh Sep 29 '17 at 09:10

2 Answers2

2

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.

mostafazh
  • 4,144
  • 1
  • 20
  • 26
  • you can use https://www.md5hashgenerator.com/ to generate an md5 online or use your programming language of choice. – mostafazh Sep 27 '17 at 12:34
  • 1
    I believe this answer might be outdated. Just tried the same in another PR. But the filename is "README.md" on root directory.. not sure if it is different there – Esser420 Jul 06 '22 at 16:30
1

The answer posted here by @mostafazh is outdated.

Nowadays github moved to using sha256, but the approach is still the same.

You can check this by pasting the a hash on hashanalyzer

Esser420
  • 780
  • 1
  • 8
  • 19