Closed davorg closed 1 year ago
A while ago @perlpunk suggested me this construct to find out the default branch of a repo
% git ls-remote --symref -q | grep ^ref: | grep 'HEAD$'
ref: refs/heads/master HEAD
That only works from a checkout, doesn't it? And, currently, when we're building the dashboards, we don't have the git repos checked out - and I'd rather keep it that way if possible.
I've worked out a way to do it with the GitHub API - now I'm just battling rate limits.
That only works from a checkout, doesn't it?
No, it also works with a git url, e.g.
% git ls-remote --symref -q git@github.com:yaml/pyyaml | grep ^ref: | grep 'HEAD$'
ref: refs/heads/master HEAD
BTW @perlpunk why do you need both greps? As I can see either one of those would work
@szabgab hm, I don't remember why I did it this way. probably a leftover from experimenting :) so this should do it:
git ls-remote --symref -q [url] | grep '^ref:.*HEAD$'
Turned out the best way was to use the GitHub CLI tools with a bit of jq
.
gh repo view owner/repo --json defaultBranchRef -q .defaultBranchRef.name
See 44b995e
We're starting to see some new GitHub repos appear with a default branch of
main
instead ofmaster
. This is a problem as we're currently assuming the branch namemaster
in some of the image links. So this needs some thinking about.Three options that immediately spring to mind:
main
branch (this might be the quickest fix, but I want to do something cleverer in the medium term)master
as the default branch (but I really want to avoid authors having to list their modules if I can possibly avoid it)And then there's a wider question of whether authors want to see results for branches other than the default branch.