diff --git a/config/config.sample.js b/config/config.sample.js index f782f70..9786c52 100644 --- a/config/config.sample.js +++ b/config/config.sample.js @@ -27,7 +27,33 @@ const config = { }, id: '41469246', hashtagMessage: '#ngVenezuelaTweet' - } + }, + githubReleases: [ + { + name: 'angular', + repo: 'angular/angular', + hasChangelog: true, + feed: 'https://github.com/angular/angular/releases.atom' + }, + { + name: 'ionic', + repo: 'driftyco/ionic', + hasChangelog: true, + feed: 'https://github.com/driftyco/ionic/releases.atom' + }, + { + name: 'nativescript', + repo: 'NativeScript/NativeScript', + hasChangelog: true, + feed: 'https://github.com/NativeScript/NativeScript/releases.atom' + }, + { + name: 'wengy-ven', + repo: 'ngVenezuela/wengy-ven', + hasChangelog: false, + feed: 'https://github.com/ngVenezuela/wengy-ven/releases.atom' + } + ] } }; diff --git a/src/index.js b/src/index.js index a1be9d6..568d80a 100644 --- a/src/index.js +++ b/src/index.js @@ -63,13 +63,6 @@ new TwitterEvent() .on('newTweet', tweet => twitterUtility.sendNewTweet(bot, tweet)); superfeedr - .on('newFeed', feed => - githubUtility.checkForRelease('angular/angular', feed) - && githubUtility.sendRelease(bot, feed, 'angular/angular', true) - ) - .on('newFeed', feed => - githubUtility.checkForRelease('ngVenezuela/wengy-ven', feed) - && githubUtility.sendRelease(bot, feed, 'ngVenezuela/wengy-ven', false) - ) + .on('newFeed', feed => githubUtility.checkAndSendRelease(bot, feed)) .on('newFeed', feed => blogUtility.checkForBlogEntry(feed) && blogUtility.sendNewBlogEntries(bot, feed)); diff --git a/src/utils/github-release.js b/src/utils/github-release.js index e5641fe..07a0868 100644 --- a/src/utils/github-release.js +++ b/src/utils/github-release.js @@ -1,8 +1,9 @@ -const config = require('./../../config/config'); +const groupId = require('./../../config/config').groupId; +const releasesToCheck = require('./../../config/config').integrations.githubReleases; const githubReleaseMessage = require('./../../config/messages').githubRelease; const sendMessage = require('./../utils/send-message'); -const checkForRelease = (repository, feed) => +const isItAGithubRelease = (repository, feed) => feed && feed.status.feed && feed.status.feed.search(repository) !== -1; const sendRelease = (bot, release, repository, changelogExist) => { @@ -17,7 +18,7 @@ const sendRelease = (bot, release, repository, changelogExist) => { sendMessage( bot, - config.groupId, + groupId, githubReleaseMessage .replace('#{name}', name) .replace('#{version}', tag) @@ -31,7 +32,16 @@ const sendRelease = (bot, release, repository, changelogExist) => { }); }; +const checkAndSendRelease = (bot, feed) => { + releasesToCheck.forEach((release) => { + if (isItAGithubRelease(release.repo, feed)) { + sendRelease(bot, feed, release.repo, release.hasChangelog); + } + }); +}; + module.exports = { - checkForRelease, + checkAndSendRelease, + isItAGithubRelease, sendRelease };