Skip to content

Commit c9b5579

Browse files
Fix WF (#3372)
1 parent 888b4c3 commit c9b5579

File tree

1 file changed

+108
-104
lines changed

1 file changed

+108
-104
lines changed

.github/workflows/changelog-pr.yml

Lines changed: 108 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -48,116 +48,120 @@ jobs:
4848
uses: actions/github-script@v7
4949
with:
5050
script: |
51-
const fs = require('fs').promises;
52-
const path = require('path');
53-
54-
const configPath = path.resolve(process.env.CONFIG_PATH);
55-
const fileContent = await fs.readFile(configPath, 'utf-8');
56-
const changelogConfig = JSON.parse(fileContent);
57-
58-
const categorizedPRs = changelogConfig.map(obj => ({
59-
...obj,
60-
notes: [],
61-
subCategories: obj.subCategories ?? (
62-
obj.labels.includes("update script") ? [
63-
{ title: "🐞 Bug Fixes", labels: ["bugfix"], notes: [] },
64-
{ title: "✨ New Features", labels: ["feature"], notes: [] },
65-
{ title: "💥 Breaking Changes", labels: ["breaking change"], notes: [] },
66-
{ title: "🔧 Refactor", labels: ["refactor"], notes: [] },
67-
] :
68-
obj.labels.includes("maintenance") ? [
69-
{ title: "🐞 Bug Fixes", labels: ["bugfix"], notes: [] },
70-
{ title: "✨ New Features", labels: ["feature"], notes: [] },
71-
{ title: "💥 Breaking Changes", labels: ["breaking change"], notes: [] },
72-
{ title: "📡 API", labels: ["api"], notes: [] },
73-
{ title: "Github", labels: ["github"], notes: [] },
74-
{ title: "📝 Documentation", labels: ["documentation"], notes: [] },
75-
{ title: "🔧 Refactor", labels: ["refactor"], notes: [] }
76-
] :
77-
obj.labels.includes("website") ? [
78-
{ title: "🐞 Bug Fixes", labels: ["bugfix"], notes: [] },
79-
{ title: "✨ New Features", labels: ["feature"], notes: [] },
80-
{ title: "💥 Breaking Changes", labels: ["breaking change"], notes: [] },
81-
{ title: "Script Information", labels: ["json"], notes: [] }
82-
] : []
83-
)
84-
}));
85-
86-
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
87-
latestDateInChangelog.setUTCHours(23, 59, 59, 999);
88-
89-
const { data: pulls } = await github.rest.pulls.list({
90-
owner: context.repo.owner,
91-
repo: context.repo.repo,
92-
base: "main",
93-
state: "closed",
94-
sort: "updated",
95-
direction: "desc",
96-
per_page: 100,
97-
});
98-
99-
pulls.filter(pr =>
100-
pr.merged_at &&
101-
new Date(pr.merged_at) > latestDateInChangelog &&
102-
!pr.labels.some(label =>
103-
["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase())
104-
)
105-
).forEach(pr => {
106-
107-
const prLabels = pr.labels.map(label => label.name.toLowerCase());
108-
if (pr.user.login === "push-app-to-main") {
109-
const scriptName = pr.title;
110-
if (scriptName) {
111-
try {
112-
const { data: relatedIssues } = await github.rest.issues.listForRepo({
113-
owner: context.repo.owner,
114-
repo: "ProxmoxVED",
115-
state: "all",
116-
label: "Started Migration To ProxmoxVE",
117-
per_page: 5
118-
});
119-
const matchingIssue = relatedIssues.find(issue =>
120-
issue.title.toLowerCase().includes(scriptName.toLowerCase())
121-
);
122-
if (matchingIssue) {
123-
const issueAuthor = matchingIssue.user.login;
124-
const issueAuthorUrl = `https://github.com/${issueAuthor}`;
125-
const prNote = `- ${pr.title} [@${issueAuthor}](${issueAuthorUrl}) ([#${pr.number}](${pr.html_url}))`;
126-
} else {
127-
const prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
51+
async function main() {
52+
const fs = require('fs').promises;
53+
const path = require('path');
54+
55+
const configPath = path.resolve(process.env.CONFIG_PATH);
56+
const fileContent = await fs.readFile(configPath, 'utf-8');
57+
const changelogConfig = JSON.parse(fileContent);
58+
59+
const categorizedPRs = changelogConfig.map(obj => ({
60+
...obj,
61+
notes: [],
62+
subCategories: obj.subCategories ?? (
63+
obj.labels.includes("update script") ? [
64+
{ title: "🐞 Bug Fixes", labels: ["bugfix"], notes: [] },
65+
{ title: "✨ New Features", labels: ["feature"], notes: [] },
66+
{ title: "💥 Breaking Changes", labels: ["breaking change"], notes: [] },
67+
{ title: "🔧 Refactor", labels: ["refactor"], notes: [] },
68+
] :
69+
obj.labels.includes("maintenance") ? [
70+
{ title: "🐞 Bug Fixes", labels: ["bugfix"], notes: [] },
71+
{ title: "✨ New Features", labels: ["feature"], notes: [] },
72+
{ title: "💥 Breaking Changes", labels: ["breaking change"], notes: [] },
73+
{ title: "📡 API", labels: ["api"], notes: [] },
74+
{ title: "Github", labels: ["github"], notes: [] },
75+
{ title: "📝 Documentation", labels: ["documentation"], notes: [] },
76+
{ title: "🔧 Refactor", labels: ["refactor"], notes: [] }
77+
] :
78+
obj.labels.includes("website") ? [
79+
{ title: "🐞 Bug Fixes", labels: ["bugfix"], notes: [] },
80+
{ title: "✨ New Features", labels: ["feature"], notes: [] },
81+
{ title: "💥 Breaking Changes", labels: ["breaking change"], notes: [] },
82+
{ title: "Script Information", labels: ["json"], notes: [] }
83+
] : []
84+
)
85+
}));
86+
87+
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
88+
latestDateInChangelog.setUTCHours(23, 59, 59, 999);
89+
90+
const { data: pulls } = await github.rest.pulls.list({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
base: "main",
94+
state: "closed",
95+
sort: "updated",
96+
direction: "desc",
97+
per_page: 100,
98+
});
99+
100+
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+
).forEach(pr => {
107+
108+
const prLabels = pr.labels.map(label => label.name.toLowerCase());
109+
if (pr.user.login === "push-app-to-main") {
110+
const scriptName = pr.title;
111+
if (scriptName) {
112+
try {
113+
const { data: relatedIssues } = await github.rest.issues.listForRepo({
114+
owner: context.repo.owner,
115+
repo: "ProxmoxVED",
116+
state: "all",
117+
label: "Started Migration To ProxmoxVE",
118+
per_page: 5
119+
});
120+
const matchingIssue = relatedIssues.find(issue =>
121+
issue.title.toLowerCase().includes(scriptName.toLowerCase())
122+
);
123+
if (matchingIssue) {
124+
const issueAuthor = matchingIssue.user.login;
125+
const issueAuthorUrl = `https://github.com/${issueAuthor}`;
126+
const prNote = `- ${pr.title} [@${issueAuthor}](${issueAuthorUrl}) ([#${pr.number}](${pr.html_url}))`;
127+
} else {
128+
const prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
129+
}
130+
} catch (error) {
131+
console.error(`Error fetching related issues: ${error}`);
132+
const prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
128133
}
129-
} catch (error) {
130-
console.error(`Error fetching related issues: ${error}`);
131-
const prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
132-
}
133-
} else {
134-
const prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
134+
} else {
135+
const prNote = `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
135136
136-
}else{
137-
const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
138-
}
139-
const updateScriptsCategory = categorizedPRs.find(category =>
140-
category.labels.some(label => prLabels.includes(label))
141-
);
142-
143-
if (updateScriptsCategory) {
144-
145-
const subCategory = updateScriptsCategory.subCategories.find(sub =>
146-
sub.labels.some(label => prLabels.includes(label))
137+
}else{
138+
const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
139+
}
140+
const updateScriptsCategory = categorizedPRs.find(category =>
141+
category.labels.some(label => prLabels.includes(label))
147142
);
148143
149-
if (subCategory) {
150-
subCategory.notes.push(prNote);
151-
} else {
152-
updateScriptsCategory.notes.push(prNote);
144+
if (updateScriptsCategory) {
145+
146+
const subCategory = updateScriptsCategory.subCategories.find(sub =>
147+
sub.labels.some(label => prLabels.includes(label))
148+
);
149+
150+
if (subCategory) {
151+
subCategory.notes.push(prNote);
152+
} else {
153+
updateScriptsCategory.notes.push(prNote);
154+
}
153155
}
154-
}
156+
});
157+
158+
console.log(JSON.stringify(categorizedPRs, null, 2));
159+
160+
return categorizedPRs;
161+
}
162+
main().catch(error => {
163+
console.error("Error in script:", error);
155164
});
156-
157-
console.log(JSON.stringify(categorizedPRs, null, 2));
158-
159-
return categorizedPRs;
160-
161165
162166
- name: Update CHANGELOG.md
163167
uses: actions/github-script@v7

0 commit comments

Comments
 (0)