Skip to content

Commit 0c13b71

Browse files
authored
Update changelog-pr.yml
1 parent e1c25a3 commit 0c13b71

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

.github/workflows/changelog-pr.yml

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
echo "LATEST_DATE=$LATEST_DATE" >> $GITHUB_ENV
4545
fi
4646
47-
- name: Get categorized pull requests
47+
- name: Get categorized pull requests (including PR template selections)
4848
id: get-categorized-prs
4949
uses: actions/github-script@v7
5050
with:
@@ -54,7 +54,23 @@ jobs:
5454
5555
const configPath = path.resolve(process.env.CONFIG_PATH);
5656
const fileContent = await fs.readFile(configPath, 'utf-8');
57-
const changelogConfig = JSON.parse(fileContent);
57+
let changelogConfig = JSON.parse(fileContent);
58+
59+
// Reihenfolge der Kategorien beibehalten
60+
const order = [
61+
"💥 Breaking Changes",
62+
"🆕 New Scripts",
63+
"🚀 Updated Scripts",
64+
"🐞 Bug Fixes (Updated Scripts)",
65+
"✨ Feature Updates (Updated Scripts)",
66+
"✨ New Features",
67+
"🌐 Website",
68+
"📡 API",
69+
"🧰 Maintenance",
70+
"❔ Unlabelled"
71+
];
72+
changelogConfig = changelogConfig.sort((a, b) => order.indexOf(a.title) - order.indexOf(b.title));
73+
5874
const categorizedPRs = changelogConfig.map(obj => ({ ...obj, notes: [] }));
5975
6076
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
@@ -76,17 +92,55 @@ jobs:
7692
!pr.labels.some(label => ["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase()))
7793
).forEach(pr => {
7894
const prLabels = pr.labels.map(label => label.name.toLowerCase());
95+
const prBody = pr.body.toLowerCase();
7996
const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
8097
81-
for (const { labels, notes } of categorizedPRs) {
82-
if (labels.length === 0 || labels.some(label => prLabels.includes(label))) {
98+
// Mapping für PR-Checkboxen → Labels
99+
const templateLabelMappings = {
100+
"🐞 bug fix": "bugfix",
101+
"✨ new feature": "feature",
102+
"💥 breaking change": "breaking change",
103+
"🆕 new script": "new script"
104+
};
105+
106+
let addedByTemplate = false;
107+
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
108+
const regex = new RegExp(`- \\[(.*?)\\] ${checkbox}`, "i");
109+
const match = prBody.match(regex);
110+
if (match && match[1].trim() !== "") { // Checkbox ist gesetzt
111+
prLabels.push(label);
112+
addedByTemplate = true;
113+
}
114+
}
115+
116+
// Unterteilung von "Updated Scripts"
117+
let categorized = false;
118+
for (const { labels, notes, title } of categorizedPRs) {
119+
if (labels.includes("update script") && labels.includes("bugfix")) {
120+
if (title === "🐞 Bug Fixes (Updated Scripts)") {
121+
notes.push(prNote);
122+
categorized = true;
123+
break;
124+
}
125+
} else if (labels.includes("update script") && labels.includes("feature")) {
126+
if (title === "✨ Feature Updates (Updated Scripts)") {
127+
notes.push(prNote);
128+
categorized = true;
129+
break;
130+
}
131+
} else if (labels.length === 0 || labels.some(label => prLabels.includes(label))) {
83132
notes.push(prNote);
133+
categorized = true;
84134
break;
85135
}
86136
}
137+
138+
if (addedByTemplate) {
139+
console.log(`PR #${pr.number} wurde durch PR-Template-Kategorie hinzugefügt`);
140+
}
87141
});
88142
89-
return categorizedPRs;
143+
core.setOutput("result", JSON.stringify(categorizedPRs));
90144
91145
- name: Update CHANGELOG.md
92146
uses: actions/github-script@v7
@@ -98,7 +152,7 @@ jobs:
98152
const today = process.env.TODAY;
99153
const latestDateInChangelog = process.env.LATEST_DATE;
100154
const changelogPath = path.resolve('CHANGELOG.md');
101-
const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
155+
const categorizedPRs = JSON.parse(process.env.RESULT);
102156
103157
let newReleaseNotes = `## ${today}\n\n### Changes\n\n`;
104158
for (const { title, notes } of categorizedPRs) {

0 commit comments

Comments
 (0)