Skip to content

Commit

Permalink
Fix RSS braider functionality
Browse files Browse the repository at this point in the history
Fixes #59
  • Loading branch information
reconman committed Sep 26, 2022
1 parent 2b1c479 commit d1dd5df
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ COPY ./package.json ./package.json

COPY ./etc ./etc

CMD node src/index.js
CMD node src/index.mjs
1 change: 0 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
- Stop the aplication
- Get the updates by pulling changes
- Run `npm install` to install new dependencies.
- Change the config format from module.exports to `const config = {` at the top and `export { config };`. (See [config.example.js](etc/config.example.js))
- Re-start the application.

## 2.0.0 to 2.1.0
Expand Down
3 changes: 1 addition & 2 deletions etc/config.example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = {
module.exports = {
interval: 60000, // Feed check interval, in miliseconds
userAgent: 'Mozilla/5.0 (Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0', // Experimental: User agent string to bypass possible fetching limits on GitHub
/**
Expand Down Expand Up @@ -84,4 +84,3 @@ const config = {
// direct rss links from other sources if you want to watch with this tool
],
};
export { config };
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "alerthub",
"version": "2.2.1",
"version": "2.2.2",
"description": "A tool to send notifications when an update to a repository is released",
"main": "./src/index.js",
"type": "module",
"main": "./src/index.mjs",
"type": "commonjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"init": "cp ./etc/config.example.js ./etc/config.js",
"start": "node ./src/index.js"
"start": "node ./src/index.mjs"
},
"author": "Arda Kilicdagi",
"license": "MIT",
Expand Down
13 changes: 7 additions & 6 deletions src/index.js → src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import RssFeedEmitter from 'rss-feed-emitter';
import http from 'http';

import alertHubUtils from './utils/alertHub.js';
import pushBulletUtils from './utils/pushBullet.js';
import pushOverUtils from './utils/pushOver.js';
import emailUtils from './utils/email.js';
import rssUtils from './utils/rss.js';
import pushBulletUtils from './utils/pushBullet.mjs';
import pushOverUtils from './utils/pushOver.mjs';
import emailUtils from './utils/email.mjs';
import RssUtils from './utils/rss.mjs';

import { config } from '../etc/config.js';
import config from '../etc/config.js';

// RSS Feed emitter to watch and parse feed
const feeder = new RssFeedEmitter({ userAgent: config.userAgent || 'Mozilla/5.0 (Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0' });
Expand Down Expand Up @@ -138,10 +138,11 @@ feeder.on('error', console.error);

// Let's handle the aggregated RSS part
if (config.rss.enabled === true) {
const rssUtils = new RssUtils(config);
http.createServer((_req, res) => {
res.writeHead(200, { 'Content-Type': 'application/xml' });
// Upon each request, let's fetch the RSS feed string from util
rssUtils.createRSSFeed(config).then((rssFeed) => {
rssUtils.createRSSFeed().then((rssFeed) => {
res.end(rssFeed);
});
}).listen(config.rss.port);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/rss-braider/addReleaseNameToTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
}]
*/
// We need a plug-in to add release name to the title.
import utils from '../../utils/alertHub.js';
const utils = require('../../utils/alertHub.js');

export default (_item, itemOptions, /* source */) => {
module.exports = (_item, itemOptions, /* source */) => {
if (
utils.isFeedFromGitHub(itemOptions) === true
|| utils.isFeedFromGitLab(itemOptions) === true
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/rss-braider/fixGitLabDateColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"props": true, "ignorePropertyModificationsFor": ["itemOptions"]
}]
*/
export default (item, itemOptions /* , source */) => {
module.exports = (item, itemOptions, /* source */) => {
if (
itemOptions.date === null
&& item.meta !== undefined
Expand Down
8 changes: 5 additions & 3 deletions src/utils/alertHub.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import URL from 'url';
import querystring from 'querystring';
const URL = require('url');
const querystring = require('querystring');

export default class AlertHubUtils {
class AlertHubUtils {
// Because there are also feeds,
// we need this method to check whether the feed is from GitHub or not
static isFeedFromGitHub(item) {
Expand Down Expand Up @@ -68,3 +68,5 @@ export default class AlertHubUtils {
return '';
}
}

module.exports = AlertHubUtils;
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 24 additions & 23 deletions src/utils/rss.js → src/utils/rss.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import rssBraider from 'rss-braider';
import path from 'path';
import * as url from 'url';

import alertHubUtils from './alertHub.js';

const __dirname = path.normalize(url.fileURLToPath(new URL('.', import.meta.url)));

export default class RssUtils {
// Creates a RSS feed from the configuration provided
static createRSSFeed(config) {
if (config.rss.enabled === true) {
const AlertHubFeeds = {
// Initializes the RSS braider client
constructor(config) {
const AlertHubFeeds = {
alertHub: {
feed_name: 'AlertHub',
default_count: 1,
Expand Down Expand Up @@ -114,29 +117,27 @@ export default class RssUtils {
plugins_directories: [path.join(__dirname, '..', 'plugins', 'rss-braider')],
};

const rssClient = rssBraider.createClient(braiderOptions);
this.rssClient = rssBraider.createClient(braiderOptions);

// Override logging level (debug, info, warn, err, off)
rssClient.logger.level(config.rss.logLevel || 'info');
this.rssClient.logger.level(config.rss.logLevel || 'info');
}

// Let's make a promise
const process = new Promise((resolve, reject) => {
rssClient.processFeed('alertHub', 'rss', (err, data) => {
if (err) {
// console.log(err);
reject(err);
// Creates a RSS feed from the configuration provided
createRSSFeed() {
// Let's make a promise
const process = new Promise((resolve, reject) => {
this.rssClient.processFeed('alertHub', 'rss', (err, data) => {
if (err) {
// console.log(err);
reject(err);

return;
}
// console.log(data);
resolve(data);
});
return;
}
// console.log(data);
resolve(data);
});

return process;
}

// If RSS output is disabled, empty string will be returned
return Promise.resolve('');
});
return process;
}
}

0 comments on commit d1dd5df

Please sign in to comment.