@eui/tools 6.4.1 → 6.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- 6.4.1
1
+ 6.4.2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 6.4.2 (2023-02-22)
2
+
3
+ ##### Chores
4
+
5
+ * **other:**
6
+ * adapted MS Teams notifications to fetch teams hook from CSDR_ARGS process variable - EUI-7146 [EUI-7146](https://webgate.ec.europa.eu/CITnet/jira/browse/EUI-7146) ([836a9c6a](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/836a9c6a2ca634c6a09be95a1cc3062ff311ec78))
7
+
8
+ * * *
9
+ * * *
1
10
  ## 6.4.1 (2023-02-22)
2
11
 
3
12
  ##### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eui/tools",
3
- "version": "6.4.1",
3
+ "version": "6.4.2",
4
4
  "tag": "latest",
5
5
  "license": "EUPL-1.1",
6
6
  "description": "eUI common tools and scripts",
@@ -42,7 +42,6 @@
42
42
  "chai": "4.3.7",
43
43
  "nyc": "15.1.0",
44
44
  "node-fetch": "2.6.9",
45
- "sendmail": "1.6.1",
46
45
  "svg-sprite": "2.0.2",
47
46
  "imagemin": "7.0.1",
48
47
  "imagemin-svgo": "9.0.0",
package/sandbox.js CHANGED
@@ -1181,8 +1181,9 @@ const versionUtils = require('./scripts/csdr/version/version-utils');
1181
1181
  // })
1182
1182
 
1183
1183
 
1184
+ const teamsUtils = require('./scripts/utils/notification/teams-utils');
1185
+
1184
1186
  Promise.resolve()
1185
1187
  .then(() => {
1186
- const config = configUtils.global.getConfigOptions();
1187
- console.log(config);
1188
+ console.log(teamsUtils.getChannelHook('pipeline-ui-edui'));
1188
1189
  })
@@ -8,7 +8,7 @@ let { dryRun, debug} = tools.getArgs();
8
8
 
9
9
 
10
10
  const sendCore = (subject, body, recipient) => {
11
- const sendmail = require('sendmail')();
11
+ const sendmail = require('sendmail')(); // if used in the future and needed this deps is required : "sendmail": "1.6.1"
12
12
 
13
13
  tools.logInfo(`Sending mail to : ${recipient}`);
14
14
  tools.logInfo('Message subject / body :');
@@ -10,9 +10,6 @@ const tools = require('../tools');
10
10
  const innerConfig = require('./config');
11
11
  const innerTeamsUtils = require('./teams-utils');
12
12
 
13
- // ARGS
14
- const { dryRun, debug, notificationActive } = tools.getArgs();
15
-
16
13
 
17
14
  // ---------------------------------------------------------------------------------------
18
15
  // MESSAGE BUFFER
@@ -44,36 +41,23 @@ module.exports.pushMessage = (message) => {
44
41
  }
45
42
 
46
43
 
47
-
48
44
  const sendMessage = (config) => {
49
-
50
45
  if (config.CLIENT === 'SLACK') {
51
46
  return Promise.resolve();
52
47
  }
53
48
 
54
- if (!notificationActive) {
55
- tools.logInfo('No notifications config found...skipping');
56
-
57
- if (debug) {
58
- console.log(messageContent);
59
- }
60
-
61
- return Promise.resolve();
49
+ return Promise.resolve()
50
+ .then(() => {
51
+ if (config.CLIENT === 'MSTEAMS') {
52
+ return innerTeamsUtils.sendMessage(config, messageContent);
62
53
 
63
- } else {
64
- return Promise.resolve()
65
- .then(() => {
66
- if (config.CLIENT === 'MSTEAMS') {
67
- return innerTeamsUtils.sendMessage(config, messageContent);
68
-
69
- } else if (config.CLIENT === 'MAIL') {
70
- // TODO IF MAIL NOTIF IS NEEDED...
71
- }
72
- })
73
- .catch((e) => {
74
- throw e;
75
- })
76
- }
54
+ } else if (config.CLIENT === 'MAIL') {
55
+ // TODO IF MAIL NOTIF IS NEEDED...
56
+ }
57
+ })
58
+ .catch((e) => {
59
+ throw e;
60
+ })
77
61
  }
78
62
 
79
63
 
@@ -56,8 +56,6 @@ module.exports.sendPackageDiffReportMessage = (pkg, diffMetadata) => {
56
56
  if (config.CLIENT === 'SLACK') {
57
57
  return Promise.resolve()
58
58
  .then(() => {
59
- const config = innerConfig.getPackageConfig(pkg);
60
-
61
59
  return slackUtils.sendPackageDiffReportMessage(
62
60
  diffMetadata,
63
61
  config.SLACK_HOOK,
@@ -9,10 +9,22 @@ const configUtils = require('../../csdr/config/config-utils');
9
9
  const { dryRun, debug} = tools.getArgs();
10
10
 
11
11
 
12
- const getChannelHook = (channelName) => {
13
- // const { msteamsHookMap } = tools.getArgs();
14
- // TODO channel/hook map parser (incoming from _CSDR_ARGS gitlab defs)
15
- return msteamsHook;
12
+ const getChannelHook = module.exports.getChannelHook = (channelName) => {
13
+ const { msteamsHooksArray } = tools.getArgs();
14
+
15
+ const msteamsHook = msteamsHooksArray.filter((h) => {
16
+ return Object.keys(h)[0] === channelName;
17
+ })[0];
18
+
19
+ if (!msteamsHook) {
20
+ tools.logInfo(`Channel hook can't be found for ${channelName} - check _CSDR_ARGS entries in gitlab pipeline configuration`);
21
+
22
+ // TODO set default channels in global config by type
23
+ // const globalConfig = configUtils.global.getConfigOptions();
24
+ return;
25
+ }
26
+
27
+ return msteamsHook[channelName];
16
28
  }
17
29
 
18
30
 
@@ -91,15 +103,19 @@ module.exports.sendMessage = (config, messageContent) => {
91
103
  tools.logTitle('Sending MS teams message');
92
104
 
93
105
  const channelHook = getChannelHook(config.MSTEAMS_CHANNEL);
106
+
107
+ if (!channelHook) {
108
+ return Promise.resolve();
109
+ }
110
+
94
111
  const payload = createPayload(messageContent);
95
112
 
113
+ if (debug) {
114
+ console.log(messageContent);
115
+ console.log(JSON.parse(JSON.stringify(payload, null, 2)));
116
+ }
117
+
96
118
  return Promise.resolve()
97
- .then(() => {
98
- if (debug) {
99
- console.log(messageContent);
100
- console.log(JSON.parse(JSON.stringify(payload, null, 2)));
101
- }
102
- })
103
119
  .then(() => {
104
120
  const host = configUtils.global.getConfigOptions().MSTEAMS_HOST;
105
121
 
@@ -68,8 +68,24 @@ function getArgs() {
68
68
 
69
69
  if (processArgs) {
70
70
  processArgs.split(',').forEach((item) => {
71
- const itemSplit = item.split(':');
72
- args[itemSplit[0].trim()] = itemSplit[1].trim();
71
+ // check if it's defined as array - example format : someArray:test1=test1|test2=test2
72
+ if (item.indexOf('Array') > 0) {
73
+ const arrayItems = item.split(':')[1];
74
+ const subItems = arrayItems.split('|');
75
+ const array = [];
76
+ subItems.forEach((sub) => {
77
+ const subItemSplit = sub.split('=');
78
+ const newItem = {};
79
+ newItem[subItemSplit[0].trim()] = subItemSplit[1].trim();
80
+ array.push(newItem);
81
+ args[item.split(':')[0]] = array;
82
+ })
83
+
84
+ // otherwise normal key/value pairs - example format : test1:test1,test2:test2
85
+ } else {
86
+ const itemSplit = item.split(':');
87
+ args[itemSplit[0].trim()] = itemSplit[1].trim();
88
+ }
73
89
  })
74
90
  }
75
91
 
@@ -1,127 +0,0 @@
1
- 'use strict';
2
-
3
- // GLOBAL
4
- const moment = require('moment');
5
-
6
- // LOCAL
7
- const mailUtils = require('./mail-utils');
8
- const tools = require('../tools');
9
-
10
- // INNER
11
- const innerConfig = require('./config');
12
-
13
- // FETCH ARGS
14
- let { dryRun, debug } = tools.getArgs();
15
-
16
- // ---------------------------------------------------------------------------------------
17
- // MAIL BUFFER
18
- // - used for storing all message happening during a run
19
- // - used for MS Teams mail notifications, to avoid multiple message send for a single run
20
- // ---------------------------------------------------------------------------------------
21
-
22
- const mailContent = {
23
- buffer: [],
24
- exception: null,
25
- };
26
-
27
- module.exports.startMailStack = () => {
28
- mailContent.buffer.push(`CSDR RUN - START - ${moment(new Date()).format("DD/MM/YYYY HH:mm")}\n\n`);
29
- }
30
-
31
- module.exports.endMailStack = () => {
32
- mailContent.buffer.push(`CSDR RUN - END - ${moment(new Date()).format("DD/MM/YYYY HH:mm")}`);
33
- }
34
-
35
- module.exports.bufferMessage = (message) => {
36
- if (message.text) {
37
- mailContent.buffer.push(message.text);
38
-
39
- } else {
40
- mailContent.buffer.push(message.mainTitle);
41
- mailContent.buffer.push(message.mainText);
42
-
43
- if (message.detailTitle) {
44
- mailContent.buffer.push(message.detailTitle);
45
- mailContent.buffer.push(message.detailText);
46
- }
47
-
48
- if (message.scope) {
49
- let subMessage = `>> <b>${message.scope}</b>`;
50
- if (message.version) {
51
- subMessage += `- <b>${message.version}</b>`;
52
- }
53
- mailContent.buffer.push(subMessage);
54
- }
55
- }
56
-
57
- if (message.exception) {
58
- mailContent.exception = message.exception;
59
- }
60
- }
61
-
62
-
63
- const sendMailStack = (config, scope, target) => {
64
- return Promise.resolve()
65
- .then(() => {
66
- let statusColor = 'green', status = 'SUCCESS';
67
-
68
- if (mailContent.exception) {
69
- statusColor = 'red';
70
- status = 'ERROR';
71
- }
72
-
73
- // const subject = `RELEASE <b style="color: ${statusColor};">${status}</b> - <b style="color:blue;">${scope}</b> - branch: <b styles="color: blue;">${target}</b>`;
74
- const subject = `Release of **${scope}** for ${target} ---- status : ${status}`;
75
- let fullMessage = `<pre>${mailContent.buffer.join('\n')}</pre>`;
76
-
77
- if (mailContent.exception) {
78
- fullMessage += mailContent.exception;
79
- }
80
-
81
- if (config.CLIENT === 'MAIL') {
82
- return mailUtils.sendMessage(subject, fullMessage, config.MAIL_ADDRESS);
83
-
84
- } else {
85
- console.log(fullMessage);
86
- }
87
- })
88
-
89
- .catch((e) => {
90
- throw e;
91
- })
92
- }
93
-
94
-
95
-
96
-
97
- module.exports.sendMailStackPackage = (pkg, branches) => {
98
-
99
- // getting package notification config
100
- const config = innerConfig.getPackageConfig(pkg);
101
-
102
- return Promise.resolve()
103
- .then(() => {
104
- return sendMailStack(config, pkg.name, branches.branch);
105
- })
106
-
107
- .catch((e) => {
108
- throw e;
109
- })
110
- }
111
-
112
-
113
- module.exports.sendMailStackProject = (project, envTarget) => {
114
-
115
- // getting package notification config
116
- const config = innerConfig.getProjectConfig(project);
117
-
118
- return Promise.resolve()
119
- .then(() => {
120
- return sendMailStack(config, project.name, envTarget);
121
- })
122
-
123
- .catch((e) => {
124
- throw e;
125
- })
126
- }
127
-