-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add comment-on-draft-pr-indicator feature
#4520
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
Conversation
There is a detection for isDraft do |
- Followed all suggestions by yakov116 and fregante - Updated the feature screenshot to include the Files tab
| let commentButton; | ||
| if (pageDetect.isPRConversation()) { | ||
| commentButton = select('#partial-new-comment-form-actions .btn-primary'); | ||
| commentButton!.innerHTML = 'Comment to Draft 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.
| let commentButton; | |
| if (pageDetect.isPRConversation()) { | |
| commentButton = select('#partial-new-comment-form-actions .btn-primary'); | |
| commentButton!.innerHTML = 'Comment to Draft PR'; | |
| if (pageDetect.isPRConversation()) { | |
| select('#partial-new-comment-form-actions .btn-primary')!.textContent = 'Comment to Draft PR'; |
Can we use textContent?
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.
yes, but, e.g. for the Conversation tab as in here,
the 'Comment' button textContent is:
\n \n \n Comment\n\n \n\n
and so I'd have to use .replace('Comment, Comment to Draft PR')
instead of putting fixed string (innerHTML = ' Comment to Draft PR ' ).
Are you ok with that?
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.
Its fine don't worry about the '\n'. I just tried it it will work correctly
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Yakov is not suggesting to use replace. Just use = and it works. The whitespace is useless.
Also never use innerHTML because it's flagged by the extension stores, just use textContent
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, I just did.
Btw, I feel once again embarrassed making the same mistakes over and over again..
Could I ask please to add some extra notes/warnings in https://github.com/sindresorhus/refined-github/blob/main/contributing.md to make sure people like me always follow them?
What comes to mind from your reviews to my previous PRs:
- describe the preferable way to sort imports for this repo
- never use
innerHTMLbecause it's flagged by the extension stores. Just usetextContent. - prefer
select(), notquerySelector - with
select(), when having multiple selectors, split them to multiple lines - selectors should be short and smart/concise. Use those class and attributes combinations that are as much specific as possible and don't need almost any other specifiers.
- use ternary
ifwhen possible.
Do you think these "tips" can be useful to contributors, or they are too self-explanatory/beginner level?
I could provide a PR with these of course, but I need your opinion first.
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.
Don't worry too much about these small mistakes. If the PR is salvageable you can learn about the project’s code style over time.
Some of those rules could be part of the contributor guide, but I'd rather have eslint check for them. It's weird that innerHTML isn't already caught by eslint, e.g.
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-text-content.md
https://github.com/salesforce/eslint-plugin-lwc/blob/master/docs/rules/no-inner-html.md
| commentButton = select('#partial-new-comment-form-actions .btn-primary'); | ||
| commentButton!.innerHTML = 'Comment to Draft PR'; | ||
| } else if (pageDetect.isPRFiles()) { | ||
| delegate('.diff-table', 'button', 'click', handleClicks); |
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 don't think that's the right way. We add custom buttons like table-input on the comment forms on the Files tab. You can copy what they use
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.
Sorry, but I don't quite understand.
With this feature, the purpose is to simply change the name of existing buttons,
not (remove the existing ones and) add new buttons with a different name.
Are you suggesting to use .remove() and .after()?
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.
It looks like a plain loop is all that should be needed and GitHub will preserve the changes, no need for onNewComments at all:
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.
Regarding onNewComments:
I tried removing it, but then, in 'Conversations' tab, the 'Comment' button name no longer changes after submitting a new comment. Therefore it seems necessary for the 'Conversations' tab.
Then, I also tried changing
commentButton = select('#partial-new-comment-form-actions .btn-primary');
commentButton!.textContent = 'Comment to Draft PR';to
commentButton = select.all('#partial-new-comment-form-actions .btn-primary');
for (const element of commentButton) {
element.textContent = 'Comment to Draft PR';
}but didn't make any difference.
And regarding my use of delegate:
in 'Files 'tab, e.g. https://github.com/darkred/test/pull/6/files, initially, there's no comment textarea,
and no table:not([style="display: none"]) .review-simple-reply-button/.start-review-label button elements:
these elements only exist after you click a '+' in a row (capture)
therefore I think it's necessary to delegate clicks on the .diff-table element.
You can't loop on these elements, before they exist.
Am I not right? Have I got something wrong?
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.
table-input does not have :not([style="display: none"]) because it's not needed. Same goes for onNewComments in this feature, it shouldn't be needed.
As I tried saying before, there's a "template comment box element" that GitHub clones every time it's needed, including all the changes we make to it. Your selector explicitly excludes this template element. This is also why onNewComments is very likely not needed.
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.
Maybe it needs dontDeduplicate. (I forgot what we called it)
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 the 'Files' tab, onNewComments is indeed not needed:
I had used the :not([style="display: none"]) selector part
because I wrongly thought that these hidden elements shouldn't also match my selector.
It indeed works ok after removing that selector part + onNewComments.
I just removed the selector part.
For the Conversations tab, your are most probably right that onNewComments is not needed as well,
but I tried using any of the selectors below with:
if (pageDetect.isPRConversation()) {
const buttonsComment = select.all('a selector');
for (const element of buttonsComment) {
element.textContent = 'Comment on draft PR';
}
}.timeline-comment .btn-primary.form-actions .btn-primaryform .btn-primarybutton[type="submit"].btn-primary
but unfortunately it still doesn't work after submitting a new comment.
I also tried searching in devtools Inspector for strings such as "Leave a comment" (for the textarea)
or for "Close pull request" (for the button)
hoping to discover such a hidden 'template comment box element' (and get the 'Submit' button selector from inside it), but didn't find anything.
Also, I tried adding the following inside void features.add( but it didn't help:
deduplicate: 'false',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.
Regarding the Conversations tab, maybe this hidden 'template comment box element' contains code only for the editor's toolbar buttons (a button of which, md-task-list, is used as reference in table-input),
but not for the 'Comment' button (or the 'Close pull request' one) too?
I'm claiming this because I couldn't find any such hidden additional button, as I describe in my previous comment.
|
Just a small note as a native English speaker… 😃 I would suggest that the prepositions need to be changed ("to" versus "on"), and I would argue that "draft" rather than "Draft" should be used. "Draft" is being used as an adjective, it looks a bit nicer as lowercase within a sentence (IMO), and that's how GitHub uses it in their docs and UI for sentences, e.g. "Convert to draft", or "… mark a draft pull request as ready …", plus also elsewhere in Refined GitHub.
|
|
Thanks for your comment. Regarding Regarding |
Co-authored-by: Federico Brigante <me@fregante.com>
…ed/refined-github into comment-to-draft-pr-button
Rename the feature
|
With the new commits, I:
|
comment-to-draft-pr-button featurecomment-on-draft-pr-rename-buttons feature
comment-on-draft-pr-rename-buttons featurecomment-on-draft-pr-indicator feature
|
@fregante |
|
You need to follow the reviews if you want to open PRs here, otherwise we're just wasting time. What I suggested works exactly like it works for |
|
I followed all reviews, with the only exception of managing to remove the need for The way your presented the alternative approach, appeared to me as a probability, not a certainty:
and, after my various attempts (with my limited experience compared to you), I came to the result that it wasn't possible. I'm sorry I couldn't make this effort to completion. |
|
@fregante
Also, in your new PR you have this commit message b385a84 :
In that commit, the only significant change is that you removed the With your last review, you suggested that use Yes, I admit my comments are sometimes too verbose/detailed.
But, wouldn't we end up to the same dead-end like in this previous closed PR of mine #4123 (comment)
I see that you made a lot of improvements from your commit 6a30be8 and on, |
|
This was mostly because in this PR a few things had to be repeated several times before being applied, with your focus going on the wrong part of our suggestion. For example you used replace() when Yakov gave you an exact code suggestion that would have just worked, and the table-input suggestion that should have resulted in the thought: “table-input works, why doesn’t it work for the button?” instead of “I doesn’t work for the button, I can’t use it.” Perhaps the easiest way to go about it is to make the requested changes and then show how they don't work in a gif. This way we can see whether the suggestion was attempted correctly. For example if you implemented the loop with the broken selector my suggestion would have been to just drop the selector and it would have worked most of the time. Occasionally suggestions will be wrong though, but that’s the problem with commenting on code without running it. The other problem is that once I have to deal with the code myself, by running it and figure it out, it’s easier to just send a PR myself. And that’s ok sometimes, we can’t merge every PR. Regarding my “probability” suggestion: 😃 Also it would personally help me read your comments if you didn’t add a line break after commas 😂 as that is not customary in English. But that’s just my opinion, man 😜 |
|
Thanks for replying. And about my linebreaks after commas: I know it's not necessary, but I don't even realize that I put commas. The point for me is to have linebreaks, as it seems to me that it makes the text easier to read. I guess I'm wrong, I'll try to avoid it. |
Don't say that at all! Your english is 💯 !
Yeah it's common among programmers, generally I prefer flowing text since the browser will pick the best place to wrap lines. |
|
By the way if you don't mind me asking, are you from Greece? |
|
Yes, I am from Greece. Neighbor of Italy 🙂 |




Closes #3857
Test URLs
Any draft PR, e.g.
https://github.com/darkred/test/pull/6
Screenshot
Note to reviewers:
The selector for the "Draft" label,#partial-discussion-header span[title="Status: Draft"],matches twice in draft PR pages (but none in non-draft ones, of course).
Do I have to make it more specific, nevertheless?