Getting the anchor to files diffs in a pull request

Hey there,

I’m trying to retrieve the link to the diff for each file in the pull request, which follows the following format:<username>/<repository>/pull/<pull-id>/files#diff-<file-diff-anchor>

The closest I’ve got is the raw patch, which is not actually useful for me (List pull requests files API documentation).

I’ve been playing around with the PR data and also googling and checking the API documentation for a while with no luck, and I don’t know where to continue looking at.

Is this even possible?

Thanks in advance.

No, there isn’t a way to get the anchor link you’re asking for via the API. It is something that has been requested previously, but I can’t give an ETA or even say whether it is something the development team will implement. I’ll pass along your feedback however.

Thanks for reaching out.

It seems to be MD5 from the file name

1 Like

This works! The diff id in the anchor tag is the md5sum of the utf-8 encoded file path in a repository. It’s the full path from the repository root.

Using the example given in the github compare documentation:

the diff id for the file path is 5ba41511a41a1ae2dea92ef1ca666ee8

In [1]: import hashlib                                                                                                  

In [2]: hashlib.md5("".encode('utf-8')).hexdigest()                                                     
Out[2]: '5ba41511a41a1ae2dea92ef1ca666ee8'

Even if it’s not in the api, this should really be in the github documentation.