Repository navigation
Add netiquette feature
#6427
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
Merged
Merged
Add netiquette feature
#6427
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
67f32a2
Add banner
fregante 717360b
Smaller banner, reuse it
fregante a72f196
It's safer to recreate
fregante 0c3e35e
Update readme.md
fregante ccf220c
Add test URLs
fregante a561ad1
Place above pro-tip
fregante c13a344
Reposition, reuse selector
fregante 300dd0e
Update screenshot
fregante 975dcbf
"This PR"
fregante 85d40b1
Move above field, leave guidelines info alone
fregante c6da8d5
Update readme.md
fregante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import React from 'dom-chef'; | ||
| import * as pageDetect from 'github-url-detection'; | ||
| import toMilliseconds from '@sindresorhus/to-milliseconds'; | ||
| import select from 'select-dom'; | ||
| import twas from 'twas'; | ||
| import {InfoIcon} from '@primer/octicons-react'; | ||
|
|
||
| import createBanner from '../github-helpers/banner'; | ||
| import features from '../feature-manager'; | ||
| import observe from '../helpers/selector-observer'; | ||
| import {buildRepoURL} from '../github-helpers'; | ||
| import {closedOrMergedMarkerSelector, getLastCloseEvent} from './jump-to-conversation-close-event'; | ||
|
|
||
| const isClosedOrMerged = (): boolean => select.exists(closedOrMergedMarkerSelector); | ||
|
|
||
| /** Returns milliseconds passed since `date` */ | ||
| function timeAgo(date: Date): number { | ||
| return Date.now() - date.getTime(); | ||
| } | ||
|
|
||
| function getCloseDate(): Date { | ||
| const datetime = select('relative-time', getLastCloseEvent())!.getAttribute('datetime')!; | ||
| console.assert(datetime, 'Datetime attribute missing from relative-time'); | ||
| return new Date(datetime); | ||
| } | ||
|
|
||
| const threeMonths = toMilliseconds({days: 90}); | ||
|
|
||
| function addConversationBanner(newCommentField: HTMLElement): void { | ||
| if (!isClosedOrMerged()) { | ||
| return; | ||
| } | ||
|
|
||
| const closingDate = getCloseDate(); | ||
| if (timeAgo(closingDate) < threeMonths) { | ||
| return; | ||
| } | ||
|
|
||
| const ago = <strong>{twas(closingDate.getTime())}</strong>; | ||
| const newIssue = <a href={buildRepoURL('issues/new/choose')}>new issue</a>; | ||
|
|
||
| newCommentField.before( | ||
| createBanner({ | ||
| classes: 'p-2 m-2 text-small color-fg-muted border-0'.split(' '), | ||
| text: ( | ||
| <div className="d-flex flex-items-center gap-2"> | ||
| <InfoIcon className="m-0"/> | ||
| {/* TODO: Drop any after https://github.com/frenic/csstype/issues/177 */} | ||
| <span style={{textWrap: 'balance'} as any}> | ||
| This {pageDetect.isPR() ? 'PR' : 'issue'} was closed {ago}. Please consider opening a {newIssue} instead of leaving a comment here. | ||
| </span> | ||
| </div> | ||
| ), | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| function init(signal: AbortSignal): void { | ||
| observe('#issue-comment-box file-attachment', addConversationBanner, {signal}); | ||
| } | ||
|
|
||
| void features.add(import.meta.url, { | ||
| include: [ | ||
| pageDetect.isConversation, | ||
| ], | ||
| awaitDomReady: true, // We're specifically looking for the last event | ||
| init, | ||
| }); | ||
|
|
||
| /* | ||
|
|
||
| Test URLs | ||
|
|
||
| - Old issue: https://github.com/refined-github/refined-github/issues/3076 | ||
| - Old PR: https://github.com/refined-github/refined-github/pull/159 | ||
|
|
||
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just extracting and reusing selectors