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,40 +77,36 @@ 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;
91+ const updateScriptsCategory = categorizedPRs.find(category =>
92+ category.labels.some(label => prLabels.includes(label))
93+ );
8294
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- }
95+ if (updateScriptsCategory) {
96+
97+ const subCategory = updateScriptsCategory.subCategories.find(sub =>
98+ sub.labels.some(label => prLabels.includes(label))
99+ );
90100
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;
96- }
97- }
98-
99- // If PR is not categorized, assign it to the "Unlabelled" category
100- if (!isCategorized) {
101- const unlabelledCategory = categorizedPRs.find(cat => cat.title === "❔ Unlabelled");
102- if (unlabelledCategory) {
103- unlabelledCategory.notes.push(prNote);
101+ if (subCategory) {
102+ subCategory.notes.push(prNote);
103+ } else {
104+ updateScriptsCategory.notes.push(prNote);
104105 }
105106 }
106107 });
108+
109+ console.log(JSON.stringify(categorizedPRs, null, 2));
107110
108111 return categorizedPRs;
109112
@@ -119,13 +122,33 @@ jobs:
119122 const changelogPath = path.resolve('CHANGELOG.md');
120123 const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
121124
125+ console.log(JSON.stringify(categorizedPRs, null, 2));
126+
122127 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`;
128+ for (const { title, notes, subCategories } of categorizedPRs) {
129+ const hasSubcategories = subCategories && subCategories.length > 0;
130+ const hasMainNotes = notes.length > 0;
131+ const hasSubNotes = hasSubcategories && subCategories.some(sub => sub.notes && sub.notes.length > 0);
132+
133+
134+ if (hasMainNotes || hasSubNotes) {
135+ newReleaseNotes += `### ${title}\n\n`;
136+ }
137+
138+ if (hasMainNotes) {
139+ newReleaseNotes += `${notes.join("\n")}\n\n`;
140+ }
141+
142+ if (hasSubcategories) {
143+ for (const { title : subTitle, notes: subNotes } of subCategories) {
144+ if (subNotes && subNotes.length > 0) {
145+ newReleaseNotes += ` # ### ${subTitle}\n\n`;
146+ newReleaseNotes += ` ${subNotes.join("\n ")}\n\n`;
147+ }
148+ }
126149 }
127- }
128-
150+ }
151+
129152 const changelogContent = await fs.readFile(changelogPath, 'utf-8');
130153 const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
131154
0 commit comments