How can i validate links within a private github repository

Viewed 155

Background

We are writing some documentation for our support team. We want to include links to files that are stored in private GitHub repositories. We do not want the documentation to become stale if somebody refactors the code in the private GitHub repositories, so instead I am setting up a CI job that parses the documentation (with jsoup if you are interested) and finds all the links. Once we have all the links we start checking them.

NOTE: we have written a custom link checker, because one of the critical set of links we have is for our monitoring solution, and sadly (also understandably) the SaaS we are using returns 404's for any unauthenticated requests on the URLs of the alerts. The SaaS itself uses a 2FA to access the Web UI, so what we have ended up doing is parsing the URLs and then constructing an equivalent call to the SaaS API to validate the link. For the monitoring system we use, this is easy: all the URLs are the same format.

Question

Can we validate a random GitHub URL as valid (ideally using only curl - I can translate to my chosen HTTP client from there, and curl gives a more generic answer) using a Personal Access Token? And if so, how?

The URLs could be:

  • simple direct to repo URLs: https://github.com/<org>/<repo>
  • direct to branch URLs: https://github.com/<org>/<repo>/tree/<branch>
  • file URLs: https://github.com/<org>/<repo>/blob/<path/to/file>
  • diff URLs: https://github.com/<org>/<repo>/compare/[<branch>...]<branch>
  • other URLs that are based on the presence of the repo and do not vary in child path, e.g. https://github.com/<org>/<repo>/pulls, https://github.com/<org>/<repo>/settings/collaboration, etc
  • plus who knows what other URLs people will add within the docs...

Things I have tried that didn't work

HTTP Basic authentication with the Personal Access Token as the password, e.g. curl -I -u stephenc:2....token.redacted....b https://github.com/stephenc/<repo-name> HTTP/1.1 404 Not Found

HTTP Bearer authentication, e.g. curl -I -H "Authorization: bearer 2....token.redacted....b" https://github.com/stephenc/<repo-name> HTTP/1.1 404 Not Found

2 Answers

It looks like it works for some URLs (no idea which ones). I can access curl -u agentgonzo:$TOKEN https://raw.githubusercontent.com/agentgonzo/repo/path/to/file using the API Token as my username, but the same doesn't work on https://github.com URLs. Not sure if this will help you or not.

I got an answer from GitHub Support: No

Since a personal access token won't work for GitHub web UI URLs, no, there isn't a way to verify all possible GitHub private repo URLs without making API calls in some cases.

Related