-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix K2 for new GitHub UI #226
Conversation
Made this version 1.4.0 (minor version bump), as it's quite a big change. |
src/js/lib/pages/github/pr.js
Outdated
$('div[data-testid="mergebox-partial"] > div > div > section:last-of-type h3') | ||
.text('You cannot merge your own PR'); | ||
$('div[data-testid="mergebox-partial"] > div > div > section:last-of-type p') | ||
.html('It\'s like giving yourself a high-five in public.'); |
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.
🤩
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'm gonna install this and test it out today!
It looks like the issue owner feature isn't working quite right. Bug 1Steps taken:
Expected outcome:The star next to my name should now be yellow to indicate that I am the issue owner Actual outcome:All the stars remain uncolored |
Bug 2Steps Taken:
Expected OutcomeThe old owner should be removed and the new owner should be added. Actual OutcomeThe markdown in the GH description contains duplicate |
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.
Thanks, looks good. Please add test steps and make sure everything changed is working. I see Tim found some bugs.
Hm, that's weird, I tested the stars earlier today and they were working fine. I'll take another look and see if I can fix that! Thanks for reporting. |
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.
Thanks for fixing this!
src/js/lib/pages/github/_base.js
Outdated
@@ -47,11 +45,11 @@ export default function () { | |||
Page.setup = function () {}; | |||
|
|||
Page.getRepoOwner = function () { | |||
return $('.author a span').text(); | |||
return document.querySelectorAll('.AppHeader-context-item-label.Truncate-text')[0].textContent.trim(); |
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.
NAB, I wonder if we could keep the repeatedly used selectors as constant with meaningful names of what we are selecting - For example - const selectorForRepoLabel = '.AppHeader-context-item-label.Truncate-text';
, so next time github changes UI, we could simply change the constant instead of going all over the code, and hopefully it should be simple to transition and works 🙏
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.
For sure, I agree with that. Once we get this PR of the gate I'll spend some time to reorganize the selectors a little bit.
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.
That would be great. Thank you!!
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.
NAB ➕ I would also like to see this. Is it easy enough to do in this PR?
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 repeating selectors are now removed, but I've added a bunch of comments for existing selectors to clarify what exactly they are selecting.
I chose comments over variables to not have to introduce additional null checks to satisfy ESLint for selectors that turn out empty.
A few new changes:
{
'@lwc/lwc/no-async-await': 'off',
'es/no-nullish-coalescing-operators' : 'off'
} |
Small bug fix, but ready for review now. |
Co-authored-by: Tim Golen <[email protected]>
@tgolen reverted the previous assignee setting functions and fixed the K2 label selectors, would you mind giving a spin again? |
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.
One small fix please. Other than that it looks good assuming testing passes. Can you please write test steps even if it's just "load the K2 extension from this branch and test all features"?
src/js/lib/pages/github/_base.js
Outdated
console.error(`Failed to load contents of ${checklistUrl}: ${response.statusText}`); | ||
return; | ||
} | ||
|
||
const fileContents = await response.text(); | ||
|
||
if (!fileContents) { | ||
console.error(`Could not load contents of ${checklistUrl} for some reason`); | ||
return; |
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.
In these error cases we should revert the loader. So instead of logging and returning we could throw an error and have the catch and finally block handle things.
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.
This was the original code moved to a different function, but I changed it to:
try {
// Fetch the checklist contents
const response = await fetch(checklistUrl);
const fileContents = await response.text();
// Call the API to add the comment
await API.addComment(fileContents);
} catch (error) {
console.error('Error fetching the checklist:', error);
} finally {
// Restore the original button content
button.innerHTML = originalContent;
}
this way the loader will always be reverted, and:
- If
fetch()
returns something other than 200, it will throw anyway - If fetched text is empty, then
API.addComment()
will throw due to incorrect parameters
So all error cases are covered now.
src/js/lib/pages/github/_base.js
Outdated
@@ -47,11 +45,11 @@ export default function () { | |||
Page.setup = function () {}; | |||
|
|||
Page.getRepoOwner = function () { | |||
return $('.author a span').text(); | |||
return document.querySelectorAll('.AppHeader-context-item-label.Truncate-text')[0].textContent.trim(); |
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.
NAB ➕ I would also like to see this. Is it easy enough to do in this PR?
@neil-marcellini basic test steps added and all change requests were addressed |
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.
Good to go! Thanks for your hard work.
The new javascript selectors are looking nasty, unfortunately the new GitHub UI has a lot of random, unreliable class names that we can't really attach to. This the best I could do in a short timespan.
I hope they won't shift the UI around once again.
Testing
npm run build:chrome
ornpm run build:firefox
dist.zip
file withnpm run package
about:debugging
)