monty-python
monty-python copied to clipboard
feat(github): support `#discussioncomment-` urls
Adds support for embedding <owner>/<repo>/discussions/<id>#discussioncomment-<id> urls.
This is... rather difficult via the GraphQL api (which you are required to use for this :/), since you would need the global ID (DC_kwDOF-MrcM4AT8ii), which you can technically only get from prior API requests.
The other "intended" way of fetching a discussion comment based on the integer ID would be to query discussion(123) { comments(after: ...) {}} and paginate through all comments until we find a matching ID. no thanks.
Instead, we rely on the undocumented format of GraphQL global IDs, which are msgpack'ed arrays containing the repo ID and resource ID, with a type prefix. This works with essentially any resource, e.g. I_{b64(msgpack([0, repo_id, issue_id]))} to fetch an issue based on its ID, and so on; the prefixes are pretty trivial to figure out.
It's worth noting that these IDs also include an owner ID (i.e. repo_id above), which we don't get from the URL. This ID isn't required atm, but may be in the future. As per GHE source:
# Currently this is defaulting to the same behavior as the legacy
# id lookup. In the future, this method needs to be modified
# to look up objects based on the ownership information in
# the passed in GlobalID.
It works fine for now, and this ID format hasn't changed for the 4 years it has been used so far. If it does end up being required in the future, we'll have to make one extra API request to turn the <owner>/<repo> part from the URL into an ID as well.
(the timestamp is wrong, see #240.)
This depends on #265, see https://github.com/shiftinv/monty-python/compare/feat/github-discussion-links...shiftinv:monty-python:feat/github-discussioncomment for a proper diff