Skip to content

Commit

Permalink
Merge 1a96b36 into 83d809a
Browse files Browse the repository at this point in the history
  • Loading branch information
Vali0 committed Nov 1, 2018
2 parents 83d809a + 1a96b36 commit ab2250d
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 61 deletions.
40 changes: 34 additions & 6 deletions lib/Gmail.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
const path = require('path');
const nodemailer = require('nodemailer');
const pug = require('pug');

/*
* Gmail requires browser authorisation and client must verify requested access rights to his account by the application.
* This means there is no way to obtain tokens with calls.
* Therefore you must obtain your refresh token via browser, postman, google playground or another preferable by you way.
*/
class Gmail {
constructor(credentials) {
this.user = credentials.user;
this.id = credentials.clientId;
this.secret = credentials.clientSecret;
this.accessToken = credentials.accessToken;
this.refreshToken = credentials.refreshToken;
constructor(configuration) {
this.user = configuration.user;
this.id = configuration.clientId;
this.secret = configuration.clientSecret;
this.accessToken = configuration.accessToken;
this.refreshToken = configuration.refreshToken;
this.options = configuration.options;
}

get user() {
Expand Down Expand Up @@ -74,6 +77,31 @@ class Gmail {
this._refreshToken = refreshToken;
}

get options() {
return this._options;
}

set options(options) {
let opts = {};

if (options && options.templatePath) {
let configurationPath = path.join('config', options.templatePath);

opts.templatePath = configurationPath;
} else {
opts.templatePath = path.join(__dirname, 'email.pug');
}

this._options = opts;
}

compileTemplate(context) {
let template = pug.compileFile(this.options.templatePath);
let content = template(context);

return content;
}

sendEmail(sender, recipientsObject, subject, content) {
let transporter = nodemailer.createTransport({
service: 'gmail',
Expand Down
17 changes: 17 additions & 0 deletions lib/email.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
table(cellspacing="0" cellpadding="10" style="border-collapse: collapse;font-family: Arial, Helvetica, sans-serif;border: 1px solid #999;text-align: left;")
each pullRequests, key in data
thead
tr
th(colspan="2" style="font-family: Arial, Helvetica, sans-serif;font-size: 19px;text-align: left;background: #666;border: 1px solid #666;color: #fff;")
= key
th(style="font-family: Arial, Helvetica, sans-serif;font-size: 19px;text-align: left;background: #666;border: 1px solid #666;color: #fff;")
| Author
tbody
each pullRequest in pullRequests
tr
td(style="font-family: Arial, Helvetica, sans-serif;border: 1px solid #999;text-align: left;" valign="top")
a(href="{{this.jiraUrl}}")= pullRequest.id
td(style="font-family: Arial, Helvetica, sans-serif;border: 1px solid #999;text-align: left;" valign="top")
a(href="{{this.prUrl}}")= pullRequest.title
td(style="font-family: Arial, Helvetica, sans-serif;border: 1px solid #999;text-align: left;" valign="top")
a(href="{{this.author.account}}")= pullRequest.author.displayName
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitbucket-notifications",
"version": "1.2.4",
"version": "1.2.5",
"description": "Node.js application which can send an email with links to all PRs that have been merged in last 24 hours. It connects to Bitbucket, Gmail and Jira with OAuth2 for higher security by simply adding your credentials in configuration file.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -35,9 +35,9 @@
},
"license": "MIT",
"dependencies": {
"handlebars": "^4.0.11",
"moment": "^2.22.2",
"nodemailer": "^4.6.7",
"pug": "^2.0.3",
"request": "^2.87.0",
"request-promise": "^4.2.2"
},
Expand All @@ -49,7 +49,7 @@
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.3.0",
"proxyquire": "^2.0.1",
"sinon": "^6.0.1"
"sinon": "^7.1.1"
},
"engines": {
"node": ">=8.9.4"
Expand Down

0 comments on commit ab2250d

Please sign in to comment.