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

Further improve branch getter function #4187

Closed
wants to merge 42 commits into from
Closed

Further improve branch getter function #4187

wants to merge 42 commits into from

Conversation

yakov116
Copy link
Member

@yakov116 yakov116 commented Apr 1, 2021

Fixes #4196
Fixes #4271

@fregante fregante added the bug label Apr 1, 2021
@fregante
Copy link
Member

fregante commented Apr 1, 2021

@fregante please let me know if we should stop the next release

Good idea, disabled.

Its not in the head of the page so...

That kills the cat.

Ensure 2 things:

  • If the element isn't found, the feature still works, somehow
  • If the element isn't found, use console.warn to alert us

@yakov116
Copy link
Member Author

yakov116 commented Apr 1, 2021

  • If the element isn't found, the feature still works, somehow

This is going to be very hard its used in 15 features.

@fregante
Copy link
Member

fregante commented Apr 1, 2021

Does this PR also fix #4178?

@yakov116
Copy link
Member Author

yakov116 commented Apr 1, 2021

No that is isPrFiles

@yakov116 yakov116 changed the title Fix GitHubURL - excluding PR Files Fix GitHubURL - Not DOM ready safe Apr 1, 2021
@yakov116
Copy link
Member Author

yakov116 commented Apr 1, 2021

@fregante ok I figured out a way to make this DOM safe in most cases. The title has the word ' at ' in it on many pages.

But I dont know regex so I wrote it...

@fregante
Copy link
Member

fregante commented Apr 1, 2021

One thing to note is that this function only really needs the branch to support branches with slashes. In every other case we really don’t care if it exists or not, it makes no difference (if I remember correctly). So in most cases the branch parser can return undefined and the feature should still work.

@yakov116
Copy link
Member Author

yakov116 commented Apr 1, 2021

One thing to note is that this function only really needs the branch to support branches with slashes. In every other case we really don’t care if it exists or not, it makes no difference (if I remember correctly). So in most cases the branch parser can return undefined and the feature should still work.

I think you are correct

@fregante fregante self-assigned this Apr 2, 2021
@fregante fregante mentioned this pull request Apr 2, 2021
1 task
@fregante
Copy link
Member

fregante commented Apr 2, 2021

Probably my PR will have to be integrated with this. I visited https://github.com/eslint/eslint and there's zero mention of master in the raw HTML request, which means everything is deferred.

Generally this is not a problem, but getCurrentBranch is used by getDefaultBranch so either we await the DOM in that case or just let it do a query.

@fregante
Copy link
Member

fregante commented Apr 2, 2021

just let it do a query

That's what #4190 is doing at the moment.

This PR can be merged in the next version, if relevant

@fregante
Copy link
Member

fregante commented Apr 3, 2021

Parts of this have been added by #4193. Here I'm hoping that we can use the DOM to fill in the details in the remaining case:

This is because on that page:

  • there's no branch selector
  • there's no branch mentioned in the title

@fregante fregante changed the title Fix GitHubURL - Not DOM ready safe Further improve branch getter function Apr 3, 2021
@yakov116
Copy link
Member Author

yakov116 commented Apr 5, 2021

Oh man this is not going to be a fun merge

@yakov116
Copy link
Member Author

🤷 I don't know

@yakov116
Copy link
Member Author

@fregante I tried last night again to figure this out, with no luck.

I don't care to close and let someone else attempt. Please do as you see fit.

@fregante
Copy link
Member

What’s missing here other than the open reviews?

Also if it’s used by any feature (and if it doesn’t already work), on the file editing page there’s a new place to read the branch name from. https://twitter.com/natfriedman/status/1383169134096093187?s=21

@yakov116
Copy link
Member Author

What’s missing here other than the open reviews?

The tests, I cant figure out how to make it pass.

source/features/index.tsx Outdated Show resolved Hide resolved
@@ -3,6 +3,8 @@ import test from 'ava';
import './fixtures/globals';
import GitHubURL from '../source/github-helpers/github-url';

document.head.insertAdjacentHTML('beforeend', '<a hidden="" data-hotkey="t" data-pjax="true" href="https://github.com/avajs/ava/find/master"></a>');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document.head.insertAdjacentHTML('beforeend', '<a hidden="" data-hotkey="t" data-pjax="true" href="https://github.com/avajs/ava/find/master"></a>');
document.head.insertAdjacentHTML('beforeend', '<a hidden="" data-hotkey="t" data-pjax="true" href="https://github.com/sindresorhus/refined-github/find/Slash%2Fslash"></a>');

Copy link
Member

@fregante fregante Apr 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this and the .remove() call can't be here. They need to be inside the test() function that uses it

@@ -34,9 +34,35 @@ export const getCurrentCommittish = (pathname = location.pathname, title = docum
return parsedTitle.groups!.branch;
}

// TODO [2021-04-12]: .last needed for #2799 // GHE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO [2021-04-12]: .last needed for #2799 // GHE
// TODO [2021-08-12]: .last needed for #2799 // GHE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh god. Hah I meant to write the same day, but in 2022

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add unicorn/expiring-todo-comments: warn in the xo settings? I don't want it to automatically fail lint.

@@ -289,7 +291,7 @@ test('getCurrentCommittish', t => {
t.is(getCurrentCommittish(
'/typescript-eslint/typescript-eslint/commits/chore/lerna-4/docs/getting-started/README.md',
'History for docs/getting-started/README.md - typescript-eslint/typescript-eslint'
), 'chore'); // Wrong, but
), 'master'); // Uses the feedlink
Copy link
Member

@fregante fregante Apr 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only shows that the test is wrong, and thus useless.

For this to be tested correctly, it should have the correct feedLink, added and removed just for this test like we do for data-hotkey="t" (including the code to add it before the test)

Suggested change
), 'master'); // Uses the feedlink
), 'chore/lerna-4');
document.querySelector('the feed link')!.remove();

@fregante
Copy link
Member

fregante commented Apr 24, 2021

I'm closing this PR because extremely long. Please send a new one if you have time, resolving all the review comments and squashing the commits. Or leave it for someone else because we've gone over the same code several times.

@fregante fregante closed this Apr 24, 2021
@yakov116 yakov116 deleted the githuburl branch April 25, 2021 01:31
@yakov116
Copy link
Member Author

I'm closing this PR because extremely long. Please send a new one if you have time, resolving all the review comments and squashing the commits. Or leave it for someone else because we've gone over the same code several times.

I will leave it for someone else.

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