Skip to content

Fix prevent-pr-commit-link-loss - #3223

Merged
fregante merged 12 commits into
masterfrom
fix-pr-loss
Jun 16, 2020
Merged

fregante merged 12 commits into
masterfrom
fix-pr-loss

Conversation

@fregante

@fregante fregante commented Jun 12, 2020 •

Copy link
Copy Markdown
Member

Blinking message

Fixes #3085 (comment)

  1. Paste https://github.com/sindresorhus/refined-github/pull/3085/commits/a7b1a8bd85c230ff9ff8e407ca8f6d3646c90eb6 in a field
  2. Type something else
  3. The message should appear and not blink at every keypress

URLs with hashes

Fixes #3222

  1. Paste https://github.com/sindresorhus/refined-github/pull/3205/commits/1da152b3f8c51dd72d8ae6ad9cc96e0c2d8716f5#diff-932095cc3c0dff00495b4c392d78f0afR60 in a field
  2. Click Fix link
  3. The resulting link should include the #diff- etc cetera part

Debounces

This should avoid slowing down typing long comments (regardless of broken links)

  1. Enter a broken URL
  2. Start typing right away
  3. The message should not appear until you stop typing (but the debounce timer is short)

Shorten URL

Since we're creating a custom link, we might as well make it look good for everyone

  1. Paste https://github.com/sindresorhus/refined-github/pull/3085/commits/a7b1a8bd85c230ff9ff8e407ca8f6d3646c90eb6 in a field

  2. Click Fix link

  3. The link should appear as

    [`1da152b` (#3205)](https://github.com/sindresorhus/refined-github/pull/3205/commits/1da152b3f8c51dd72d8ae6ad9cc96e0c2d8716f5) 

Note: the hash doesn't appear in this shortened version... but it's no biggie IMHO

@fregante fregante added the bug label Jun 12, 2020
@fregante

This comment has been minimized.

@fregante
fregante marked this pull request as ready for review June 13, 2020 17:59
@fregante
fregante marked this pull request as draft June 13, 2020 18:09
fregante added 2 commits June 13, 2020 20:15
I don't think it's possible to both look for an optional string and exclude whole strings that are followed by a paren, so I had to move that logic outside the regex
@fregante

Copy link
Copy Markdown
Member Author

Successful test with 06d10f3 (#3223)

@fregante fregante closed this Jun 13, 2020
@fregante fregante reopened this Jun 13, 2020
@fregante
fregante marked this pull request as ready for review June 13, 2020 18:57

const escapeRegex = (string: string) => string.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
export const prCommitRegex = new RegExp(`\\b${escapeRegex(location.origin)}[/][^/]+[/][^/]+[/]pull[/]\\d+[/]commits[/][0-9a-f]{7,40}\\b(?! \\]|\\))`, 'gi');
const prCommitPathnameRegex = /[/][^/]+[/][^/]+[/]pull[/](\d+)[/]commits[/]([\da-f]{7})[\da-f]{33}(?:#[\w-]+)?\b/; // eslint-disable-line unicorn/better-regex

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you use [/] instead of \/?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I generally find them easier to follow. Example, how long does it take to understand what this regex matches?

/^\/\/\*\??/
[] equivalent
/^[/][/][*][?]?/

matches

'//*?' or '//*'

@fregante
fregante merged commit 5fb374f into master Jun 16, 2020
@fregante
fregante deleted the fix-pr-loss branch June 16, 2020 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

prevent-pr-commit-link-loss doesn't respect URL hash

2 participants