30
30
31
31
- name : Get latest dates in changelog
32
32
run : |
33
- # Extrahiere die neuesten zwei Daten aus dem Changelog
34
33
DATES=$(grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2}' CHANGELOG.md | head -n 2 | awk '{print $2}')
35
34
36
35
LATEST_DATE=$(echo "$DATES" | sed -n '1p')
55
54
const configPath = path.resolve(process.env.CONFIG_PATH);
56
55
const fileContent = await fs.readFile(configPath, 'utf-8');
57
56
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
+ }));
59
66
60
67
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
61
68
latestDateInChangelog.setUTCHours(23, 59, 59, 999);
@@ -70,40 +77,36 @@ jobs:
70
77
per_page: 100,
71
78
});
72
79
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
+ )
77
86
).forEach(pr => {
87
+
78
88
const prLabels = pr.labels.map(label => label.name.toLowerCase());
79
89
const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
80
90
81
- let isCategorized = false;
91
+ const updateScriptsCategory = categorizedPRs.find(category =>
92
+ category.labels.some(label => prLabels.includes(label))
93
+ );
82
94
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
+ );
90
100
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);
104
105
}
105
106
}
106
107
});
108
+
109
+ console.log(JSON.stringify(categorizedPRs, null, 2));
107
110
108
111
return categorizedPRs;
109
112
@@ -119,13 +122,33 @@ jobs:
119
122
const changelogPath = path.resolve('CHANGELOG.md');
120
123
const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
121
124
125
+ console.log(JSON.stringify(categorizedPRs, null, 2));
126
+
122
127
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
+ }
126
149
}
127
- }
128
-
150
+ }
151
+
129
152
const changelogContent = await fs.readFile(changelogPath, 'utf-8');
130
153
const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
131
154
0 commit comments