PerlToolsTeam / dashboard

Simple code build dashboard
18 stars 28 forks source link

master vs main #39

Closed davorg closed 1 year ago

davorg commented 3 years ago

We're starting to see some new GitHub repos appear with a default branch of main instead of master. This is a problem as we're currently assuming the branch name master in some of the image links. So this needs some thinking about.

Three options that immediately spring to mind:

And then there's a wider question of whether authors want to see results for branches other than the default branch.

szabgab commented 3 years 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
davorg commented 3 years ago

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.

davorg commented 3 years ago

See https://github.com/davorg/dashboard/commit/45e33ce2b413f04c239c40406129a59e63192a2b

perlpunk commented 3 years ago

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
szabgab commented 3 years ago

BTW @perlpunk why do you need both greps? As I can see either one of those would work

perlpunk commented 3 years ago

@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$'
davorg commented 1 year ago

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