Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both main and master as default branches #974

Open
xt0rted opened this issue Jul 12, 2020 · 5 comments
Open

Support both main and master as default branches #974

xt0rted opened this issue Jul 12, 2020 · 5 comments
Labels

Comments

@xt0rted
Copy link
Member

xt0rted commented Jul 12, 2020

Recently GitHub announced they were going to be renaming their default branches to main and that this should become the default for new repos too. Other repos have already made the switch.

There's a few spots where the code assumes master as the default.

if (!path.length) {
return [
`{BASE_URL}/${user}/${repo}/blob/master/${repo}.go`,
`{BASE_URL}/${user}/${repo}`,
];
}
const fullPath = path.join('/');
const last = path.slice(-1);
return [
`{BASE_URL}/${user}/${repo}/blob/master/${fullPath}/${last}.go`,
`{BASE_URL}/${user}/${repo}/tree/master/${fullPath}`,
`{BASE_URL}/${user}/${repo}`,
];
}

return [
relativeFile({ path, target }),
`https://github.com/Homebrew/homebrew-core/blob/master/Formula/${target}`,
];

The remaining spots all look to be related to tests.

The GitHub Actions plugin is already handling this but might need to be changed depending on how this is handled going forward.

return [
`{BASE_URL}/${join(org, repo, 'tree', 'main', ...folder)}`,
`{BASE_URL}/${join(org, repo, 'tree', 'master', ...folder)}`,
];

@xt0rted
Copy link
Member Author

xt0rted commented Sep 12, 2020

We might not need to make any changes here. Recently GitHub made an update so links to branches that don't exist redirect to the default branch.

Revisiting the changes in #943, removing the main option from the returned urls and clicking on the link in the test file brings you to the correct url. I'm not sure how the tests will resolve & handle this though.

@jimeh
Copy link

jimeh commented Oct 14, 2021

The redirect from deleted to main branch thing doesn't solve things for new repos which never had a master branch, but instead was created with a main branch.

Also some repos use custom default branches, I'd suggest that OctoLinker should actually lookup what the default branch is for a repo, and use that.

@stefanbuck
Copy link
Member

I agree that looking up what the actual default branch for a repo is would be the ideal solution. However, I'm less sure how to implement this given this requires an API call that needs to be resolved before anything else. Also, for users without a token it could eat up the rate limit quickly. I think we should do a best effort here given that either master or main the default branch in most repositories.

@jimeh
Copy link

jimeh commented Oct 19, 2021

Ah, true, requiring an API for that would be annoying. Maybe it could be somewhat cleaver and look it up if an API key is available, otherwise try master, and if that fails try main? And I assume default branch info could probably be cached rather safely.

@silverwind
Copy link

There is a trick to get the default branch without any guessing involved: Specify HEAD instead of the branch name. For example, this triggers a branch redirection message:

https://github.com/facebook/jest/tree/master/packages/jest-environment-jsdom

But this doesn't:

https://github.com/facebook/jest/tree/HEAD/packages/jest-environment-jsdom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants