I'm writing a PHP script that lets users enter a GitHub owner & repo name, and then it downloads a zip file from that repo.
GitHub allows linking directly to the download of the latest release for a repo: /owner/name/releases/latest/download/name.zip
(see https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/linking-to-releases). So if a repo has a release, that works fine.
However, for repos without a release, I want to download from the default branch instead. GitHub provides a link for this (green 'Code' button > 'Download ZIP'), but that URL includes the branch name: /owner/name/archive/[BRANCH].zip
.
Is there a way to link directly to the download for the latest branch without knowing what the branch might be called? For example, something like this hypothetical URL: /owner/name/archive/latest.zip