Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

152 extension ci details #157

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-results-reporter",
"version": "1.1.2",
"version": "1.1.3",
"description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
"main": "src/index.js",
"types": "./src/index.d.ts",
Expand Down
12 changes: 10 additions & 2 deletions src/extensions/ci-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ function get_repository_elements(inputs) {
elements.push({ label: 'Repository', key: ci.repository_name, value: ci.repository_url, type: 'hyperlink' });
}
if (inputs.show_repository_branch && ci && ci.repository_ref) {
elements.push({ key: 'Branch', value: ci.repository_ref.replace('refs/heads/', '') });
if (ci.repository_ref.includes('refs/pull')) {
const pr_url = ci.repository_url + ci.repository_ref.replace('refs/pull/', 'pull/');
const pr_name = ci.repository_ref.replace('refs/pull/', '').replace('/merge', '');
elements.push({ label: 'Pull Request', key: pr_name, value: pr_url, type: 'hyperlink' });
} else {
const branch_url = ci.repository_url + ci.repository_ref.replace('refs/heads/', 'tree/');
const branch_name = ci.repository_ref.replace('refs/heads/', '');
elements.push({ label: 'Branch', key: branch_name, value: branch_url, type: 'hyperlink' });
}
}
return elements;
}
Expand All @@ -57,7 +65,7 @@ function get_build_elements(inputs) {
const ci = getCIInformation();
if (inputs.show_build && ci && ci.build_url) {
const name = (ci.build_name || 'Build') + (ci.build_number ? ` #${ci.build_number}` : '');
elements.push({ key: name, value: ci.build_url, type: 'hyperlink' });
elements.push({ label: 'Build', key: name, value: ci.build_url, type: 'hyperlink' });
}
if (inputs.data) {
elements = elements.concat(inputs.data);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getGitHubActionsInformation() {
repository_name: ENV.GITHUB_REPOSITORY,
repository_ref: ENV.GITHUB_REF,
repository_commit_sha: ENV.GITHUB_SHA,
build_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/commit/' + ENV.GITHUB_SHA + '/checks/' + ENV.GITHUB_RUN_ID,
build_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID,
build_number: ENV.GITHUB_RUN_NUMBER,
build_name: ENV.GITHUB_WORKFLOW,
user: ENV.GITHUB_ACTOR,
Expand Down
49 changes: 48 additions & 1 deletion test/ext-ci-info.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('extensions - ci-info', () => {
process.env.SYSTEM_TEAMPROJECT = 'test';
process.env.BUILD_REPOSITORY_URI = 'https://github.com/test/test';
process.env.BUILD_REPOSITORY_NAME = 'test/test';
process.env.BUILD_SOURCEBRANCH = '/refs/heads/feature-test';
process.env.BUILD_SOURCEBRANCH = '/refs/pull/123/merge';
process.env.BUILD_SOURCEVERSION = 'sha';
process.env.BUILD_BUILDID = 'id-123';
process.env.BUILD_BUILDNUMBER = 'number-123';
Expand Down Expand Up @@ -131,6 +131,53 @@ describe('extensions - ci-info', () => {
assert.equal(mock.getInteraction(id).exercised, true);
});

it('should send test-summary with azure devops ci information to chat and extra data', async () => {
process.env.GITHUB_ACTIONS = 'GITHUB_ACTIONS';
process.env.GITHUB_SERVER_URL = 'https://github.com';
process.env.GITHUB_REPOSITORY = 'org/repo';
process.env.GITHUB_REF = '/refs/heads/feature-test';
process.env.GITHUB_SHA = 'sha';
process.env.GITHUB_RUN_ID = 'id-123';
process.env.GITHUB_RUN_NUMBER = 'number-123';
process.env.GITHUB_WORKFLOW = 'Build';
const id = mock.addInteraction('post test-summary with ci-info to chat');
await publish({
config: {
targets: [
{
name: 'chat',
inputs: {
url: 'http://localhost:9393/message'
},
extensions: [
{
name: 'ci-info',
inputs: {
data: [
{
"key": "Download Logs",
"value": "{LOGS_URL}",
"type": "hyperlink"
}
]
}
}
]
}
],
results: [
{
type: 'testng',
files: [
'test/data/testng/single-suite.xml'
]
}
]
}
});
assert.equal(mock.getInteraction(id).exercised, true);
});

afterEach(() => {
mock.clearInteractions();
});
Expand Down
32 changes: 32 additions & 0 deletions test/mocks/chat.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,36 @@ addInteractionHandler('post test-summary with metadata to chat', () => {
status: 200
}
}
});

addInteractionHandler('post test-summary with ci-info to chat', () => {
return {
request: {
method: 'POST',
path: '/message',
body: {
"cards": [
{
"sections": [
{
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE"
},
{
"widgets": [
{
"textParagraph": {
"text": "<b>Repository:</b> <a href=\"https://github.com/org/repo\">org/repo</a> | <b>Branch:</b> <a href=\"https://github.com/org/repo/tree/feature-test\">/feature-test</a><br><b>Build:</b> <a href=\"https://github.com/org/repo/actions/runs/id-123\">Build #number-123</a> | <a href=\"LOGS_URL\">Download Logs</a>"
}
}
]
}
]
}
]
}
},
response: {
status: 200
}
}
});
2 changes: 1 addition & 1 deletion test/mocks/slack.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ addInteractionHandler('post test-summary with ci-info to slack', () => {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Repository:* <https://github.com/test/test|test/test> | *Branch:* /feature-test\n<https://dev.azure.com/test/_build/results?buildId=id-123|Build #number-123>"
"text": "*Repository:* <https://github.com/test/test|test/test> | *Pull Request:* <https://github.com/test/test/pull/123/merge|/123>\n*Build:* <https://dev.azure.com/test/_build/results?buildId=id-123|Build #number-123>"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/teams.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ addInteractionHandler('post test-summary with ci-info to teams', () => {
},
{
"type": "TextBlock",
"text": "**Repository:** [test/test](https://github.com/test/test) | **Branch:** /feature-test\n\n[Build #number-123](https://github.com/test/test/commit/sha/checks/id-123)",
"text": "**Repository:** [test/test](https://github.com/test/test) | **Branch:** [/feature-test](https://github.com/test/test/tree/feature-test)\n\n**Build:** [Build #number-123](https://github.com/test/test/actions/runs/id-123)",
"wrap": true,
"separator": true
}
Expand Down
Loading