forked from Ardakilic/alerthub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Ardakilic#58
- Loading branch information
Showing
10 changed files
with
243 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,70 @@ | ||
import URL from 'url'; | ||
import querystring from 'querystring'; | ||
|
||
// Because there are also feeds, | ||
// we need this method to check whether the feed is from GitHub or not | ||
function isFeedFromGitHub(item) { | ||
if (item.guid !== undefined && item.guid !== null && typeof item.guid === 'string') { | ||
if (item.guid.substring(0, 14) === 'tag:github.com') { | ||
export default class AlertHubUtils { | ||
// Because there are also feeds, | ||
// we need this method to check whether the feed is from GitHub or not | ||
static isFeedFromGitHub(item) { | ||
if (item.guid !== undefined && item.guid !== null && typeof item.guid === 'string') { | ||
if (item.guid.substring(0, 14) === 'tag:github.com') { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
static isFeedFromGitLab(item) { | ||
const parsedURL = URL.parse(item.url); | ||
if (parsedURL.hostname === 'gitlab.com') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
function isFeedFromGitLab(item) { | ||
const parsedURL = URL.parse(item.url); | ||
if (parsedURL.hostname === 'gitlab.com') { | ||
return true; | ||
// Because there's no release name in GitHub feed, we steal from URL | ||
static getReleaseNameFromGitHubAndGitLabFeedLink(link) { | ||
const parts = link.split('/'); | ||
return `${parts[3]}/${parts[4]}`; | ||
} | ||
return false; | ||
} | ||
|
||
// Because there's no release name in GitHub feed, we steal from URL | ||
function getReleaseNameFromGitHubAndGitLabFeedLink(link) { | ||
const parts = link.split('/'); | ||
return `${parts[3]}/${parts[4]}`; | ||
} | ||
// Standardize the new feed element | ||
static parseFeedData(feedData) { | ||
const parsedFeed = { | ||
title: feedData.title, | ||
link: feedData.link, | ||
description: feedData.description, | ||
// summary: feedData.summary, | ||
date: feedData.date, | ||
}; | ||
|
||
// Standardize the new feed element | ||
function parseFeedData(feedData) { | ||
const parsedFeed = { | ||
title: feedData.title, | ||
link: feedData.link, | ||
description: feedData.description, | ||
// summary: feedData.summary, | ||
date: feedData.date, | ||
}; | ||
// We need to prepend release name to the title | ||
if (this.isFeedFromGitHub(feedData) === true || this.isFeedFromGitLab(feedData) === true) { | ||
parsedFeed.title = `${this.getReleaseNameFromGitHubAndGitLabFeedLink(feedData.link)} - ${feedData.title}`; | ||
} | ||
|
||
// We need to prepend release name to the title | ||
if (isFeedFromGitHub(feedData) === true || isFeedFromGitLab(feedData) === true) { | ||
parsedFeed.title = `${getReleaseNameFromGitHubAndGitLabFeedLink(feedData.link)} - ${feedData.title}`; | ||
return parsedFeed; | ||
} | ||
|
||
return parsedFeed; | ||
} | ||
|
||
// Generates the RSS feed URL with given parameters honoring the configuration | ||
function generateURLForTheFeed(options, config) { | ||
if (options.resource === 'github') { | ||
const optionalGitHubAccessToken = config.githubToken !== null ? `?token=${config.githubToken}` : ''; | ||
if (options.type === 'issues') { | ||
return `https://issue-tracker-rss.now.sh/${options.repository}?${querystring.encode(options.params)}`; | ||
// Generates the RSS feed URL with given parameters honoring the configuration | ||
static generateURLForTheFeed(options, config) { | ||
if (options.resource === 'github') { | ||
const optionalGitHubAccessToken = config.githubToken !== null ? `?token=${config.githubToken}` : ''; | ||
if (options.type === 'issues') { | ||
return `https://issue-tracker-rss.now.sh/${options.repository}?${querystring.encode(options.params)}`; | ||
} | ||
if (Object.prototype.hasOwnProperty.call(options, 'subType')) { | ||
return `https://www.github.com/${options.repository}/${options.type}/${options.subType}.atom${optionalGitHubAccessToken}`; | ||
} | ||
return `https://www.github.com/${options.repository}/${options.type}.atom${optionalGitHubAccessToken}`; | ||
} | ||
if (Object.prototype.hasOwnProperty.call(options, 'subType')) { | ||
return `https://www.github.com/${options.repository}/${options.type}/${options.subType}.atom${optionalGitHubAccessToken}`; | ||
} | ||
return `https://www.github.com/${options.repository}/${options.type}.atom${optionalGitHubAccessToken}`; | ||
} | ||
|
||
if (options.resource === 'gitlab') { | ||
if (Object.prototype.hasOwnProperty.call(options, 'subType')) { | ||
return `https://gitlab.com/${options.repository}/-/${options.type}/${options.subType}?format=atom`; | ||
if (options.resource === 'gitlab') { | ||
if (Object.prototype.hasOwnProperty.call(options, 'subType')) { | ||
return `https://gitlab.com/${options.repository}/-/${options.type}/${options.subType}?format=atom`; | ||
} | ||
return `https://gitlab.com/${options.repository}/-/${options.type}?format=atom`; | ||
} | ||
return `https://gitlab.com/${options.repository}/-/${options.type}?format=atom`; | ||
} | ||
|
||
return ''; | ||
return ''; | ||
} | ||
} | ||
|
||
export { | ||
parseFeedData, | ||
generateURLForTheFeed, | ||
// These bottom methods are for rss braider plugin to prepend release name to feed title | ||
isFeedFromGitHub, | ||
isFeedFromGitLab, | ||
getReleaseNameFromGitHubAndGitLabFeedLink, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
import mail from 'nodemailer'; | ||
import striptags from 'striptags'; | ||
|
||
// Sends and e-mail notification to provided user | ||
export default async function sendEmailNotification(config, feedData) { | ||
const transporter = mail.createTransport(config.notifications.email.config); | ||
export default class Email { | ||
// Sends and e-mail notification to provided user | ||
static async sendEmailNotification(config, feedData) { | ||
const transporter = mail.createTransport(config.notifications.email.config); | ||
|
||
/* await smtp.verify((error, success) => { | ||
if (error) { | ||
// console.log(error); | ||
return false; | ||
} | ||
// successful smtp | ||
}); */ | ||
// E-mail options that will be used by nodemailer | ||
const mailOptions = { | ||
from: config.notifications.email.mailOptions.from, | ||
to: config.notifications.email.mailOptions.to, | ||
subject: config.notifications.email.mailOptions.subjectPrefix.length > 0 ? `${config.notifications.email.mailOptions.subjectPrefix} - ${feedData.title}` : feedData.title, | ||
text: `${feedData.link}\n${striptags(feedData.description)}`, | ||
html: `<a target="_blank" href="${feedData.link}">${feedData.title}</a><br><br>${feedData.description}`, | ||
}; | ||
/* await smtp.verify((error, success) => { | ||
if (error) { | ||
// console.log(error); | ||
return false; | ||
} | ||
// successful smtp | ||
}); */ | ||
// E-mail options that will be used by nodemailer | ||
const mailOptions = { | ||
from: config.notifications.email.mailOptions.from, | ||
to: config.notifications.email.mailOptions.to, | ||
subject: config.notifications.email.mailOptions.subjectPrefix.length > 0 ? `${config.notifications.email.mailOptions.subjectPrefix} - ${feedData.title}` : feedData.title, | ||
text: `${feedData.link}\n${striptags(feedData.description)}`, | ||
html: `<a target="_blank" href="${feedData.link}">${feedData.title}</a><br><br>${feedData.description}`, | ||
}; | ||
|
||
// send mail with defined transport object | ||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
// console.log(error); | ||
return false; | ||
} | ||
// console.log('Message sent: %s', info.messageId); | ||
return info; | ||
}); | ||
// send mail with defined transport object | ||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
// console.log(error); | ||
return false; | ||
} | ||
// console.log('Message sent: %s', info.messageId); | ||
return info; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
import PushOver from 'pushover-notifications'; | ||
import striptags from 'striptags'; | ||
|
||
// Send the push notification. | ||
// Todo: why bother with async / await at all ? | ||
export default async function sendPushOverNotification(config, feedData) { | ||
return new Promise((resolve, reject) => { | ||
const pusher = new PushOver({ | ||
user: config.notifications.pushover.config.user, | ||
token: config.notifications.pushover.config.token, | ||
export default class PushOverUtils { | ||
// Send the push notification. | ||
// Todo: why bother with async / await at all ? | ||
static async sendPushOverNotification(config, feedData) { | ||
return new Promise((resolve, reject) => { | ||
const pusher = new PushOver({ | ||
user: config.notifications.pushover.config.user, | ||
token: config.notifications.pushover.config.token, | ||
}); | ||
const msg = { | ||
message: `${striptags(feedData.description)}\n\n${feedData.link}`, | ||
title: feedData.title, | ||
}; | ||
pusher.send(msg, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
// throw err; | ||
return false; | ||
} | ||
resolve(result); | ||
return result; | ||
}); | ||
}); | ||
const msg = { | ||
message: `${striptags(feedData.description)}\n\n${feedData.link}`, | ||
title: feedData.title, | ||
}; | ||
pusher.send(msg, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
// throw err; | ||
return false; | ||
} | ||
resolve(result); | ||
return result; | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.