Skip to content

suggest-commit-title-limit - Fix length limit on new PRs - #7728

Merged
fregante merged 13 commits into
refined-github:mainfrom
karlhorky:fix-suggest-commit-title-limit-early-warning
Aug 23, 2024
Merged

fregante merged 13 commits into
refined-github:mainfrom
karlhorky:fix-suggest-commit-title-limit-early-warning

Conversation

@karlhorky

Copy link
Copy Markdown
Contributor

async function validatePrTitle({delegateTarget: field}: DelegateEvent<Event, HTMLInputElement>): Promise<void> {
// Include the PR number in the title length calculation because it will be added to the commit title
field.classList.toggle('rgh-title-over-limit', formatPrCommitTitle(field.value).length > limit);
const prTitle = await formatPrOrCompareCommitTitle(field.value);

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.

by the way API calls are automatically cached (in RAM), so this should be instant after the first input event

@karlhorky

Copy link
Copy Markdown
Contributor Author

I'm having trouble understanding the output of the Vitest failures:

> vitest
> vitest --run --exclude build/features* --exclude **/selectors*


 RUN  v2.0.5 /home/runner/work/refined-github/refined-github

(node:18[6](https://github.com/refined-github/refined-github/actions/runs/10509515097/job/29115903313?pr=7728#step:5:7)2) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1864) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1861) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 ❯ source/github-helpers/prevent-link-loss.test.ts  (0 test)
 ❯ source/github-helpers/get-current-git-ref.test.ts  (0 test)
 ❯ source/github-helpers/github-file-url.test.ts  (0 test)
(node:1933) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1931) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 ❯ source/github-helpers/index.test.ts  (0 test)
 ❯ test/shorten-link.test.ts  (0 test)
 ✓ source/helpers/show-whitespace-on-line.test.ts  (3 tests) 39ms
 ✓ source/github-helpers/search-query.test.ts  (14 tests) 8ms
 ✓ source/github-helpers/parse-backticks.test.ts  (1 test) 2ms
 ✓ source/helpers/feature-utils.test.ts  (1 test) 3ms
 ✓ source/helpers/clean-commit-message.test.ts  (1 test) 4ms
 ✓ source/helpers/is-low-quality-comment.test.ts  (1 test) 3ms
 ✓ source/github-helpers/pr-branches.test.ts  (1 test) 5ms
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
 ✓ source/helpers/get-items-between.test.ts  (1 test) 3ms
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
 ✓ source/feature-renames.test.ts  (2 tests) 136ms
 ✓ source/github-helpers/hotkeys.test.ts  (3 tests) 4ms
 ✓ source/github-helpers/bugs-label.test.ts  (1 test) 4ms
 ✓ build/readme-parser.test.ts  (1 test) 42ms
 ✓ source/helpers/pr-commit-cleaner.test.ts  (1 test) 3ms
 ✓ source/helpers/calculate-css-calc-string.test.ts  (1 test) 4ms
 ✓ source/helpers/pluralize.test.ts  (1 test) 1ms
stderr | source/helpers/caller-id.test.ts > getCallerID: getStackLine
The stack doesn’t have the line { line: 42, stack: 'Error: Get stack\nA\nB' }

 ✓ source/helpers/caller-id.test.ts  (1 test) [7](https://github.com/refined-github/refined-github/actions/runs/10509515097/job/29115903313?pr=7728#step:5:8)ms
 ✓ source/helpers/loose-parse-int.test.ts  (1 test) 3ms

⎯⎯⎯⎯⎯⎯ Failed Suites 5 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/shorten-link.test.ts [ test/shorten-link.test.ts ]
 FAIL  source/github-helpers/get-current-git-ref.test.ts [ source/github-helpers/get-current-git-ref.test.ts ]
 FAIL  source/github-helpers/github-file-url.test.ts [ source/github-helpers/github-file-url.test.ts ]
 FAIL  source/github-helpers/index.test.ts [ source/github-helpers/index.test.ts ]
 FAIL  source/github-helpers/prevent-link-loss.test.ts [ source/github-helpers/prevent-link-loss.test.ts ]
TypeError: Method Promise.prototype.then called on incompatible receiver [object Module]
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/5]⎯

 Test Files  5 failed | [17](https://github.com/refined-github/refined-github/actions/runs/10509515097/job/29115903313?pr=7728#step:5:18) passed (22)
      Tests  35 passed (35)

@fregante

Copy link
Copy Markdown
Member

I opened an issue for rg, but I don't know what's up with .then, you might have to google a bit.

Comment thread source/github-helpers/index.ts Resolved
@karlhorky

Copy link
Copy Markdown
Contributor Author

I opened an issue for rg, but I don't know what's up with .then, you might have to google a bit.

Not sure that's actually causing the Vitest failures, see this successful test run from 1 hour ago (logs below) where the rg: not found message is also present, but the Vitest tests succeed:

> vitest
> vitest --run --exclude build/features* --exclude **/selectors*


 RUN  v2.0.5 /home/runner/work/refined-github/refined-github

(node:1863) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1860) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1859) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 ✓ source/github-helpers/prevent-link-loss.test.ts  (3 tests) 5ms
 ✓ source/github-helpers/get-current-git-ref.test.ts  (2 tests) 7ms
 ✓ source/github-helpers/github-file-url.test.ts  (7 tests) 13ms
(node:1929) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1941) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 ✓ source/github-helpers/index.test.ts  (4 tests) 13ms
 ✓ test/shorten-link.test.ts  (5 tests) 13ms
 ✓ source/helpers/show-whitespace-on-line.test.ts  (3 tests) 41ms
 ✓ source/github-helpers/search-query.test.ts  (14 tests) 10ms
 ✓ source/github-helpers/parse-backticks.test.ts  (1 test) 4ms
 ✓ source/helpers/feature-utils.test.ts  (1 test) 2ms
 ✓ source/helpers/is-low-quality-comment.test.ts  (1 test) 5ms
 ✓ source/helpers/clean-commit-message.test.ts  (1 test) 2ms
 ✓ source/github-helpers/pr-branches.test.ts  (1 test) 4ms
/bin/sh: 1: rg: not found
 ✓ source/helpers/get-items-between.test.ts  (1 test) 4ms
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
/bin/sh: 1: rg: not found
 ✓ source/feature-renames.test.ts  (2 tests) 118ms
 ✓ source/github-helpers/hotkeys.test.ts  (3 tests) 4ms
 ✓ build/readme-parser.test.ts  (1 test) 30ms
 ✓ source/github-helpers/bugs-label.test.ts  (1 test) 5ms
 ✓ source/helpers/pr-commit-cleaner.test.ts  (1 test) 3ms
 ✓ source/helpers/pluralize.test.ts  (1 test) 3ms
 ✓ source/helpers/calculate-css-calc-string.test.ts  (1 test) 3ms
stderr | source/helpers/caller-id.test.ts > getCallerID: getStackLine
The stack doesn’t have the line { line: 42, stack: 'Error: Get stack\nA\nB' }

 ✓ source/helpers/caller-id.test.ts  (1 test) 6ms
 ✓ source/helpers/loose-parse-int.test.ts  (1 test) 2ms

 Test Files  22 passed (22)
      Tests  56 passed (56)
   Start at  14:20:45
   Duration  3.23s (transform 469ms, setup 2.77s, collect 1.34s, tests 297ms, environment 4ms, prepare 1.80s)

@karlhorky

Copy link
Copy Markdown
Contributor Author

What looks potentially more interesting are these error messages here from the failing workflow run:

⎯⎯⎯⎯⎯⎯ Failed Suites 5 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/shorten-link.test.ts [ test/shorten-link.test.ts ]
 FAIL  source/github-helpers/get-current-git-ref.test.ts [ source/github-helpers/get-current-git-ref.test.ts ]
 FAIL  source/github-helpers/github-file-url.test.ts [ source/github-helpers/github-file-url.test.ts ]
 FAIL  source/github-helpers/index.test.ts [ source/github-helpers/index.test.ts ]
 FAIL  source/github-helpers/prevent-link-loss.test.ts [ source/github-helpers/prevent-link-loss.test.ts ]
TypeError: Method Promise.prototype.then called on incompatible receiver [object Module]
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/5]⎯

I could try to track down any .then() calls, but I was wondering if there's an easier / more understandable way to read this test output. Maybe a different test reporter or something...

@karlhorky

karlhorky commented Aug 22, 2024 •

Copy link
Copy Markdown
Contributor Author

@fregante So the confusing Vitest test failures start as soon as api is imported in source/github-helpers/index.ts.

Minimal reproduction:

source/github-helpers/index.ts

import {$, elementExists, expectElement} from 'select-dom';
import onetime from 'onetime';
import elementReady from 'element-ready';
import compareVersions from 'tiny-version-compare';
import {RequireAtLeastOne} from 'type-fest';
import * as pageDetect from 'github-url-detection';
import mem from 'memoize';

+import api from './api.js';
import {branchSelector} from './selectors.js';

+console.log(api);

This causes test failures of unrelated features eg. prevent-link-loss because of these imports:

  • source/github-helpers/prevent-link-loss.test.ts import from source/github-helpers/prevent-link-loss.ts
  • source/github-helpers/prevent-link-loss.ts imports from source/github-helpers/index.ts

Maybe there is some dependency in source/github-helpers/api.ts that is causing it to fail if imported in this file?

@karlhorky

karlhorky commented Aug 22, 2024 •

Copy link
Copy Markdown
Contributor Author

@fregante a possible fix for the Vitest tests is to switch from static import to dynamic import(), in case this is ok:

// ...

-import api from './api.js';
import {branchSelector} from './selectors.js';

// This never changes, so it can be cached here
export const getUsername = onetime(pageDetect.utils.getUsername);
export const {getRepositoryInfo: getRepo, getCleanPathname} = pageDetect.utils;

export function getConversationNumber(): number | undefined {
	const [, _owner, _repo, type, prNumber] = location.pathname.split('/');
	return (type === 'pull' || type === 'issues') && Number(prNumber) ? Number(prNumber) : undefined;
}

export async function getNextConversationNumber(): Promise<number> {
+	const api = (await import('./api.js')).default;
	const issues = await api.v3('issues?per_page=1');
	return issues[0].number;
}

Implemented in da7b5b9...763ac0e

@fregante

Copy link
Copy Markdown
Member

So yes the issue is about circular references. The solution would be to move this helper out of index.ts and into its own file. import() may cause additional bundles to be generated and we don’t want that.

@karlhorky

karlhorky commented Aug 22, 2024 •

Copy link
Copy Markdown
Contributor Author

Done in 324602c...89b0a6e

@fregante fregante left a comment

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.

Thank you!

@fregante fregante changed the title suggest-commit-title-limit - Retrieve number for compare pages suggest-commit-title-limit - Fix length estimate limit Aug 22, 2024
@karlhorky

Copy link
Copy Markdown
Contributor Author

Thanks for the guidance, review and merge!

@fregante fregante changed the title suggest-commit-title-limit - Fix length estimate limit suggest-commit-title-limit - Fix length limit on new PRs Aug 22, 2024
@fregante fregante added the bug label Aug 22, 2024
@fregante
fregante merged commit 978386a into refined-github:main Aug 23, 2024
@karlhorky
karlhorky deleted the fix-suggest-commit-title-limit-early-warning branch August 23, 2024 19:17
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.

2 participants