Skip to content

Commit ef839ac

Browse files
committed
Update changelog-pr.yml
1 parent 5aca671 commit ef839ac

File tree

1 file changed

+59
-50
lines changed

1 file changed

+59
-50
lines changed

.github/workflows/changelog-pr.yml

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -97,62 +97,71 @@ jobs:
9797
per_page: 100,
9898
});
9999
100-
const filteredPRs = pulls.filter(pr =>
101-
pr.merged_at &&
102-
new Date(pr.merged_at) > latestDateInChangelog &&
103-
!pr.labels.some(label =>
104-
["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase())
105-
)
106-
);
107-
108-
for (const pr of filteredPRs) {
109-
const prLabels = pr.labels.map(label => label.name.toLowerCase());
100+
const filteredPRs = pulls.filter(pr =>
101+
pr.merged_at &&
102+
new Date(pr.merged_at) > latestDateInChangelog &&
103+
!pr.labels.some(label =>
104+
["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase())
105+
)
106+
);
110107
111-
let prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
112-
113-
if (pr.user.login === "push-app-to-main") {
114-
const scriptName = pr.title;
115-
if (scriptName) {
116-
try {
117-
const { data: relatedIssues } = await github.rest.issues.listForRepo({
118-
owner: context.repo.owner,
119-
repo: "ProxmoxVED",
120-
state: "all",
121-
labels: ["Started Migration To ProxmoxVE"],
122-
per_page: 5
123-
});
124-
const matchingIssue = relatedIssues.find(issue =>
125-
issue.title.toLowerCase().includes(scriptName.toLowerCase())
126-
);
127-
if (matchingIssue) {
128-
const issueAuthor = matchingIssue.user.login;
129-
const issueAuthorUrl = `https://github.com/${issueAuthor}`;
130-
prNote = `- ${pr.title} [@${issueAuthor}](${issueAuthorUrl}) ([#${pr.number}](${pr.html_url}))`;
108+
for (const pr of filteredPRs) {
109+
const prLabels = pr.labels.map(label => label.name.toLowerCase());
110+
111+
let prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
112+
113+
if (pr.user.login === "push-app-to-main") {
114+
const scriptName = pr.title;
115+
if (scriptName) {
116+
try {
117+
const { data: relatedIssues } = await github.rest.issues.listForRepo({
118+
owner: context.repo.owner,
119+
repo: "ProxmoxVED",
120+
state: "all",
121+
labels: ["Started Migration To ProxmoxVE"],
122+
per_page: 5
123+
});
124+
const matchingIssue = relatedIssues.find(issue =>
125+
issue.title.toLowerCase().includes(scriptName.toLowerCase())
126+
);
127+
if (matchingIssue) {
128+
const issueAuthor = matchingIssue.user.login;
129+
const issueAuthorUrl = `https://github.com/${issueAuthor}`;
130+
prNote = `- ${pr.title} [@${issueAuthor}](${issueAuthorUrl}) ([#${pr.number}](${pr.html_url}))`;
131+
}
132+
} catch (error) {
133+
console.error(`Error fetching related issues: ${error}`);
131134
}
132-
} catch (error) {
133-
console.error(`Error fetching related issues: ${error}`);
135+
} else {
136+
prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
134137
}
135-
} else {
136-
prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
137138
}
138-
139-
const updateScriptsCategory = categorizedPRs.find(category =>
140-
category.labels.some(label => prLabels.includes(label))
141-
);
142-
143-
if (updateScriptsCategory) {
144-
const subCategory = updateScriptsCategory.subCategories.find(sub =>
145-
sub.labels.some(label => prLabels.includes(label))
146-
);
147-
148-
if (subCategory) {
149-
subCategory.notes.push(prNote);
150-
} else {
151-
updateScriptsCategory.notes.push(prNote);
139+
140+
// Find matching category
141+
for (const category of categorizedPRs) {
142+
if (category.labels.some(label => prLabels.includes(label))) {
143+
// Check if PR belongs to a subcategory
144+
if (category.subCategories && category.subCategories.length > 0) {
145+
const subCategory = category.subCategories.find(sub =>
146+
sub.labels.some(label => prLabels.includes(label))
147+
);
148+
149+
if (subCategory) {
150+
subCategory.notes.push(prNote);
151+
} else {
152+
category.notes.push(prNote);
153+
}
154+
} else {
155+
category.notes.push(prNote);
156+
}
152157
}
153158
}
154159
}
155-
160+
161+
return categorizedPRs;
162+
}
163+
164+
return await main();
156165
157166
- name: Update CHANGELOG.md
158167
uses: actions/github-script@v7
@@ -248,4 +257,4 @@ jobs:
248257
PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number')
249258
if [ -n "$PR_NUMBER" ]; then
250259
gh pr review $PR_NUMBER --approve
251-
fi
260+
fi

0 commit comments

Comments
 (0)