Skip to content

Commit 3a91f60

Browse files
CopilotTylerJDev
andauthored
Address review feedback: schema version, node engine, repo URL parsing
Co-authored-by: TylerJDev <26746305+TylerJDev@users.noreply.github.com>
1 parent c2b6d64 commit 3a91f60

4 files changed

Lines changed: 54 additions & 5 deletions

File tree

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
2+
"$schema": "https://unpkg.com/@changesets/config@4.0.0/schema.json",
33
"changelog": ["@changesets/changelog-github", {"repo": "github/remote-input-element"}],
44
"commit": false,
55
"fixed": [],

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- uses: actions/setup-node@v4
2727
with:
28-
node-version: 18
28+
node-version: 22
2929
registry-url: https://registry.npmjs.org
3030

3131
- name: Install dependencies

scripts/prepare-release.mjs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ export function getCommitsSinceTag(range, cwd, repository) {
8080
return entries
8181
}
8282

83+
// Normalizes the `repository` field of package.json (which may be a plain
84+
// "owner/repo" shorthand string, a full git/https URL string, or an object
85+
// with a `url` property) into a plain "owner/repo" string suitable for
86+
// building GitHub URLs.
87+
export function normalizeRepository(repository) {
88+
const raw = typeof repository === 'string' ? repository : repository?.url
89+
if (!raw) {
90+
throw new Error('Unable to determine the GitHub "owner/repo" from package.json\'s "repository" field.')
91+
}
92+
93+
// Plain "owner/repo" shorthand, e.g. "github/remote-input-element".
94+
if (/^[^/\s:]+\/[^/\s]+$/.test(raw)) {
95+
return raw
96+
}
97+
98+
// A GitHub URL (git/https/ssh), e.g.
99+
// "git+https://github.com/owner/repo.git" or "git@github.com:owner/repo.git".
100+
const match = raw.match(/(?:^|\/\/|@)github\.com[:/]([^/\s]+\/[^/\s]+?)(?:\.git)?\/?$/)
101+
if (!match) {
102+
throw new Error(`Unable to parse a GitHub "owner/repo" from repository field: ${JSON.stringify(raw)}`)
103+
}
104+
return match[1]
105+
}
106+
83107
function parseCommit({sha, subject, body}, repository) {
84108
const shortSha = sha.slice(0, 7)
85109
const mergeMatch = subject.match(/^Merge pull request #(\d+) from/)
@@ -151,15 +175,16 @@ export function prepareRelease({cwd = process.cwd()} = {}) {
151175
}
152176

153177
const range = `${tag}..HEAD`
154-
const entries = getCommitsSinceTag(range, cwd, pkg.repository)
178+
const repository = normalizeRepository(pkg.repository)
179+
const entries = getCommitsSinceTag(range, cwd, repository)
155180
if (entries.length === 0) {
156181
if (existsSync(autoChangesetPath)) {
157182
rmSync(autoChangesetPath)
158183
}
159184
return {action: 'skipped-no-changes', tag}
160185
}
161186

162-
const content = buildChangesetContent(pkg.name, entries, pkg.repository)
187+
const content = buildChangesetContent(pkg.name, entries, repository)
163188
writeFileSync(autoChangesetPath, content)
164189
return {action: 'created', tag, path: autoChangesetPath, entries}
165190
}

scripts/prepare-release.test.mjs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import os from 'node:os'
55
import path from 'node:path'
66
import {test, describe, beforeEach, afterEach} from 'node:test'
77

8-
import {prepareRelease, AUTO_CHANGESET_FILENAME} from './prepare-release.mjs'
8+
import {prepareRelease, AUTO_CHANGESET_FILENAME, normalizeRepository} from './prepare-release.mjs'
99

1010
function git(args, cwd) {
1111
return execFileSync('git', args, {cwd, encoding: 'utf8'}).trim()
@@ -41,6 +41,30 @@ afterEach(() => {
4141
rmSync(repoDir, {recursive: true, force: true})
4242
})
4343

44+
describe('normalizeRepository', () => {
45+
test('accepts the "owner/repo" shorthand string', () => {
46+
assert.equal(normalizeRepository('github/remote-input-element'), 'github/remote-input-element')
47+
})
48+
49+
test('accepts a full git URL string', () => {
50+
assert.equal(
51+
normalizeRepository('git+https://github.com/github/remote-input-element.git'),
52+
'github/remote-input-element',
53+
)
54+
})
55+
56+
test('accepts an object with a url property', () => {
57+
assert.equal(
58+
normalizeRepository({type: 'git', url: 'https://github.com/github/remote-input-element.git'}),
59+
'github/remote-input-element',
60+
)
61+
})
62+
63+
test('rejects a non-GitHub URL instead of extracting the wrong owner/repo', () => {
64+
assert.throws(() => normalizeRepository('https://notgithub.com/owner/repo'))
65+
})
66+
})
67+
4468
describe('prepareRelease', () => {
4569
test('does nothing when the checked-in version has no matching tag (pending publication)', () => {
4670
writePackageJson(repoDir, '0.4.0')

0 commit comments

Comments
 (0)