Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 94be218

Browse files
committed
no message
1 parent 06af68a commit 94be218

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

scripts/utils/changesets.js

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async function readChangeset(filePath) {
7575
* @returns {Promise<Array>} Array of changeset objects
7676
*/
7777
async function readAllChangesets(options = {}) {
78-
const { branch } = options;
78+
const { branch } = options || {};
7979

8080
// Get all changeset files
8181
const changesetDir = path.join(process.cwd(), '.changesets');
@@ -89,7 +89,7 @@ async function readAllChangesets(options = {}) {
8989
const content = await fs.readFile(filePath, 'utf8');
9090

9191
// Parse the changeset content
92-
const changeset = parseChangeset(content);
92+
const changeset = parseChangesetContent(content);
9393

9494
// Add the filename to the changeset
9595
changeset.filename = file;
@@ -103,22 +103,66 @@ async function readAllChangesets(options = {}) {
103103
// Special case for develop branch - include milestone branch changesets
104104
if (branch === 'develop') {
105105
return changesets.filter(changeset =>
106+
!changeset.branch || // Include changesets without branch info
106107
changeset.branch === branch ||
107-
changeset.branch === undefined || // Include changesets without branch info
108108
changeset.branch.startsWith('milestone/')
109109
);
110110
}
111111

112112
// Otherwise, filter by the specified branch
113113
return changesets.filter(changeset =>
114-
changeset.branch === branch ||
115-
changeset.branch === undefined // Include changesets without branch info
114+
!changeset.branch || // Include changesets without branch info
115+
changeset.branch === branch
116116
);
117117
}
118118

119119
return changesets;
120120
}
121121

122+
/**
123+
* Parse changeset content from a file
124+
*
125+
* @param {string} content The content of the changeset file
126+
* @returns {Object} Parsed changeset object
127+
*/
128+
function parseChangesetContent(content) {
129+
// Use your existing parsing logic here
130+
// This should extract title, PR number, author, type, breaking flag, branch, etc.
131+
// from the changeset content
132+
133+
// Example implementation (adjust based on your actual changeset format):
134+
const lines = content.split('\n');
135+
const changeset = {
136+
title: '',
137+
pr: null,
138+
author: '',
139+
type: 'other',
140+
breaking: false,
141+
branch: undefined,
142+
description: ''
143+
};
144+
145+
// Parse metadata lines (key: value format)
146+
const metadataLines = lines.filter(line => line.includes(':'));
147+
for (const line of metadataLines) {
148+
const [key, value] = line.split(':', 2).map(part => part.trim());
149+
if (key === 'title') changeset.title = value;
150+
else if (key === 'pr') changeset.pr = parseInt(value, 10) || null;
151+
else if (key === 'author') changeset.author = value;
152+
else if (key === 'type') changeset.type = value;
153+
else if (key === 'breaking') changeset.breaking = value === 'true';
154+
else if (key === 'branch') changeset.branch = value;
155+
}
156+
157+
// Extract description (everything after metadata)
158+
const descriptionStartIndex = metadataLines.length;
159+
if (descriptionStartIndex < lines.length) {
160+
changeset.description = lines.slice(descriptionStartIndex).join('\n').trim();
161+
}
162+
163+
return changeset;
164+
}
165+
122166
/**
123167
* Determine the version bump type based on changesets
124168
*

0 commit comments

Comments
 (0)