Skip to content

fix: use the repository default branch in the GitHub connector - #6800

Merged
timothycarambat merged 2 commits into
Mintplex-Labs:masterfrom
Enesuygurs:fix/github-default-branch
Oct 21, 2026
Merged

timothycarambat merged 2 commits into
Mintplex-Labs:masterfrom
Enesuygurs:fix/github-default-branch

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

Pull Request Type

  • ✨ feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #6799

Description

GitHubRepoLoader auto-assigns a branch when none is given or the given one does not exist on the remote. It picked main or master without looking at the repository, so a repository with a different default branch got either another branch or one that does not exist. For mrdoob/three.js (default branch dev, plus a release-only master), the loader resolved to master.

This adds fetchDefaultBranch(), which reads default_branch from GET /repos/{owner}/{repo} on the resolved API root, so it works for github.com, GitHub Enterprise Server and GHE.com alike. #validBranch() now prefers that branch the same way GiteaRepoLoader already does, and falls back to main/master as before when the metadata cannot be read. An explicitly provided branch that exists is kept, and the extra request is skipped.

Tests: mockGithubApi now serves the repository metadata endpoint, and a new GitHubRepoLoader branch resolution block mirrors the Gitea tests:

  • an explicit branch is kept without the metadata lookup
  • the default branch is used when no branch is given, or the given one does not exist
  • the lookup goes to the Enterprise Server API root
  • main and then master are used when the metadata request fails

Three of the six tests fail without the change.

Visuals (if applicable)

N/A

Additional Information

I also checked this against the live GitHub API with mrdoob/three.js: init() without a branch resolves to master before the change and to dev after it.

Validation (Node 26.5.0, Windows):

  • GithubRepo.test.js: 40 of 40 tests pass.
  • The collector test suites: 418 of 421 tests pass. The 3 failures are in WhisperProviders/ffmpeg and fail the same way on an unmodified checkout, since ffmpeg is not installed on this machine.
  • yarn lint:check in collector, the only package this touches, passes. I did not run the root yarn lint or a Docker build.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

…s back

GitHubRepoLoader picked main or master whenever no branch was given or the
given branch did not exist on the remote, without checking the repository.
A repository with a different default branch got another branch or one that
does not exist; mrdoob/three.js, for example, resolved to its release-only
master instead of dev.

Read default_branch from the repository metadata on the resolved API root
and prefer it, falling back to main/master when the lookup fails, the same
way GiteaRepoLoader already does.
The connector UI preselects the first branch returned, which was always
main/master, so the init fallback alone never changed what users imported.
getRepoBranches now lists default_branch first, init only looks it up when
the requested branch is missing, and the token is validated before the
branch list is fetched.
@timothycarambat

Copy link
Copy Markdown
Member

Thanks @Enesuygurs, the fetchDefaultBranch() lookup was the right building block. I pushed a commit on top (e4e65af) because the init fallback alone doesn't change what users import:

  • The UI always submits a branch. The connector's dropdown preselects the first branch that getRepoBranches() returns, and #branchPrefSort always put main/master first. For three.js the user submits master, it exists, and #validBranch() returns early before the fallback runs. getRepoBranches() now lists default_branch first, so dev is preselected.
  • The "branch list failed to load" case still landed on master. When listing fails, this.branches is [], so branches.includes(defaultBranch) was always false. The fallback now trusts the metadata's default_branch directly and uses main/master only when that lookup fails too.
  • Same request cost on the happy path. Branch paging moved into a private #fetchBranches(), so init() with an existing branch (e.g. every per-file resync) makes no metadata request. getRepoBranches() also skips the lookup when no branches load.
  • Tests now cover dropdown ordering (default first, fallback ordering on 404/500, a default branch missing from the list, enterprise API root), the init fallbacks, and an invalid token being dropped before the branch list is requested.

Live against mrdoob/three.js: the dropdown and init() both resolve to dev (both were master before).

@timothycarambat timothycarambat changed the title fix: use the repository default branch when the GitHub connector falls back fix: use the repository default branch in the GitHub connector Oct 21, 2026
@timothycarambat
timothycarambat merged commit 1aec023 into Mintplex-Labs:master Oct 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: GitHub data connector falls back to master instead of the repository's default branch

2 participants