-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Default branch and current branch detector improvements #6636
Conversation
// Slashed branches on `commits`, including pages without a branch picker | ||
const branchFromFeed = getCurrentBranchFromFeed(); | ||
if (branchFromFeed) { | ||
return branchFromFeed; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to drop this, but decided to keep it because there's no branch selector on some commit pages, so this is the only way to get the current branch.
// Slashed branches on `commits` | ||
if (type === 'commits') { | ||
return getCurrentBranchFromFeed()!; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"current" in parametrized function 🙅♂️ 😩
// Slashed branches on `blob` and `tree` | ||
const parsedTitle = titleWithGitRef.exec(title); | ||
if (parsedTitle) { | ||
return parsedTitle.groups!.branch; | ||
} | ||
|
||
// Couldn't ensure it's not slashed, so we'll return the first piece whether correct or not | ||
// TODO: extract from `ref-selector` if available https://github.com/refined-github/refined-github/issues/6557 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No: #6557 (comment)
export const getDefaultBranchOfRepo = cache.function('default-branch', | ||
async (repository: RepositoryInfo): Promise<string> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name clarifies that it refers to a specific repo, not the current repo/page.
Wow this looks like you put in a lot of work! |
And it's not even fixed yet. (branch name Edit: This is because, again and again, we use the "current" state after accepting arguments, this time in GitHubURL: 🥲 refined-github/source/github-helpers/github-url.ts Lines 38 to 40 in 081ae02
Edit: actually I'm not sure that's it. It seems that |
More of #6637 please 🥺 ✌️
Ok, patched up. Time to dance |
Base branch was modified
EDIT: Fixed by # 6 6 4 1
|
Thanks for the reports @DanielMiao1! |
ref-selector
element #6557default-branch-button
#6629A mistake that we keep making is mixing parameterized functions which then ignore the parameters and use the DOM. This must either be made clear by the function name (e.g. "current") or by verifying that the arguments match the current page. Default parameters are the worst because they make us forget this important distinction.
Related: