Skip to content

Commit 109c486

Browse files
authored
Update changelog-pr.yml
1 parent d0cd58e commit 109c486

File tree

1 file changed

+9
-67
lines changed

1 file changed

+9
-67
lines changed

.github/workflows/changelog-pr.yml

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030

3131
- name: Get latest dates in changelog
3232
run: |
33+
# Extrahiere die neuesten zwei Daten aus dem Changelog
3334
DATES=$(grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2}' CHANGELOG.md | head -n 2 | awk '{print $2}')
35+
3436
LATEST_DATE=$(echo "$DATES" | sed -n '1p')
3537
SECOND_LATEST_DATE=$(echo "$DATES" | sed -n '2p')
3638
TODAY=$(date -u +%Y-%m-%d)
@@ -42,7 +44,7 @@ jobs:
4244
echo "LATEST_DATE=$LATEST_DATE" >> $GITHUB_ENV
4345
fi
4446
45-
- name: Get categorized pull requests (including PR template selections)
47+
- name: Get categorized pull requests
4648
id: get-categorized-prs
4749
uses: actions/github-script@v7
4850
with:
@@ -52,22 +54,7 @@ jobs:
5254
5355
const configPath = path.resolve(process.env.CONFIG_PATH);
5456
const fileContent = await fs.readFile(configPath, 'utf-8');
55-
let changelogConfig = JSON.parse(fileContent);
56-
57-
const order = [
58-
"💥 Breaking Changes",
59-
"🆕 New Scripts",
60-
"🚀 Updated Scripts",
61-
"🐞 Bug Fixes (Updated Scripts)",
62-
"✨ Feature Updates (Updated Scripts)",
63-
"✨ New Features",
64-
"🌐 Website",
65-
"📡 API",
66-
"🧰 Maintenance",
67-
"❔ Unlabelled"
68-
];
69-
changelogConfig = changelogConfig.sort((a, b) => order.indexOf(a.title) - order.indexOf(b.title));
70-
57+
const changelogConfig = JSON.parse(fileContent);
7158
const categorizedPRs = changelogConfig.map(obj => ({ ...obj, notes: [] }));
7259
7360
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
@@ -83,65 +70,23 @@ jobs:
8370
per_page: 100,
8471
});
8572
86-
if (!pulls || pulls.length === 0) {
87-
console.log("⚠️ Keine gemergten PRs gefunden. Setze leeres Changelog.");
88-
core.setOutput("result", "[]");
89-
return;
90-
}
91-
9273
pulls.filter(pr =>
9374
pr.merged_at &&
9475
new Date(pr.merged_at) > latestDateInChangelog &&
9576
!pr.labels.some(label => ["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase()))
9677
).forEach(pr => {
9778
const prLabels = pr.labels.map(label => label.name.toLowerCase());
98-
const prBody = pr.body ? pr.body.toLowerCase() : "";
9979
const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
10080
101-
const templateLabelMappings = {
102-
"🐞 bug fix": "bugfix",
103-
"✨ new feature": "feature",
104-
"💥 breaking change": "breaking change",
105-
"🆕 new script": "new script"
106-
};
107-
108-
let addedByTemplate = false;
109-
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
110-
const regex = new RegExp(`- \\[(.*?)\\] ${checkbox}`, "i");
111-
const match = prBody.match(regex);
112-
if (match && match[1].trim() !== "") {
113-
prLabels.push(label);
114-
addedByTemplate = true;
115-
}
116-
}
117-
118-
let categorized = false;
119-
for (const { labels, notes, title } of categorizedPRs) {
120-
if (labels.includes("update script") && labels.includes("bugfix")) {
121-
if (title === "🐞 Bug Fixes (Updated Scripts)") {
122-
notes.push(prNote);
123-
categorized = true;
124-
break;
125-
}
126-
} else if (labels.includes("update script") && labels.includes("feature")) {
127-
if (title === "✨ Feature Updates (Updated Scripts)") {
128-
notes.push(prNote);
129-
categorized = true;
130-
break;
131-
}
132-
} else if (labels.length === 0 || labels.some(label => prLabels.includes(label))) {
81+
for (const { labels, notes } of categorizedPRs) {
82+
if (labels.length === 0 || labels.some(label => prLabels.includes(label))) {
13383
notes.push(prNote);
134-
categorized = true;
13584
break;
13685
}
13786
}
138-
139-
if (addedByTemplate) {
140-
console.log(`PR #${pr.number} wurde durch PR-Template-Kategorie hinzugefügt.`);
141-
}
14287
});
14388
144-
core.setOutput("result", JSON.stringify(categorizedPRs.length ? categorizedPRs : []));
89+
return categorizedPRs;
14590
14691
- name: Update CHANGELOG.md
14792
uses: actions/github-script@v7
@@ -153,11 +98,7 @@ jobs:
15398
const today = process.env.TODAY;
15499
const latestDateInChangelog = process.env.LATEST_DATE;
155100
const changelogPath = path.resolve('CHANGELOG.md');
156-
const result = `${{ steps.get-categorized-prs.outputs.result }}`.trim();
157-
158-
console.log("🔹 Ergebnis aus get-categorized-prs:", result);
159-
160-
const categorizedPRs = result && result !== "undefined" ? JSON.parse(result) : [];
101+
const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
161102
162103
let newReleaseNotes = `## ${today}\n\n### Changes\n\n`;
163104
for (const { title, notes } of categorizedPRs) {
@@ -169,6 +110,7 @@ jobs:
169110
const changelogContent = await fs.readFile(changelogPath, 'utf-8');
170111
const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
171112
113+
// Ersetze oder füge Release Notes ein
172114
const regex = changelogIncludesTodaysReleaseNotes
173115
? new RegExp(`## ${today}.*(?=## ${latestDateInChangelog})`, "gs")
174116
: new RegExp(`(?=## ${latestDateInChangelog})`, "gs");

0 commit comments

Comments
 (0)