diff --git a/backend/database.js b/backend/database.js
index 9ea69b3..4cd5782 100644
--- a/backend/database.js
+++ b/backend/database.js
@@ -167,8 +167,8 @@ async function releasesAdd(release) {
release.id = uuid.v4();
release.createdAt = release.createdAt || 0;
- await db.query('INSERT INTO releases (id, projectId, version, body, notified, createdAt) VALUES (?, ?, ?, ?, ?, ?)',
- [ release.id, release.projectId, release.version, release.body, release.notified, release.createdAt ]);
+ await db.query('INSERT INTO releases (id, projectId, version, body, notified, prerelease, createdAt) VALUES (?, ?, ?, ?, ?, ?, ?)',
+ [ release.id, release.projectId, release.version, release.body, release.notified, release.prerelease, release.createdAt ]);
return release;
}
diff --git a/backend/github.js b/backend/github.js
index 46a925a..d96224c 100644
--- a/backend/github.js
+++ b/backend/github.js
@@ -1,6 +1,6 @@
'use strict';
-var assert = require('assert'),
+const assert = require('assert'),
{ Octokit } = require('@octokit/rest'),
{ retry } = require('@octokit/plugin-retry'),
{ throttling } = require('@octokit/plugin-throttling');
@@ -9,7 +9,7 @@ module.exports = exports = {
verifyToken,
getStarred,
getReleases,
- getReleaseBody,
+ getRelease,
getCommit
};
@@ -106,7 +106,7 @@ async function getReleases(token, project) {
return releases;
}
-async function getReleaseBody(token, project, version) {
+async function getRelease(token, project, version) {
assert.strictEqual(typeof token, 'string');
assert.strictEqual(typeof project, 'object');
assert.strictEqual(typeof version, 'string');
@@ -124,11 +124,10 @@ async function getReleaseBody(token, project, version) {
rethrow(error);
}
- if (!release.data.body) return '';
+ if (!release.data.body) return { body: '', prerelease: false };
- const fullBody = release.data.body.replace(/\r\n/g, '\n');
-
- return fullBody.length > 1000 ? fullBody.substring(0, 1000) + '...' : fullBody;
+ let body = release.data.body.replace(/\r\n/g, '\n');
+ return { body, prerelease: release.data.prerelease };
}
// Returns { createdAt, message }
diff --git a/backend/gitlab.js b/backend/gitlab.js
index 6c7f349..8f08d4b 100644
--- a/backend/gitlab.js
+++ b/backend/gitlab.js
@@ -1,13 +1,13 @@
'use strict';
-var assert = require('assert'),
+const assert = require('assert'),
superagent = require('superagent');
module.exports = exports = {
verifyToken,
getStarred,
getReleases,
- getReleaseBody,
+ getRelease,
getCommit
};
@@ -54,12 +54,12 @@ async function getReleases(token, project) {
return releaseObjects;
}
-function getReleaseBody(token, project, version) {
+function getRelease(token, project, version) {
assert.strictEqual(typeof token, 'string');
assert.strictEqual(typeof project, 'object');
assert.strictEqual(typeof version, 'string');
- return '';
+ return { body: '', prerelease: false };
}
// Returns { createdAt, message }
diff --git a/backend/notification.template b/backend/notification.template
index 91cd4b3..c1ff7e9 100644
--- a/backend/notification.template
+++ b/backend/notification.template
@@ -46,7 +46,11 @@
+ {{#if release.prerelease}}
@@ -55,7 +59,11 @@
- {{ release.version }}
+ {{ release.version }}
+ {{#if release.prerelease}}
+ (prerelease)
+ {{/if}}
+
|
{{#if release.body}}
diff --git a/backend/tasks.js b/backend/tasks.js
index 1b86500..b563364 100644
--- a/backend/tasks.js
+++ b/backend/tasks.js
@@ -173,6 +173,7 @@ async function syncReleasesByProject(user, project) {
release.notified = !project.lastSuccessfulSyncAt ? true : !project.enabled;
release.body = '';
release.createdAt = 0;
+ release.prerelease = false;
// skip fetching details for notification which will not be sent
if (release.notified) {
@@ -180,15 +181,16 @@ async function syncReleasesByProject(user, project) {
continue;
}
- let result;
try {
- result = await api.getReleaseBody(user.githubToken, project, release.version);
+ const result = await api.getRelease(user.githubToken, project, release.version); // { body, prerelease }
+ release.body = result.body;
+ release.prerelease = result.prerelease;
} catch (error) {
console.error(`Failed to get release body for ${project.name} ${release.version}. Falling back to commit message.`, error);
+ release.body = '';
+ release.prerelease = false;
}
- release.body = result || '';
-
const commit = await api.getCommit(user.githubToken, project, release.sha);
release.createdAt = new Date(commit.createdAt).getTime() || 0;
@@ -271,8 +273,8 @@ async function sendNotificationEmail(release) {
from: `ReleaseBell <${process.env.CLOUDRON_MAIL_FROM}>`,
to: user.email,
subject: `${project.name} ${release.version} released`,
- text: `A new release at ${project.name} with version ${release.version} was published. ${release.body}. Read more about this release at ${versionLink}`,
- html: EMAIL_TEMPLATE({ project: project, release: release, versionLink: versionLink, settingsLink: settingsLink })
+ text: `A new ${release.prerelease ? 'prerelease' : 'release'} at ${project.name} with version ${release.version} was published. ${release.body}. Read more about this release at ${versionLink}`,
+ html: EMAIL_TEMPLATE({ project, release, versionLink, settingsLink })
};
await transport.sendMail(mail);
diff --git a/migrations/20230926130714-add-release-prerelease.js b/migrations/20230926130714-add-release-prerelease.js
new file mode 100644
index 0000000..5ff9239
--- /dev/null
+++ b/migrations/20230926130714-add-release-prerelease.js
@@ -0,0 +1,10 @@
+'use strict';
+
+exports.up = function(db, callback) {
+ db.runSql('ALTER TABLE releases ADD COLUMN prerelease BOOLEAN DEFAULT 0', callback);
+};
+
+exports.down = function(db, callback) {
+ db.runSql('ALTER TABLE releases DROP COLUMN prerelease', callback);
+};
+
diff --git a/migrations/current_schema.sql b/migrations/current_schema.sql
index 1447826..76bfcd6 100644
--- a/migrations/current_schema.sql
+++ b/migrations/current_schema.sql
@@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS releases(
version VARCHAR(512) NOT NULL,
body TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
notified BOOLEAN DEFAULT false,
+ prereleases BOOLEAN DEFAULT false,
createdAt BIGINT NOT NULL,
FOREIGN KEY(projectId) REFERENCES projects(id),