Repository navigation
fix: notify PRs and issues for prerelease versions #431
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
Open
KyleAMathews
wants to merge
1
commit into
TanStack:main
Choose a base branch
from
KyleAMathews:codex/fix-prerelease-comments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { spawnSync } from 'node:child_process' | ||
| import { | ||
| mkdtempSync, | ||
| mkdirSync, | ||
| readFileSync, | ||
| rmSync, | ||
| writeFileSync, | ||
| } from 'node:fs' | ||
| import { tmpdir } from 'node:os' | ||
| import { delimiter, join } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { test } from 'node:test' | ||
|
|
||
| const script = fileURLToPath( | ||
| new URL('./comment-on-release.ts', import.meta.url), | ||
| ) | ||
| const releases = [ | ||
| ['1.0.0', '100'], | ||
| ['1.0.0-rc.1.3', '100-rc13'], | ||
| ['1.0.0-rc.1.4', '100-rc14'], | ||
| ['1.0.0-rc.1.40', '100-rc140'], | ||
| ['1.0.0-beta.1', '100-beta1'], | ||
| ['1.0.0-rc.1.4+build.7', '100-rc14build7'], | ||
| ['1.0.0+build.7', '100build7'], | ||
| ['1.0.0+BUILD.7', '100build7'], | ||
| ].map(([version, anchor], index) => ({ version, anchor, pr: 200 + index })) | ||
|
|
||
| function runAction(version) { | ||
| const root = mkdtempSync(join(tmpdir(), 'release-comments-')) | ||
| try { | ||
| const bin = join(root, 'bin') | ||
| const pkg = join(root, 'packages', 'db') | ||
| const calls = join(root, 'calls.jsonl') | ||
| mkdirSync(bin) | ||
| mkdirSync(pkg, { recursive: true }) | ||
| writeFileSync(calls, '') | ||
| writeFileSync( | ||
| join(pkg, 'CHANGELOG.md'), | ||
| '# @tanstack/db\n\n' + | ||
| releases | ||
| .map( | ||
| ({ version: heading, pr }) => | ||
| `## ${heading}\n\n### Patch Changes\n\n- Fix ([#${pr}](https://github.com/TanStack/db/pull/${pr}))\n`, | ||
| ) | ||
| .join('\n') + | ||
| '\n## Archive\n\n[#999](https://github.com/TanStack/db/pull/999)\n', | ||
| ) | ||
| // Execute the real action, but replace every GitHub operation with a local | ||
| // recorder. The fixture links each PR to the issue numbered 1000 above it. | ||
| writeFileSync( | ||
| join(bin, 'gh'), | ||
| `#!/usr/bin/env node | ||
| const { appendFileSync } = require('node:fs') | ||
| const args = process.argv.slice(2) | ||
| appendFileSync(process.env.RELEASE_COMMENT_CALLS, JSON.stringify(args) + '\\n') | ||
| if (args[0] === 'api' && args[1] === 'graphql') { | ||
| console.log(Number(args.find(arg => arg.startsWith('pr=')).slice(3)) + 1000) | ||
| } else if (args[0] === 'api' && args[1].endsWith('/comments')) { | ||
| console.log('0') | ||
| } else if ((args[0] === 'pr' || args[0] === 'issue') && args[1] === 'comment') { | ||
| // Recorded above; no network operation. | ||
| } else { | ||
| console.error('Unexpected gh call:', args) | ||
| process.exit(1) | ||
| } | ||
| `, | ||
| { mode: 0o755 }, | ||
| ) | ||
| const result = spawnSync(process.execPath, [script], { | ||
| cwd: root, | ||
| encoding: 'utf8', | ||
| env: { | ||
| ...process.env, | ||
| PATH: [bin, process.env.PATH].join(delimiter), | ||
| PUBLISHED_PACKAGES: JSON.stringify([{ name: '@tanstack/db', version }]), | ||
| REPOSITORY: 'TanStack/db', | ||
| GITHUB_REPOSITORY: 'TanStack/db', | ||
| RELEASE_COMMENT_CALLS: calls, | ||
| }, | ||
| }) | ||
| assert.equal(result.status, 0, result.stderr) | ||
| return { | ||
| output: result.stdout + result.stderr, | ||
| calls: readFileSync(calls, 'utf8') | ||
| .split('\n') | ||
| .filter(Boolean) | ||
| .map((line) => JSON.parse(line)), | ||
| } | ||
| } finally { | ||
| rmSync(root, { recursive: true, force: true }) | ||
| } | ||
| } | ||
|
|
||
| for (const { version, anchor, pr } of releases) { | ||
| test(`comments only on the PR and linked issue in the exact ${version} section`, () => { | ||
| const { calls } = runAction(version) | ||
| const comments = calls.filter((args) => args[1] === 'comment') | ||
| assert.deepEqual( | ||
| comments.map((args) => args.slice(0, 3)), | ||
| [ | ||
| ['pr', 'comment', String(pr)], | ||
| ['issue', 'comment', String(pr + 1000)], | ||
| ], | ||
| ) | ||
| for (const args of comments) { | ||
| assert.ok(args[4].includes(`@tanstack/db@${version}`)) | ||
| assert.ok(args[4].includes('has been released!')) | ||
| assert.ok(args[4].includes(`/CHANGELOG.md#${anchor})`)) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| test('does not comment when the published version has no changelog section', () => { | ||
| const { calls, output } = runAction('2.0.0-rc.1') | ||
| assert.deepEqual(calls, []) | ||
| assert.ok(output.includes('Could not find version 2.0.0-rc.1')) | ||
| }) | ||
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
Oops, something went wrong.
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.
Script executed:
Repository: TanStack/config
Length of output: 9878
Script executed:
Repository: TanStack/config
Length of output: 5276
Web query:
Node.js documentation os.tmpdir TMPDIR environment variable nearest package.json type module extensionless files requireResult:
Web query:
Node.js 24 extensionless entry point package.json type module require not definedResult:
Script executed:
Repository: TanStack/config
Length of output: 6013
Give the stub an explicit CommonJS package scope.
If
TMPDIRpoints inside this repository, Node treatsghas an ES module. Itsrequirecall fails, so the test cannot record the expected comments.Set the temporary package type
try { + writeFileSync(join(root, 'package.json'), '{"type":"commonjs"}') const bin = join(root, 'bin')