@@ -68,40 +68,55 @@ async function readChangeset(filePath) {
6868}
6969
7070/**
71- * Read all changesets
71+ * Read all changesets from the .changesets directory
7272 *
73- * @returns {Promise<Object[]> } Array of parsed changesets
73+ * @param {Object } options Options for reading changesets
74+ * @param {string } options.branch Branch to filter changesets by
75+ * @returns {Promise<Array> } Array of changeset objects
7476 */
75- async function readAllChangesets ( branch = null ) {
76- const dir = getChangesetDir ( ) ;
77+ async function readAllChangesets ( options = { } ) {
78+ const { branch } = options ;
7779
78- try {
79- const files = await fs . readdir ( dir ) ;
80- const changesets = await Promise . all ( files . map ( async file => {
81- const filepath = path . join ( dir , file ) ;
82- const content = await fs . readFile ( filepath , 'utf8' ) ;
83- const { data, content : description } = matter ( content ) ;
80+ // Get all changeset files
81+ const changesetDir = path . join ( process . cwd ( ) , '.changesets' ) ;
82+ const files = await fs . readdir ( changesetDir ) ;
83+ const changesetFiles = files . filter ( file => file . endsWith ( '.md' ) ) ;
84+
85+ // Read each changeset file
86+ const changesets = await Promise . all (
87+ changesetFiles . map ( async file => {
88+ const filePath = path . join ( changesetDir , file ) ;
89+ const content = await fs . readFile ( filePath , 'utf8' ) ;
8490
85- return {
86- ...data ,
87- description : description . trim ( ) ,
88- file
89- } ;
90- } ) ) ;
91-
92- if ( branch ) {
91+ // Parse the changeset content
92+ const changeset = parseChangeset ( content ) ;
93+
94+ // Add the filename to the changeset
95+ changeset . filename = file ;
96+
97+ return changeset ;
98+ } )
99+ ) ;
100+
101+ // If branch is specified, filter changesets by branch
102+ if ( branch ) {
103+ // Special case for develop branch - include milestone branch changesets
104+ if ( branch === 'develop' ) {
93105 return changesets . filter ( changeset =>
94- ! changeset . branch || changeset . branch === branch
106+ changeset . branch === branch ||
107+ changeset . branch === undefined || // Include changesets without branch info
108+ changeset . branch . startsWith ( 'milestone/' )
95109 ) ;
96110 }
97111
98- return changesets ;
99- } catch ( error ) {
100- if ( error . code === 'ENOENT' ) {
101- return [ ] ;
102- }
103- throw error ;
112+ // Otherwise, filter by the specified branch
113+ return changesets . filter ( changeset =>
114+ changeset . branch === branch ||
115+ changeset . branch === undefined // Include changesets without branch info
116+ ) ;
104117 }
118+
119+ return changesets ;
105120}
106121
107122/**
0 commit comments