fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-18 19:37:45 +02:00
parent ccc2fc689f
commit 07ea092dea
7 changed files with 159 additions and 58 deletions

View File

@ -54,7 +54,7 @@ testBuild:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
@ -65,7 +65,7 @@ testBuild:
release: release:
stage: release stage: release
script: script:
- npmci node install lts - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags

110
package-lock.json generated
View File

@ -4,6 +4,26 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@babel/code-frame": {
"version": "7.5.5",
"resolved": "https://verdaccio.lossless.one/@babel%2fcode-frame/-/code-frame-7.5.5.tgz",
"integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==",
"dev": true,
"requires": {
"@babel/highlight": "^7.0.0"
}
},
"@babel/highlight": {
"version": "7.5.0",
"resolved": "https://verdaccio.lossless.one/@babel%2fhighlight/-/highlight-7.5.0.tgz",
"integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==",
"dev": true,
"requires": {
"chalk": "^2.0.0",
"esutils": "^2.0.2",
"js-tokens": "^4.0.0"
}
},
"@gitzone/tsbuild": { "@gitzone/tsbuild": {
"version": "2.1.17", "version": "2.1.17",
"resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbuild/-/tsbuild-2.1.17.tgz", "resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbuild/-/tsbuild-2.1.17.tgz",
@ -473,6 +493,12 @@
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
"dev": true "dev": true
}, },
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://verdaccio.lossless.one/builtin-modules/-/builtin-modules-1.1.1.tgz",
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=",
"dev": true
},
"camelcase": { "camelcase": {
"version": "5.3.1", "version": "5.3.1",
"resolved": "https://verdaccio.lossless.one/camelcase/-/camelcase-5.3.1.tgz", "resolved": "https://verdaccio.lossless.one/camelcase/-/camelcase-5.3.1.tgz",
@ -609,6 +635,12 @@
"delayed-stream": "~1.0.0" "delayed-stream": "~1.0.0"
} }
}, },
"commander": {
"version": "2.20.0",
"resolved": "https://verdaccio.lossless.one/commander/-/commander-2.20.0.tgz",
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
"dev": true
},
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -707,6 +739,12 @@
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true "dev": true
}, },
"esutils": {
"version": "2.0.3",
"resolved": "https://verdaccio.lossless.one/esutils/-/esutils-2.0.3.tgz",
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true
},
"execa": { "execa": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://verdaccio.lossless.one/execa/-/execa-1.0.0.tgz", "resolved": "https://verdaccio.lossless.one/execa/-/execa-1.0.0.tgz",
@ -881,6 +919,12 @@
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"dev": true "dev": true
}, },
"js-tokens": {
"version": "4.0.0",
"resolved": "https://verdaccio.lossless.one/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"js-yaml": { "js-yaml": {
"version": "3.13.1", "version": "3.13.1",
"resolved": "https://verdaccio.lossless.one/js-yaml/-/js-yaml-3.13.1.tgz", "resolved": "https://verdaccio.lossless.one/js-yaml/-/js-yaml-3.13.1.tgz",
@ -988,6 +1032,21 @@
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
}, },
"minimist": {
"version": "0.0.8",
"resolved": "https://verdaccio.lossless.one/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://verdaccio.lossless.one/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": {
"minimist": "0.0.8"
}
},
"moment": { "moment": {
"version": "2.24.0", "version": "2.24.0",
"resolved": "https://verdaccio.lossless.one/moment/-/moment-2.24.0.tgz", "resolved": "https://verdaccio.lossless.one/moment/-/moment-2.24.0.tgz",
@ -1152,6 +1211,12 @@
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=",
"dev": true "dev": true
}, },
"path-parse": {
"version": "1.0.6",
"resolved": "https://verdaccio.lossless.one/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"dev": true
},
"pathval": { "pathval": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
@ -1219,6 +1284,15 @@
"integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=",
"dev": true "dev": true
}, },
"resolve": {
"version": "1.12.0",
"resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.12.0.tgz",
"integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==",
"dev": true,
"requires": {
"path-parse": "^1.0.6"
}
},
"restore-cursor": { "restore-cursor": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://verdaccio.lossless.one/restore-cursor/-/restore-cursor-2.0.0.tgz", "resolved": "https://verdaccio.lossless.one/restore-cursor/-/restore-cursor-2.0.0.tgz",
@ -1409,6 +1483,42 @@
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==",
"dev": true "dev": true
}, },
"tslint": {
"version": "5.20.0",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
"integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
"builtin-modules": "^1.1.1",
"chalk": "^2.3.0",
"commander": "^2.12.1",
"diff": "^4.0.1",
"glob": "^7.1.1",
"js-yaml": "^3.13.1",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8.0",
"tsutils": "^2.29.0"
}
},
"tslint-config-prettier": {
"version": "1.18.0",
"resolved": "https://verdaccio.lossless.one/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz",
"integrity": "sha512-xPw9PgNPLG3iKRxmK7DWr+Ea/SzrvfHtjFt5LBl61gk2UBG/DB9kCXRjv+xyIU1rUtnayLeMUVJBcMX8Z17nDg==",
"dev": true
},
"tsutils": {
"version": "2.29.0",
"resolved": "https://verdaccio.lossless.one/tsutils/-/tsutils-2.29.0.tgz",
"integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==",
"dev": true,
"requires": {
"tslib": "^1.8.1"
}
},
"type-detect": { "type-detect": {
"version": "4.0.8", "version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",

View File

@ -17,7 +17,9 @@
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.24",
"@pushrocks/qenv": "^4.0.4", "@pushrocks/qenv": "^4.0.4",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.4" "@types/node": "^12.7.4",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.0.5", "@pushrocks/smartpromise": "^3.0.5",

View File

@ -8,11 +8,11 @@ import * as slackme from '../ts/index';
let testSlackAccount: slackme.SlackAccount; let testSlackAccount: slackme.SlackAccount;
let testSlackMessage: slackme.SlackMessage; let testSlackMessage: slackme.SlackMessage;
tap.test('should create a valid slackme instance', async (tools) => { tap.test('should create a valid slackme instance', async tools => {
testSlackAccount = new slackme.SlackAccount(testQenv.getEnvVarOnDemand('SLACK_TOKEN')); testSlackAccount = new slackme.SlackAccount(testQenv.getEnvVarOnDemand('SLACK_TOKEN'));
}); });
tap.test('should send a message to Slack', async (tools) => { tap.test('should send a message to Slack', async tools => {
const messageOptions = { const messageOptions = {
author_name: 'GitLab CI', author_name: 'GitLab CI',
author_link: 'https://gitlab.com/', author_link: 'https://gitlab.com/',
@ -38,28 +38,25 @@ tap.test('should send a message to Slack', async (tools) => {
}); });
}); });
tap.test('should send a message to Slack by directly calling the message', async (tools) => { tap.test('should send a message to Slack by directly calling the message', async tools => {
testSlackMessage = new slackme.SlackMessage( testSlackMessage = new slackme.SlackMessage(testSlackAccount, {
testSlackAccount, author_name: 'GitLab CI',
{ author_link: 'https://gitlab.com/',
author_name: 'GitLab CI', pretext: '*Good News*: Build successfull!',
author_link: 'https://gitlab.com/', color: '#3cb371',
pretext: '*Good News*: Build successfull!', fields: [
color: '#3cb371', {
fields: [ title: 'Branch',
{ value: 'Lossless Cloud',
title: 'Branch', short: true
value: 'Lossless Cloud', },
short: true {
}, title: 'Product ID',
{ value: 'pushrocks',
title: 'Product ID', short: true
value: 'pushrocks', }
short: true ]
} });
]
}
);
await testSlackMessage.sendToRoom('random'); await testSlackMessage.sendToRoom('random');
await tools.delayFor(1000); await tools.delayFor(1000);
await testSlackMessage.updateAndSend({ await testSlackMessage.updateAndSend({
@ -115,21 +112,19 @@ tap.test('should send a message to Slack by directly calling the message', async
short: true short: true
} }
] ]
}) });
}); });
tap.test('should send logs', async () => { tap.test('should send logs', async () => {
const slackLog = new slackme.SlackLog({ const slackLog = new slackme.SlackLog({
slackAccount: testSlackAccount, slackAccount: testSlackAccount,
channelName: 'random' channelName: 'random'
}) });
for (let i = 0; i < 30; i++) { for (let i = 0; i < 30; i++) {
await slackLog.sendLogLine('hi there'); await slackLog.sendLogLine('hi there');
await slackLog.sendLogLine('so awesome'); await slackLog.sendLogLine('so awesome');
await slackLog.sendLogLine('really'); await slackLog.sendLogLine('really');
} }
});
})
tap.start(); tap.start();

View File

@ -15,27 +15,25 @@ export class SlackAccount {
ts?: string; ts?: string;
mode: 'new' | 'threaded' | 'update'; mode: 'new' | 'threaded' | 'update';
}) { }) {
let requestBody: any = { let requestBody: any = {
channel: optionsArg.channelArg, channel: optionsArg.channelArg,
text: optionsArg.messageOptions.text, text: optionsArg.messageOptions.text
}; };
if (optionsArg.messageOptions.fields) { if (optionsArg.messageOptions.fields) {
requestBody = { requestBody = {
...requestBody, ...requestBody,
attachments: [{ attachments: [
pretext: optionsArg.messageOptions.pretext, {
fields: optionsArg.messageOptions.fields, pretext: optionsArg.messageOptions.pretext,
ts: optionsArg.messageOptions.ts, fields: optionsArg.messageOptions.fields,
color: optionsArg.messageOptions.color ts: optionsArg.messageOptions.ts,
}] color: optionsArg.messageOptions.color
} }
]
};
} }
let postUrl = this.postUrl; let postUrl = this.postUrl;
switch (true) { switch (true) {
@ -50,8 +48,7 @@ export class SlackAccount {
requestBody = { requestBody = {
...requestBody, ...requestBody,
thread_ts: optionsArg.ts thread_ts: optionsArg.ts
};
}
break; break;
} }

View File

@ -1,5 +1,5 @@
import { SlackAccount } from "./slack.classes.slackaccount"; import { SlackAccount } from './slack.classes.slackaccount';
import { SlackMessage } from "./slack.classes.slackmessage"; import { SlackMessage } from './slack.classes.slackmessage';
export class SlackLog { export class SlackLog {
public slackAccount: SlackAccount; public slackAccount: SlackAccount;
@ -8,10 +8,7 @@ export class SlackLog {
public completeLog = ``; public completeLog = ``;
constructor(optionsArg: { constructor(optionsArg: { slackAccount: SlackAccount; channelName: string }) {
slackAccount: SlackAccount;
channelName: string;
}) {
this.slackAccount = optionsArg.slackAccount; this.slackAccount = optionsArg.slackAccount;
this.channelName = optionsArg.channelName; this.channelName = optionsArg.channelName;
} }
@ -23,10 +20,10 @@ export class SlackLog {
await this.slackMessage.sendToRoom(this.channelName); await this.slackMessage.sendToRoom(this.channelName);
} }
const date = new Date(); const date = new Date();
this.completeLog += `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} - ` + logText + '\n'; this.completeLog +=
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} - ` + logText + '\n';
await this.slackMessage.updateAndSend({ await this.slackMessage.updateAndSend({
text: '```\n' + this.completeLog + '\n```' text: '```\n' + this.completeLog + '\n```'
}) });
} }
}
};

View File

@ -75,7 +75,7 @@ export class SlackMessage {
async startThread(messageOptionsArg: IMessageOptions) { async startThread(messageOptionsArg: IMessageOptions) {
this.messageOptions = messageOptionsArg; this.messageOptions = messageOptionsArg;
this.sendToRoom(this.channel, 'threaded') this.sendToRoom(this.channel, 'threaded');
} }
async sendToRoom(channelNameArg: string, modeArg: 'new' | 'update' | 'threaded' = 'new') { async sendToRoom(channelNameArg: string, modeArg: 'new' | 'update' | 'threaded' = 'new') {