Skip to content

Commit fdd8381

Browse files
refactor: enhance release fetching to support multiple stable releases
- Renamed `getLatestRelease` to `getReleases` to fetch all stable (non-prerelease, non-draft) releases - Updated logic to retrieve commits between the latest and previous stable release using a proper git range - Removed arbitrary -50 limit on commit history, ensuring accurate changelog generation for Discord posts - Improved error handling and filtering for better reliability in release automation
1 parent 2dd37bd commit fdd8381

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

post-discord-release.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,28 @@ function classifyCommit(message) {
8383
return null;
8484
}
8585

86-
// Get latest release from GitHub API
87-
function getLatestRelease() {
86+
// Get the latest stable releases from GitHub
87+
function getReleases() {
8888
const options = {
8989
hostname: "api.github.com",
9090
path: "/repos/CodeWorksCreativeHub/mLauncher/releases",
9191
method: "GET",
9292
headers: { "User-Agent": "Node.js" },
9393
};
94+
9495
return new Promise((resolve, reject) => {
9596
const req = https.request(options, (res) => {
9697
let data = "";
9798
res.on("data", (chunk) => (data += chunk));
9899
res.on("end", () => {
99100
try {
100101
const releases = JSON.parse(data);
101-
// Filter out pre-releases and get the latest non-prerelease
102-
const latestRelease = releases.find((r) => !r.prerelease);
103-
if (!latestRelease) {
104-
reject(new Error("No non-prerelease releases found"));
105-
return;
106-
}
107-
resolve(latestRelease);
108-
} catch (error) {
109-
reject(error);
102+
// Only non-prerelease, non-draft releases
103+
const stable = releases.filter((r) => !r.prerelease && !r.draft);
104+
if (stable.length < 1) return reject(new Error("No stable releases found"));
105+
resolve(stable);
106+
} catch (e) {
107+
reject(e);
110108
}
111109
});
112110
});
@@ -135,13 +133,17 @@ function formatLauncherVersion(input) {
135133
// Main async function
136134
(async () => {
137135
try {
138-
// Get latest release from GitHub API
139-
const latestRelease = await getLatestRelease();
136+
const releases = await getReleases();
137+
const latestRelease = releases[0];
138+
const previousRelease = releases[1]; // may be undefined
140139

141140
const latestTag = latestRelease.tag_name;
141+
const previousTag = previousRelease ? previousRelease.tag_name : null;
142+
143+
// Commit range
144+
const range = previousTag ? `${previousTag}..${latestTag}` : latestTag;
145+
const rawCommits = run(`git log ${range} --pretty=format:"%h|%s"`).split("\n");
142146

143-
// Get commits since previous release (or all commits if no previous release)
144-
let rawCommits = run(`git log ${latestTag} --pretty=format:"%h|%s" -50`).split("\n");
145147
const commits = rawCommits
146148
.map((line) => {
147149
const [hash, ...msgParts] = line.split("|");

0 commit comments

Comments
 (0)