Skip to content

Commit aae1f7c

Browse files
authored
URL Parsing fixes and Support for host:port format (#30)
* Add support for host:port format * Update Task versions and packaging logging fix * URL parsing fixes
1 parent 3048c5d commit aae1f7c

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

Tasks/emailReportTask/EmailSender.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,34 @@ import { Report } from "./model/Report";
55
import { MailError } from "./exceptions/MailError";
66
import { isNullOrUndefined } from "util";
77
const nodemailer = require("nodemailer");
8+
const url = require("url");
89

910
export class EmailSender implements IReportSender {
1011
public async sendReportAsync(report: Report, htmlReportMessage: string, mailConfiguration: MailConfiguration): Promise<boolean> {
1112
const mailAddressViewModel = new MailAddressViewModel(report, mailConfiguration);
1213

14+
let smtpUrlProvided = mailConfiguration.$smtpConfig.$smtpHost;
15+
console.log(`Using SmtpHost URL: ${smtpUrlProvided}`);
16+
smtpUrlProvided = smtpUrlProvided.includes("://") ? smtpUrlProvided : "smtp://" + smtpUrlProvided;
17+
console.log(`Parsed Url: ${smtpUrlProvided}`);
18+
let smtpUrl = url.parse(smtpUrlProvided, true);
19+
20+
console.log(`Host: ${smtpUrl.host}`);
21+
console.log(`HostName: ${smtpUrl.hostname}`);
22+
console.log(`Port: ${smtpUrl.port}`);
23+
console.log(`Protocol: ${smtpUrl.protocol}`);
24+
25+
const smtpHost = smtpUrl.hostname;
26+
let smtpPort = smtpUrl.port;
27+
smtpPort = isNullOrUndefined(smtpUrl.port) ? 587 : smtpUrl.port;
28+
29+
console.log(`Using HostName: ${smtpHost} and port: ${smtpPort}`);
30+
1331
let transporter: any;
14-
if(mailConfiguration.$smtpConfig.$enableTLS) {
32+
if(mailConfiguration.$smtpConfig.$enableTLS) {
1533
transporter = nodemailer.createTransport({
16-
host: mailConfiguration.$smtpConfig.$smtpHost,
17-
port: 587,
34+
host: smtpHost,
35+
port: smtpPort,
1836
tls: {
1937
maxVersion: 'TLSv1.2',
2038
minVersion: 'TLSv1.2',
@@ -29,8 +47,8 @@ export class EmailSender implements IReportSender {
2947
}
3048
else {
3149
transporter = nodemailer.createTransport({
32-
host: mailConfiguration.$smtpConfig.$smtpHost,
33-
port: 587,
50+
host: smtpHost,
51+
port: smtpPort,
3452
auth: {
3553
user: mailConfiguration.$smtpConfig.$userName,
3654
pass: mailConfiguration.$smtpConfig.$password

Tasks/emailReportTask/task.dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 2,
16-
"Patch": 200
16+
"Patch": 202
1717
},
1818
"groups": [
1919
{

Tasks/emailReportTask/task.prod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 1,
16-
"Patch": 2
16+
"Patch": 5
1717
},
1818
"groups": [
1919
{

Tasks/emailReportTask/tests/__e_to_e_tests__/InvokeTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ export class ReportCreatorWrapper implements IHTMLReportCreator {
5757
export class MockConfigProvider implements IConfigurationProvider {
5858

5959
getPipelineConfiguration(): PipelineConfiguration {
60-
return new PipelineConfiguration(PipelineType.Release, 13942411, "AzureDevOps", "AzureDevOps", 160977787, 9462, false, "https://dev.azure.com/{account}/", accessKey);
60+
return new PipelineConfiguration(PipelineType.Release, 13942411, "ProjectId", "ProjectName", 160977787, 9462, false, "https://dev.azure.com/{account}/", accessKey);
6161
}
6262

6363
getMailConfiguration(): MailConfiguration {
6464
return new MailConfiguration("[{environmentStatus}] {passPercentage} tests passed",
65-
new RecipientsConfiguration("xyz@test.com", false, false, false, false),
65+
new RecipientsConfiguration("xyz@email.com", false, false, false, false),
6666
new RecipientsConfiguration("", false, false, false, false),
67-
new SmtpConfiguration(smtpUser, smtpPassword, "smtp.live.com", true), "test.m");
67+
new SmtpConfiguration(smtpUser, smtpPassword, "smtp.live.com", true), "test.com");
6868
}
6969

7070
getReportDataConfiguration(): ReportDataConfiguration {

Tasks/emailReportTask/vss-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "EmailReportExtension",
44
"name": "Email Report Extension",
5-
"version": "1.1.0",
5+
"version": "1.1.5",
66
"publisher": "epsteam",
77
"targets": [
88
{

commands/package.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exec(npmInstallCommand, function (error) {
2525
console.log(`NPM Install Error: ${error}`);
2626
} else {
2727
console.log("NPM Install Done");
28-
28+
2929
var imagesDir = path.resolve(common.TaskSrcDir, "images");
3030
if (fs.existsSync(imagesDir)) {
3131
var files = fs.readdirSync(imagesDir);
@@ -37,7 +37,7 @@ exec(npmInstallCommand, function (error) {
3737
}
3838
});
3939

40-
if(fs.existsSync(path.resolve(imagesDir, "icon.png"))) {
40+
if (fs.existsSync(path.resolve(imagesDir, "icon.png"))) {
4141
common.CopyFile(imagesDir, "icon.png", `${common.TaskOutDir}`);
4242
}
4343
}
@@ -52,10 +52,12 @@ exec(npmInstallCommand, function (error) {
5252
console.log(`Package create error: ${error}`);
5353
} else {
5454
console.log("Package created. Upload the VSIX to Visual Studio Marketplace if you wish to publish the extension.");
55-
console.log(`If you want to upload to AzureDevOps account directly, then Navigate to ${common.TaskOutDir} and run the tfx upload command on the desired azure devops account to upload task directly. Command: 'tfx login && tfx build tasks upload --task-path .'`);
56-
process.chdir(cwd);
55+
console.log(`If you want to upload to an AzureDevOps account directly, then Navigate to: \r\n${common.TaskOutDir}\r\n and run the following command: \r\n'tfx login && tfx build tasks upload --task-path .'\r\n`);
56+
process.chdir(cwd);
5757
}
5858
});
59+
} else {
60+
console.log(`\r\nIf you want to upload to an AzureDevOps account directly, then Navigate to: \r\n${common.TaskOutDir}\r\n and run the following command: \r\n'tfx login && tfx build tasks upload --task-path .'\r\n`);
5961
}
6062
}
6163
});

0 commit comments

Comments
 (0)