testbeats 2.2.4 → 2.2.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testbeats",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
5
5
  "main": "src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -1,6 +1,7 @@
1
1
  const TestResult = require('test-results-parser/src/models/TestResult');
2
2
  const logger = require('../utils/logger');
3
- const { addChatExtension, addSlackExtension, addTeamsExtension } = require('../helpers/extension.helper');
3
+ const { addChatExtension, addSlackExtension, addTeamsExtension, addGithubExtension } = require('../helpers/extension.helper');
4
+ const { getPlatform } = require('../platforms');
4
5
 
5
6
  class BaseExtension {
6
7
 
@@ -32,6 +33,11 @@ class BaseExtension {
32
33
  * @type {import('..').IExtensionDefaultOptions}
33
34
  */
34
35
  this.default_options = {};
36
+
37
+ /**
38
+ * @type {import('../platforms').BasePlatform}
39
+ */
40
+ this.platform = getPlatform(this.target.name);
35
41
  }
36
42
 
37
43
  updateExtensionInputs() {
@@ -46,6 +52,9 @@ class BaseExtension {
46
52
  case 'chat':
47
53
  this.extension.inputs = Object.assign({}, { separator: true }, this.extension.inputs);
48
54
  break;
55
+ case 'github':
56
+ this.extension.inputs = Object.assign({}, { separator: true }, this.extension.inputs);
57
+ break;
49
58
  default:
50
59
  break;
51
60
  }
@@ -67,6 +76,9 @@ class BaseExtension {
67
76
  case 'chat':
68
77
  addChatExtension({ payload: this.payload, extension: this.extension, text: this.text });
69
78
  break;
79
+ case 'github':
80
+ addGithubExtension({ payload: this.payload, extension: this.extension, text: this.text });
81
+ break;
70
82
  default:
71
83
  break;
72
84
  }
@@ -84,6 +96,8 @@ class BaseExtension {
84
96
  return _texts.join('\n');
85
97
  case 'chat':
86
98
  return _texts.join('<br>');
99
+ case 'github':
100
+ return _texts.join('\n');
87
101
  default:
88
102
  break;
89
103
  }
@@ -100,6 +114,8 @@ class BaseExtension {
100
114
  return `*${text}*`;
101
115
  case 'chat':
102
116
  return `<b>${text}</b>`;
117
+ case 'github':
118
+ return `**${text}**`;
103
119
  default:
104
120
  break;
105
121
  }
@@ -38,7 +38,7 @@ class ErrorClustersExtension extends BaseExtension {
38
38
  for (const cluster of clusters) {
39
39
  texts.push(`${truncate(cluster.failure, 150)} - ${this.bold(`(x${cluster.count})`)}`);
40
40
  }
41
- this.text = this.mergeTexts(texts);
41
+ this.text = this.platform.bullets(texts);
42
42
  }
43
43
  }
44
44
 
@@ -100,6 +100,15 @@ function addChatExtension({ payload, extension, text }) {
100
100
  });
101
101
  }
102
102
 
103
+ function addGithubExtension({ payload, extension, text }) {
104
+ if (extension.inputs.title) {
105
+ const title = extension.inputs.title_link ? `[${extension.inputs.title}](${extension.inputs.title_link})` : extension.inputs.title;
106
+ payload.content.push(`**${title}**\n${text}\n\n`);
107
+ } else {
108
+ payload.content.push(`${text}\n\n`);
109
+ }
110
+ }
111
+
103
112
  /**
104
113
  * Sort extensions by their order property.
105
114
  * Extensions without order will appear last, maintaining their original relative order.
@@ -123,5 +132,6 @@ module.exports = {
123
132
  addSlackExtension,
124
133
  addTeamsExtension,
125
134
  addChatExtension,
135
+ addGithubExtension,
126
136
  sortExtensionsByOrder
127
137
  }
@@ -6,11 +6,29 @@ class BasePlatform {
6
6
  * @param {string|number} text
7
7
  */
8
8
  bold(text) {
9
- throw new Error('Not Implemented');
9
+ return `**${text}**`;
10
10
  }
11
11
 
12
12
  break() {
13
- throw new Error('Not Implemented');
13
+ return '\n';
14
+ }
15
+
16
+ /**
17
+ * @param {string[]} values
18
+ */
19
+ merge(values) {
20
+ return this.getValidTexts(values).join(this.break());
21
+ }
22
+
23
+ /**
24
+ * @param {string[]} items - Array of strings to convert to bullet points
25
+ * @returns {string} - Formatted bullet points as a string
26
+ */
27
+ bullets(items) {
28
+ if (!items || !Array.isArray(items) || items.length === 0) {
29
+ return '';
30
+ }
31
+ return this.merge(items.map(item => `- ${item}`));
14
32
  }
15
33
 
16
34
  /**
@@ -123,6 +141,14 @@ class BasePlatform {
123
141
 
124
142
  return texts.join(' • ');
125
143
  }
144
+
145
+ /**
146
+ * @param {string[]} texts
147
+ * @returns {string[]}
148
+ */
149
+ getValidTexts(texts) {
150
+ return texts.filter(text => !!text);
151
+ }
126
152
  }
127
153
 
128
154
  module.exports = { BasePlatform }
@@ -13,6 +13,17 @@ class ChatPlatform extends BasePlatform {
13
13
  return '<br>';
14
14
  }
15
15
 
16
+ /**
17
+ * @param {string[]} items - Array of strings to convert to bullet points
18
+ * @returns {string} - Formatted bullet points as a string
19
+ */
20
+ bullets(items) {
21
+ if (!items || !Array.isArray(items) || items.length === 0) {
22
+ return '';
23
+ }
24
+ return this.merge(items.map(item => `• ${item}`));
25
+ }
26
+
16
27
  }
17
28
 
18
29
  module.exports = { ChatPlatform }
@@ -2,17 +2,6 @@ const { BasePlatform } = require('./base.platform');
2
2
 
3
3
  class GitHubPlatform extends BasePlatform {
4
4
 
5
- /**
6
- * @param {string|number} text
7
- */
8
- bold(text) {
9
- return `**${text}**`;
10
- }
11
-
12
- break() {
13
- return '\n';
14
- }
15
-
16
5
  }
17
6
 
18
7
  module.exports = { GitHubPlatform };
@@ -9,8 +9,15 @@ class SlackPlatform extends BasePlatform {
9
9
  return `*${text}*`;
10
10
  }
11
11
 
12
- break() {
13
- return '\n';
12
+ /**
13
+ * @param {string[]} items - Array of strings to convert to bullet points
14
+ * @returns {string} - Formatted bullet points as a string
15
+ */
16
+ bullets(items) {
17
+ if (!items || !Array.isArray(items) || items.length === 0) {
18
+ return '';
19
+ }
20
+ return this.merge(items.map(item => `• ${item}`));
14
21
  }
15
22
  }
16
23
 
@@ -1,16 +1,21 @@
1
1
  const { BasePlatform } = require("./base.platform");
2
2
 
3
3
  class TeamsPlatform extends BasePlatform {
4
- /**
5
- * @param {string|number} text
6
- */
7
- bold(text) {
8
- return `**${text}**`;
9
- }
10
4
 
11
5
  break() {
12
6
  return '\n\n';
13
7
  }
8
+
9
+ /**
10
+ * @param {string[]} items - Array of strings to convert to bullet points
11
+ * @returns {string} - Formatted bullet points as a string
12
+ */
13
+ bullets(items) {
14
+ if (!items || !Array.isArray(items) || items.length === 0) {
15
+ return '';
16
+ }
17
+ return this.merge(items.map(item => `- ${item}`));
18
+ }
14
19
  }
15
20
 
16
21
  module.exports = { TeamsPlatform }
@@ -136,7 +136,7 @@ async function publishToGitHub({ target, message }) {
136
136
  const token = target.inputs.token || process.env.GITHUB_TOKEN;
137
137
 
138
138
  if (!token) {
139
- throw new Error('GitHub token is required. Set GITHUB_TOKEN environment variable or provide github_token in target inputs.');
139
+ throw new Error('GitHub token is required. Set GITHUB_TOKEN environment variable or provide token in target inputs.');
140
140
  }
141
141
 
142
142
  if (!pull_number) {
@@ -155,7 +155,7 @@ async function publishToGitHub({ target, message }) {
155
155
 
156
156
  if (target.inputs.update_comment) {
157
157
  // Try to find existing comment and update it
158
- const existingComment = await findExistingComment({ owner, repo, pull_number, github_token: token, comment_title: target.inputs.comment_title });
158
+ const existingComment = await findExistingComment({ owner, repo, pull_number, token, comment_title: target.inputs.comment_title });
159
159
  if (existingComment) {
160
160
  return request.patch({
161
161
  url: `${url}/repos/${owner}/${repo}/issues/comments/${existingComment.id}`,
@@ -173,13 +173,13 @@ async function publishToGitHub({ target, message }) {
173
173
  });
174
174
  }
175
175
 
176
- async function findExistingComment({ owner, repo, pull_number, github_token, comment_title }) {
176
+ async function findExistingComment({ owner, repo, pull_number, token, comment_title }) {
177
177
  if (!comment_title) return null;
178
178
 
179
179
  try {
180
180
  const url = `https://api.github.com/repos/${owner}/${repo}/issues/${pull_number}/comments`;
181
181
  const headers = {
182
- 'Authorization': `token ${github_token}`,
182
+ 'Authorization': `token ${token}`,
183
183
  'Accept': 'application/vnd.github.v3+json',
184
184
  'User-Agent': 'testbeats'
185
185
  };
@@ -280,7 +280,7 @@ async function handleErrors({ target, errors }) {
280
280
  }
281
281
 
282
282
  const default_inputs = {
283
- github_token: undefined,
283
+ token: undefined,
284
284
  comment_title: undefined,
285
285
  update_comment: false,
286
286
  owner: undefined,