3030
3131 - name : Get latest dates in changelog
3232 run : |
33- # Extrahiere die neuesten zwei Daten aus dem Changelog
3433 DATES=$(grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2}' CHANGELOG.md | head -n 2 | awk '{print $2}')
3534
3635 LATEST_DATE=$(echo "$DATES" | sed -n '1p')
5554 const configPath = path.resolve(process.env.CONFIG_PATH);
5655 const fileContent = await fs.readFile(configPath, 'utf-8');
5756 const changelogConfig = JSON.parse(fileContent);
58- const categorizedPRs = changelogConfig.map(obj => ({ ...obj, notes: [] }));
57+
58+ const categorizedPRs = changelogConfig.map(obj => ({
59+ ...obj,
60+ notes: [],
61+ subCategories: obj.subCategories ?? (obj.labels.includes("update script") ? [
62+ { title: "🐞 Bug Fixes", labels: ["bugfix"] },
63+ { title: "✨ Feature Updates", labels: ["feature"] }
64+ ] : [])
65+ }));
5966
6067 const latestDateInChangelog = new Date(process.env.LATEST_DATE);
6168 latestDateInChangelog.setUTCHours(23, 59, 59, 999);
@@ -70,29 +77,33 @@ jobs:
7077 per_page: 100,
7178 });
7279
73- pulls.filter(pr =>
74- pr.merged_at &&
75- new Date(pr.merged_at) > latestDateInChangelog &&
76- !pr.labels.some(label => ["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase()))
80+ pulls.filter(pr =>
81+ pr.merged_at &&
82+ new Date(pr.merged_at) > latestDateInChangelog &&
83+ !pr.labels.some(label =>
84+ ["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase())
85+ )
7786 ).forEach(pr => {
87+
7888 const prLabels = pr.labels.map(label => label.name.toLowerCase());
7989 const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
8090
81- let isCategorized = false;
8291
83- for (const { labels, notes } of categorizedPRs) {
84- // If no labels are specified (e.g., "Unlabelled"), assign to this category
85- if (labels.length === 0 && prLabels.length === 0) {
86- notes.push(prNote);
87- isCategorized = true;
88- break;
89- }
92+ const updateScriptsCategory = categorizedPRs.find(category =>
93+ category.labels.some(label => prLabels.includes(label))
94+ );
95+
96+ if (updateScriptsCategory) {
97+
98+ const subCategory = updateScriptsCategory.subCategories.find(sub =>
99+ sub.labels.some(label => prLabels.includes(label))
100+ );
101+
102+ if (subCategory) {
103+ subCategory.notes.push(prNote);
104+ } else {
105+ updateScriptsCategory.notes.push(prNote);
90106
91- // If labels are specified, check if PR has ALL required labels
92- if (labels.length > 0 && labels.every(label => prLabels.includes(label.toLowerCase()))) {
93- notes.push(prNote);
94- isCategorized = true;
95- break;
96107 }
97108 }
98109
@@ -104,9 +115,12 @@ jobs:
104115 }
105116 }
106117 });
118+
119+ console.log(JSON.stringify(categorizedPRs, null, 2));
107120
108121 return categorizedPRs;
109122
123+
110124 - name : Update CHANGELOG.md
111125 uses : actions/github-script@v7
112126 with :
@@ -119,13 +133,32 @@ jobs:
119133 const changelogPath = path.resolve('CHANGELOG.md');
120134 const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
121135
136+ console.log(JSON.stringify(categorizedPRs, null, 2));
137+
122138 let newReleaseNotes = `## ${today}\n\n### Changes\n\n`;
123- for (const { title, notes } of categorizedPRs) {
124- if (notes.length > 0) {
125- newReleaseNotes += `### ${title}\n\n${notes.join("\n")}\n\n`;
139+ for (const { title, notes, subCategories } of categorizedPRs) {
140+ const hasSubcategories = subCategories && subCategories.length > 0;
141+ const hasMainNotes = notes.length > 0;
142+ const hasSubNotes = hasSubcategories && subCategories.some(sub => sub.notes && sub.notes.length > 0);
143+
144+ if (hasMainNotes || hasSubNotes) {
145+ newReleaseNotes += `### ${title}\n\n`;
146+ }
147+
148+ if (hasMainNotes) {
149+ newReleaseNotes += `${notes.join("\n")}\n\n`;
150+ }
151+
152+ if (hasSubcategories) {
153+ for (const { title : subTitle, notes: subNotes } of subCategories) {
154+ if (subNotes && subNotes.length > 0) {
155+ newReleaseNotes += ` # ### ${subTitle}\n\n`;
156+ newReleaseNotes += ` ${subNotes.join("\n ")}\n\n`;
157+ }
158+ }
126159 }
127- }
128-
160+ }
161+
129162 const changelogContent = await fs.readFile(changelogPath, 'utf-8');
130163 const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
131164
0 commit comments