testbeats 2.0.5 → 2.0.7
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 +1 -1
- package/src/beats/beats.types.d.ts +1 -0
- package/src/extensions/base.extension.js +18 -1
- package/src/extensions/ci-info.extension.js +81 -0
- package/src/extensions/custom.extension.js +47 -0
- package/src/extensions/extensions.d.ts +12 -0
- package/src/extensions/index.js +4 -4
- package/src/extensions/smart-analysis.extension.js +8 -5
- package/src/helpers/ci.js +25 -0
- package/src/helpers/metadata.helper.js +15 -1
- package/src/targets/chat.js +1 -1
- package/src/targets/slack.js +7 -6
- package/src/targets/teams.js +1 -1
- package/src/extensions/ci-info.js +0 -134
- package/src/extensions/custom.js +0 -29
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@ class BaseExtension {
|
|
|
50
50
|
|
|
51
51
|
attach() {
|
|
52
52
|
if (!this.text) {
|
|
53
|
-
logger.
|
|
53
|
+
logger.debug(`⚠️ Extension '${this.extension.name}' has no text. Skipping.`);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -69,6 +69,23 @@ class BaseExtension {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* @param {string[]} texts
|
|
74
|
+
*/
|
|
75
|
+
mergeTexts(texts) {
|
|
76
|
+
const _texts = texts.filter(text => !!text);
|
|
77
|
+
switch (this.target.name) {
|
|
78
|
+
case 'teams':
|
|
79
|
+
return _texts.join('\n\n');
|
|
80
|
+
case 'slack':
|
|
81
|
+
return _texts.join('\n');
|
|
82
|
+
case 'chat':
|
|
83
|
+
return _texts.join('<br>');
|
|
84
|
+
default:
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
72
89
|
}
|
|
73
90
|
|
|
74
91
|
module.exports = { BaseExtension }
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const { BaseExtension } = require("./base.extension");
|
|
2
|
+
const { getCIInformation } = require('../helpers/ci');
|
|
3
|
+
const { getMetaDataText } = require("../helpers/metadata.helper");
|
|
4
|
+
const { STATUS, HOOK } = require("../helpers/constants");
|
|
5
|
+
|
|
6
|
+
class CIInfoExtension extends BaseExtension {
|
|
7
|
+
|
|
8
|
+
constructor(target, extension, result, payload, root_payload) {
|
|
9
|
+
super(target, extension, result, payload, root_payload);
|
|
10
|
+
this.#setDefaultOptions();
|
|
11
|
+
this.#setDefaultInputs();
|
|
12
|
+
this.updateExtensionInputs();
|
|
13
|
+
|
|
14
|
+
this.ci = null;
|
|
15
|
+
this.repository_elements = [];
|
|
16
|
+
this.build_elements = [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#setDefaultOptions() {
|
|
20
|
+
this.default_options.hook = HOOK.AFTER_SUMMARY,
|
|
21
|
+
this.default_options.condition = STATUS.PASS_OR_FAIL;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#setDefaultInputs() {
|
|
25
|
+
this.default_inputs.title = '';
|
|
26
|
+
this.default_inputs.title_link = '';
|
|
27
|
+
this.default_inputs.show_repository = true;
|
|
28
|
+
this.default_inputs.show_repository_branch = true;
|
|
29
|
+
this.default_inputs.show_build = true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async run() {
|
|
33
|
+
this.ci = getCIInformation();
|
|
34
|
+
|
|
35
|
+
this.setRepositoryElements();
|
|
36
|
+
this.setBuildElements();
|
|
37
|
+
|
|
38
|
+
const repository_text = await getMetaDataText({ elements: this.repository_elements, target: this.target, extension: this.extension, result: this.result, default_condition: this.default_options.condition });
|
|
39
|
+
const build_text = await getMetaDataText({ elements: this.build_elements, target: this.target, extension: this.extension, result: this.result, default_condition: this.default_options.condition });
|
|
40
|
+
this.text = this.mergeTexts([repository_text, build_text]);
|
|
41
|
+
this.attach();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setRepositoryElements() {
|
|
45
|
+
if (!this.ci) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.extension.inputs.show_repository && this.ci.repository_url && this.ci.repository_name) {
|
|
50
|
+
this.repository_elements.push({ label: 'Repository', key: this.ci.repository_name, value: this.ci.repository_url, type: 'hyperlink' });
|
|
51
|
+
}
|
|
52
|
+
if (this.extension.inputs.show_repository_branch && this.ci.repository_ref) {
|
|
53
|
+
if (this.ci.repository_ref.includes('refs/pull')) {
|
|
54
|
+
const pr_url = this.ci.repository_url + this.ci.repository_ref.replace('refs/pull/', '/pull/');
|
|
55
|
+
const pr_name = this.ci.repository_ref.replace('refs/pull/', '').replace('/merge', '');
|
|
56
|
+
this.repository_elements.push({ label: 'Pull Request', key: pr_name, value: pr_url, type: 'hyperlink' });
|
|
57
|
+
} else {
|
|
58
|
+
const branch_url = this.ci.repository_url + this.ci.repository_ref.replace('refs/heads/', '/tree/');
|
|
59
|
+
const branch_name = this.ci.repository_ref.replace('refs/heads/', '');
|
|
60
|
+
this.repository_elements.push({ label: 'Branch', key: branch_name, value: branch_url, type: 'hyperlink' });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setBuildElements() {
|
|
66
|
+
if (!this.ci) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (this.extension.inputs.show_build && this.ci.build_url) {
|
|
71
|
+
const name = (this.ci.build_name || 'Build') + (this.ci.build_number ? ` #${this.ci.build_number}` : '');
|
|
72
|
+
this.build_elements.push({ label: 'Build', key: name, value: this.ci.build_url, type: 'hyperlink' });
|
|
73
|
+
}
|
|
74
|
+
if (this.extension.inputs.data) {
|
|
75
|
+
this.build_elements = this.build_elements.concat(this.extension.inputs.data);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { CIInfoExtension };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { BaseExtension } = require("./base.extension");
|
|
3
|
+
const { STATUS, HOOK } = require("../helpers/constants");
|
|
4
|
+
|
|
5
|
+
class CustomExtension extends BaseExtension {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('..').CustomExtension} extension
|
|
9
|
+
*/
|
|
10
|
+
constructor(target, extension, result, payload, root_payload) {
|
|
11
|
+
super(target, extension, result, payload, root_payload);
|
|
12
|
+
this.extension = extension;
|
|
13
|
+
this.#setDefaultOptions();
|
|
14
|
+
this.updateExtensionInputs();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#setDefaultOptions() {
|
|
18
|
+
this.default_options.hook = HOOK.END,
|
|
19
|
+
this.default_options.condition = STATUS.PASS_OR_FAIL;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async run() {
|
|
23
|
+
const params = this.#getParams();
|
|
24
|
+
if (typeof this.extension.inputs.load === 'string') {
|
|
25
|
+
const cwd = process.cwd();
|
|
26
|
+
const extension_runner = require(path.join(cwd, this.extension.inputs.load));
|
|
27
|
+
await extension_runner.run(params);
|
|
28
|
+
} else if (typeof this.extension.inputs.load === 'function') {
|
|
29
|
+
await this.extension.inputs.load(params);
|
|
30
|
+
} else {
|
|
31
|
+
throw `Invalid 'load' input in custom extension - ${this.extension.inputs.load}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#getParams() {
|
|
36
|
+
return {
|
|
37
|
+
target: this.target,
|
|
38
|
+
extension: this.extension,
|
|
39
|
+
payload: this.payload,
|
|
40
|
+
root_payload: this.root_payload,
|
|
41
|
+
result: this.result
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = { CustomExtension }
|
package/src/extensions/index.js
CHANGED
|
@@ -4,11 +4,11 @@ const rp_analysis = require('./report-portal-analysis');
|
|
|
4
4
|
const rp_history = require('./report-portal-history');
|
|
5
5
|
const qc_test_summary = require('./quick-chart-test-summary');
|
|
6
6
|
const percy_analysis = require('./percy-analysis');
|
|
7
|
-
const custom = require('./custom');
|
|
8
7
|
const metadata = require('./metadata');
|
|
9
|
-
const ci_info = require('./ci-info');
|
|
10
8
|
const { AIFailureSummaryExtension } = require('./ai-failure-summary.extension');
|
|
11
9
|
const { SmartAnalysisExtension } = require('./smart-analysis.extension');
|
|
10
|
+
const { CIInfoExtension } = require('./ci-info.extension');
|
|
11
|
+
const { CustomExtension } = require('./custom.extension');
|
|
12
12
|
const { EXTENSION } = require('../helpers/constants');
|
|
13
13
|
const { checkCondition } = require('../helpers/helper');
|
|
14
14
|
const logger = require('../utils/logger');
|
|
@@ -51,11 +51,11 @@ function getExtensionRunner(extension, options) {
|
|
|
51
51
|
case EXTENSION.PERCY_ANALYSIS:
|
|
52
52
|
return percy_analysis;
|
|
53
53
|
case EXTENSION.CUSTOM:
|
|
54
|
-
return
|
|
54
|
+
return new CustomExtension(options.target, extension, options.result, options.payload, options.root_payload);
|
|
55
55
|
case EXTENSION.METADATA:
|
|
56
56
|
return metadata;
|
|
57
57
|
case EXTENSION.CI_INFO:
|
|
58
|
-
return
|
|
58
|
+
return new CIInfoExtension(options.target, extension, options.result, options.payload, options.root_payload);
|
|
59
59
|
case EXTENSION.AI_FAILURE_SUMMARY:
|
|
60
60
|
return new AIFailureSummaryExtension(options.target, extension, options.result, options.payload, options.root_payload);
|
|
61
61
|
case EXTENSION.SMART_ANALYSIS:
|
|
@@ -38,17 +38,20 @@ class SmartAnalysisExtension extends BaseExtension {
|
|
|
38
38
|
const execution_metrics = data.execution_metrics[0];
|
|
39
39
|
|
|
40
40
|
const smart_analysis = [];
|
|
41
|
+
if (execution_metrics.newly_failed) {
|
|
42
|
+
smart_analysis.push(`⭕ Newly Failed: ${execution_metrics.newly_failed}`);
|
|
43
|
+
}
|
|
41
44
|
if (execution_metrics.always_failing) {
|
|
42
|
-
smart_analysis.push(
|
|
45
|
+
smart_analysis.push(`🔴 Always Failing: ${execution_metrics.always_failing}`);
|
|
43
46
|
}
|
|
44
|
-
if (execution_metrics.
|
|
45
|
-
smart_analysis.push(
|
|
47
|
+
if (execution_metrics.recurring_errors) {
|
|
48
|
+
smart_analysis.push(`🟠 Recurring Errors: ${execution_metrics.recurring_errors}`);
|
|
46
49
|
}
|
|
47
50
|
if (execution_metrics.flaky) {
|
|
48
|
-
smart_analysis.push(
|
|
51
|
+
smart_analysis.push(`🟡 Flaky: ${execution_metrics.flaky}`);
|
|
49
52
|
}
|
|
50
53
|
if (execution_metrics.recovered) {
|
|
51
|
-
smart_analysis.push(`🟢
|
|
54
|
+
smart_analysis.push(`🟢 Recovered: ${execution_metrics.recovered}`);
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
this.text = smart_analysis.join(' | ');
|
package/src/helpers/ci.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
const ENV = process.env;
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @returns {import('../extensions/extensions').ICIInfo}
|
|
5
|
+
*/
|
|
3
6
|
function getCIInformation() {
|
|
4
7
|
if (ENV.GITHUB_ACTIONS) {
|
|
5
8
|
return getGitHubActionsInformation();
|
|
6
9
|
}
|
|
10
|
+
if (ENV.GITLAB_CI) {
|
|
11
|
+
return getGitLabInformation();
|
|
12
|
+
}
|
|
7
13
|
if (ENV.JENKINS_URL) {
|
|
8
14
|
return getJenkinsInformation();
|
|
9
15
|
}
|
|
@@ -23,6 +29,7 @@ function getGitHubActionsInformation() {
|
|
|
23
29
|
build_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID,
|
|
24
30
|
build_number: ENV.GITHUB_RUN_NUMBER,
|
|
25
31
|
build_name: ENV.GITHUB_WORKFLOW,
|
|
32
|
+
build_reason: ENV.GITHUB_EVENT_NAME,
|
|
26
33
|
user: ENV.GITHUB_ACTOR,
|
|
27
34
|
}
|
|
28
35
|
}
|
|
@@ -38,6 +45,7 @@ function getAzureDevOpsInformation() {
|
|
|
38
45
|
build_url: ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + ENV.SYSTEM_TEAMPROJECT + '/_build/results?buildId=' + ENV.BUILD_BUILDID,
|
|
39
46
|
build_number: ENV.BUILD_BUILDNUMBER,
|
|
40
47
|
build_name: ENV.BUILD_DEFINITIONNAME,
|
|
48
|
+
build_reason: ENV.BUILD_REASON,
|
|
41
49
|
user: ENV.BUILD_REQUESTEDFOR
|
|
42
50
|
}
|
|
43
51
|
}
|
|
@@ -53,10 +61,27 @@ function getJenkinsInformation() {
|
|
|
53
61
|
build_url: ENV.BUILD_URL,
|
|
54
62
|
build_number: ENV.BUILD_NUMBER,
|
|
55
63
|
build_name: ENV.JOB_NAME,
|
|
64
|
+
build_reason: ENV.BUILD_CAUSE,
|
|
56
65
|
user: ENV.USER || ENV.USERNAME
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
|
|
69
|
+
function getGitLabInformation() {
|
|
70
|
+
return {
|
|
71
|
+
ci: 'GITLAB',
|
|
72
|
+
git: 'GITLAB',
|
|
73
|
+
repository_url: ENV.CI_PROJECT_URL,
|
|
74
|
+
repository_name: ENV.CI_PROJECT_NAME,
|
|
75
|
+
repository_ref: ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || ENV.CI_COMMIT_REF_NAME,
|
|
76
|
+
repository_commit_sha:ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || ENV.CI_COMMIT_SHA,
|
|
77
|
+
build_url: ENV.CI_JOB_URL,
|
|
78
|
+
build_number: ENV.CI_JOB_ID,
|
|
79
|
+
build_name: ENV.CI_JOB_NAME,
|
|
80
|
+
build_reason: ENV.CI_PIPELINE_SOURCE,
|
|
81
|
+
user: ENV.GITLAB_USER_LOGIN || ENV.CI_COMMIT_AUTHOR
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
60
85
|
module.exports = {
|
|
61
86
|
getCIInformation
|
|
62
87
|
}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
const { checkCondition } = require('./helper')
|
|
1
|
+
const { checkCondition } = require('./helper');
|
|
2
|
+
|
|
3
|
+
function getMetaDataText(params) {
|
|
4
|
+
switch (params.target.name) {
|
|
5
|
+
case 'teams':
|
|
6
|
+
return getTeamsMetaDataText(params);
|
|
7
|
+
case 'slack':
|
|
8
|
+
return getSlackMetaDataText(params);
|
|
9
|
+
case 'chat':
|
|
10
|
+
return getChatMetaDataText(params);
|
|
11
|
+
default:
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
/**
|
|
4
17
|
* Asynchronously generates metadata text for slack.
|
|
@@ -109,6 +122,7 @@ function get_url({ url, target, extension, result}) {
|
|
|
109
122
|
}
|
|
110
123
|
|
|
111
124
|
module.exports = {
|
|
125
|
+
getMetaDataText,
|
|
112
126
|
getSlackMetaDataText,
|
|
113
127
|
getTeamsMetaDataText,
|
|
114
128
|
getChatMetaDataText
|
package/src/targets/chat.js
CHANGED
|
@@ -111,7 +111,7 @@ function getFailureDetails(suite) {
|
|
|
111
111
|
for (let i = 0; i < cases.length; i++) {
|
|
112
112
|
const test_case = cases[i];
|
|
113
113
|
if (test_case.status === 'FAIL') {
|
|
114
|
-
text += `<b>Test</b>: ${test_case.name}<br><b>Error</b>: ${truncate(test_case.failure, 150)}<br><br>`;
|
|
114
|
+
text += `<b>Test</b>: ${test_case.name}<br><b>Error</b>: ${truncate(test_case.failure ?? 'N/A', 150)}<br><br>`;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
return text;
|
package/src/targets/slack.js
CHANGED
|
@@ -22,7 +22,7 @@ async function run({ result, target }) {
|
|
|
22
22
|
} else {
|
|
23
23
|
await setFunctionalPayload({ result, target, payload });
|
|
24
24
|
}
|
|
25
|
-
const message = getRootPayload({ result, payload });
|
|
25
|
+
const message = getRootPayload({ result, target, payload });
|
|
26
26
|
return request.post({
|
|
27
27
|
url: target.inputs.url,
|
|
28
28
|
body: message
|
|
@@ -66,12 +66,12 @@ function setMainBlock({ result, target, payload }) {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function getTitleText(result, target) {
|
|
69
|
+
function getTitleText(result, target, {allowTitleLink = true} = {}) {
|
|
70
70
|
let text = target.inputs.title ? target.inputs.title : result.name;
|
|
71
71
|
if (target.inputs.title_suffix) {
|
|
72
72
|
text = `${text} ${target.inputs.title_suffix}`;
|
|
73
73
|
}
|
|
74
|
-
if (target.inputs.title_link) {
|
|
74
|
+
if (allowTitleLink && target.inputs.title_link) {
|
|
75
75
|
text = `<${target.inputs.title_link}|${text}>`;
|
|
76
76
|
}
|
|
77
77
|
return text;
|
|
@@ -129,7 +129,7 @@ function getFailureDetails(suite) {
|
|
|
129
129
|
for (let i = 0; i < cases.length; i++) {
|
|
130
130
|
const test_case = cases[i];
|
|
131
131
|
if (test_case.status === 'FAIL') {
|
|
132
|
-
text += `*Test*: ${test_case.name}\n*Error*: ${truncate(test_case.failure, 150)}\n\n`;
|
|
132
|
+
text += `*Test*: ${test_case.name}\n*Error*: ${truncate(test_case.failure ?? 'N/A', 150)}\n\n`;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
return {
|
|
@@ -147,7 +147,7 @@ function getFailureDetails(suite) {
|
|
|
147
147
|
* @param {PerformanceTestResult | TestResult} param0.result
|
|
148
148
|
* @returns
|
|
149
149
|
*/
|
|
150
|
-
function getRootPayload({ result, payload }) {
|
|
150
|
+
function getRootPayload({ result, target, payload }) {
|
|
151
151
|
let color = COLORS.GOOD;
|
|
152
152
|
if (result.status !== 'PASS') {
|
|
153
153
|
let somePassed = true;
|
|
@@ -166,7 +166,8 @@ function getRootPayload({ result, payload }) {
|
|
|
166
166
|
"attachments": [
|
|
167
167
|
{
|
|
168
168
|
"color": color,
|
|
169
|
-
"blocks": payload.blocks
|
|
169
|
+
"blocks": payload.blocks,
|
|
170
|
+
"fallback": `${getTitleText(result, target, {allowTitleLink: false})}\nResults: ${getResultText(result)}`,
|
|
170
171
|
}
|
|
171
172
|
]
|
|
172
173
|
};
|
package/src/targets/teams.js
CHANGED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
const { STATUS, HOOK } = require("../helpers/constants");
|
|
2
|
-
const { getCIInformation } = require('../helpers/ci');
|
|
3
|
-
const { addTeamsExtension, addSlackExtension, addChatExtension } = require('../helpers/extension.helper');
|
|
4
|
-
const { getTeamsMetaDataText, getSlackMetaDataText, getChatMetaDataText } = require('../helpers/metadata.helper');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {object} param0 - the payload object
|
|
9
|
-
* @param {import('..').Extension} param0.extension - The result object
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
async function run({ target, extension, payload, result }) {
|
|
13
|
-
extension.inputs = Object.assign({}, default_inputs, extension.inputs);
|
|
14
|
-
if (target.name === 'teams') {
|
|
15
|
-
extension.inputs = Object.assign({}, default_inputs_teams, extension.inputs);
|
|
16
|
-
const text = await get_text({ target, extension, result });
|
|
17
|
-
if (text) {
|
|
18
|
-
addTeamsExtension({ payload, extension, text });
|
|
19
|
-
}
|
|
20
|
-
} else if (target.name === 'slack') {
|
|
21
|
-
extension.inputs = Object.assign({}, default_inputs_slack, extension.inputs);
|
|
22
|
-
const text = await get_text({ target, extension, result });
|
|
23
|
-
if (text) {
|
|
24
|
-
addSlackExtension({ payload, extension, text });
|
|
25
|
-
}
|
|
26
|
-
} else if (target.name === 'chat') {
|
|
27
|
-
extension.inputs = Object.assign({}, default_inputs_chat, extension.inputs);
|
|
28
|
-
const text = await get_text({ target, extension, result });
|
|
29
|
-
if (text) {
|
|
30
|
-
addChatExtension({ payload, extension, text });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @param {import('..').CIInfoInputs} inputs
|
|
38
|
-
*/
|
|
39
|
-
function get_repository_elements(inputs) {
|
|
40
|
-
const elements = [];
|
|
41
|
-
const ci = getCIInformation();
|
|
42
|
-
if (inputs.show_repository && ci && ci.repository_url && ci.repository_name) {
|
|
43
|
-
elements.push({ label: 'Repository', key: ci.repository_name, value: ci.repository_url, type: 'hyperlink' });
|
|
44
|
-
}
|
|
45
|
-
if (inputs.show_repository_branch && ci && ci.repository_ref) {
|
|
46
|
-
if (ci.repository_ref.includes('refs/pull')) {
|
|
47
|
-
const pr_url = ci.repository_url + ci.repository_ref.replace('refs/pull/', '/pull/');
|
|
48
|
-
const pr_name = ci.repository_ref.replace('refs/pull/', '').replace('/merge', '');
|
|
49
|
-
elements.push({ label: 'Pull Request', key: pr_name, value: pr_url, type: 'hyperlink' });
|
|
50
|
-
} else {
|
|
51
|
-
const branch_url = ci.repository_url + ci.repository_ref.replace('refs/heads/', '/tree/');
|
|
52
|
-
const branch_name = ci.repository_ref.replace('refs/heads/', '');
|
|
53
|
-
elements.push({ label: 'Branch', key: branch_name, value: branch_url, type: 'hyperlink' });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return elements;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
* @param {import('..').CIInfoInputs} inputs
|
|
62
|
-
*/
|
|
63
|
-
function get_build_elements(inputs) {
|
|
64
|
-
let elements = [];
|
|
65
|
-
const ci = getCIInformation();
|
|
66
|
-
if (inputs.show_build && ci && ci.build_url) {
|
|
67
|
-
const name = (ci.build_name || 'Build') + (ci.build_number ? ` #${ci.build_number}` : '');
|
|
68
|
-
elements.push({ label: 'Build', key: name, value: ci.build_url, type: 'hyperlink' });
|
|
69
|
-
}
|
|
70
|
-
if (inputs.data) {
|
|
71
|
-
elements = elements.concat(inputs.data);
|
|
72
|
-
}
|
|
73
|
-
return elements;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function get_text({ target, extension, result }) {
|
|
77
|
-
const repository_elements = get_repository_elements(extension.inputs);
|
|
78
|
-
const build_elements = get_build_elements(extension.inputs);
|
|
79
|
-
if (target.name === 'teams') {
|
|
80
|
-
const repository_text = await getTeamsMetaDataText({ elements: repository_elements, target, extension, result, default_condition: default_options.condition });
|
|
81
|
-
const build_text = await getTeamsMetaDataText({ elements: build_elements, target, extension, result, default_condition: default_options.condition });
|
|
82
|
-
if (build_text) {
|
|
83
|
-
return `${repository_text ? `${repository_text}\n\n` : '' }${build_text}`;
|
|
84
|
-
} else {
|
|
85
|
-
return repository_text;
|
|
86
|
-
}
|
|
87
|
-
} else if (target.name === 'slack') {
|
|
88
|
-
const repository_text = await getSlackMetaDataText({ elements: repository_elements, target, extension, result, default_condition: default_options.condition });
|
|
89
|
-
const build_text = await getSlackMetaDataText({ elements: build_elements, target, extension, result, default_condition: default_options.condition });
|
|
90
|
-
if (build_text) {
|
|
91
|
-
return `${repository_text ? `${repository_text}\n` : '' }${build_text}`;
|
|
92
|
-
} else {
|
|
93
|
-
return repository_text;
|
|
94
|
-
}
|
|
95
|
-
} else if (target.name === 'chat') {
|
|
96
|
-
const repository_text = await getChatMetaDataText({ elements: repository_elements, target, extension, result, default_condition: default_options.condition });
|
|
97
|
-
const build_text = await getChatMetaDataText({ elements: build_elements, target, extension, result, default_condition: default_options.condition });
|
|
98
|
-
if (build_text) {
|
|
99
|
-
return `${repository_text ? `${repository_text}<br>` : '' }${build_text}`;
|
|
100
|
-
} else {
|
|
101
|
-
return repository_text;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const default_options = {
|
|
107
|
-
hook: HOOK.AFTER_SUMMARY,
|
|
108
|
-
condition: STATUS.PASS_OR_FAIL,
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const default_inputs = {
|
|
112
|
-
title: '',
|
|
113
|
-
show_repository: true,
|
|
114
|
-
show_repository_branch: true,
|
|
115
|
-
show_build: true,
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const default_inputs_teams = {
|
|
119
|
-
|
|
120
|
-
separator: true
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const default_inputs_slack = {
|
|
124
|
-
separator: false
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const default_inputs_chat = {
|
|
128
|
-
separator: true
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
module.exports = {
|
|
132
|
-
run,
|
|
133
|
-
default_options
|
|
134
|
-
}
|
package/src/extensions/custom.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const { HOOK, STATUS } = require('../helpers/constants');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {object} param0
|
|
7
|
-
* @param {import('../index').CustomExtension} param0.extension
|
|
8
|
-
*/
|
|
9
|
-
async function run({ target, extension, payload, root_payload, result }) {
|
|
10
|
-
if (typeof extension.inputs.load === 'string') {
|
|
11
|
-
const cwd = process.cwd();
|
|
12
|
-
const extension_runner = require(path.join(cwd, extension.inputs.load));
|
|
13
|
-
await extension_runner.run({ target, extension, payload, root_payload, result });
|
|
14
|
-
} else if (typeof extension.inputs.load === 'function') {
|
|
15
|
-
await extension.inputs.load({ target, extension, payload, root_payload, result });
|
|
16
|
-
} else {
|
|
17
|
-
throw `Invalid 'load' input in custom extension - ${extension.inputs.load}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const default_options = {
|
|
22
|
-
hook: HOOK.END,
|
|
23
|
-
condition: STATUS.PASS_OR_FAIL
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
run,
|
|
28
|
-
default_options
|
|
29
|
-
}
|