Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@decathlon/newman-reporter-pullrequest-decorator

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@decathlon/newman-reporter-pullrequest-decorator - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

### 0.0.22 (2023-10-25)
### Features
* newman results as pull request comment ([#13](https://github.com/Decathlon/newman-reporter-pullrequest-decorator/issues/13)) ([e3c5d38](https://github.com/Decathlon/newman-reporter-pullrequest-decorator/commit/e3c5d385c600534452e7d632c906f249a9088f63))
### 0.0.21 (2023-03-30)

@@ -7,0 +14,0 @@

2

index.js
const PullRequestDecoratorReporter = require('./lib/pullrequest-decorator-reporter');
module.exports = PullRequestDecoratorReporter;
module.exports = PullRequestDecoratorReporter;
const { Octokit } = require('@octokit/rest');
const { buildMarkdownText } = require('./utils');
const { buildMarkdownText, buildPullRequestComment } = require('./utils');
const hasCollectionSucceed = (assertions) => assertions.failed_count === 0;
const getAssociatedPullRequestNumberFromSha = (octokit, repository, commitSha) => octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls', {
owner: repository.split('/')[0],
repo: repository.split('/')[1],
commit_sha: commitSha,
});
/**

@@ -32,2 +38,18 @@ * Service responsible of calling Github and create the check containing postman collection results.

createPullRequestComment(report) {
return getAssociatedPullRequestNumberFromSha(this.getOctokitInstance(),
this.options.repo, this.options.refCommit)
.then((response) => {
if (response.data.length) {
return this.getOctokitInstance().request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', {
owner: this.options.repo.split('/')[0],
repo: this.options.repo.split('/')[1],
issue_number: response.data[0].number,
body: buildPullRequestComment(report),
});
}
return Promise.reject(new Error(`No pull request found for commit id : ${this.options.refCommit}`));
});
}
getOctokitInstance() {

@@ -34,0 +56,0 @@ return new Octokit({ auth: this.options.token });

@@ -33,2 +33,3 @@ /* eslint-disable no-console */

debug: reporterOptions.debug,
enablePullRequestComment: reporterOptions.pullrequestDecoratorEnablecomment,
};

@@ -69,2 +70,15 @@ };

decoratePullRequest(report, options) {
if (this.options.enablePullRequestComment) {
this.githubService.createPullRequestComment(report)
.then(() => console.log('[+] Creating Pull Request Comment'))
.catch((exception) => console.error(`[+] An error occured while creating a comment : ${exception}`))
.finally(() => console.log(`[+] Finished creating comment for collection: ${options.collectionName}`));
}
return this.githubService.createPullRequestCheck(report, options)
.catch((exception) => console.error(`[+] An error occured while creating checks : ${exception}`))
.finally(() => console.log(`[+] Finished collection: ${options.collectionName}`));
}
start() {

@@ -135,10 +149,4 @@ console.log(`[+] Starting collection: ${this.options.collectionName} with following context : ${JSON.stringify(this.options)} `);

if (!this.options.export) {
return this.githubService.createPullRequestCheck(
this.buildReport(this.context.assertions, summary.collection.items),
this.options,
)
.catch((exception) => { console.error(`[+] An error occured : ${exception}`); })
.finally(() => {
console.log(`[+] Finished collection: ${this.options.collectionName}`);
});
return this.decoratePullRequest(this.buildReport(this.context.assertions,
summary.collection.items), this.options);
}

@@ -145,0 +153,0 @@ return Promise.resolve();

@@ -66,4 +66,25 @@ const HEADER_STARTING_NUMBER = 2;

const buildPullRequestComment = (report) => {
const { assertions, items } = report;
let comment = `**Summary**:
❌ ${assertions.failed_count} **Tests Failed**
⏩ ${assertions.skipped_count} **Tests Skipped**
✅ ${items.length - (report.items.filter((item) => item.test_status === 'FAIL').length) - assertions.skipped_count} / ${items.length} **Reqests Passed**`;
report.items
.filter((item) => item.test_status === 'FAIL')
.forEach((item, index) => {
if (index === 0) {
comment += ' \n **The following tests are failing** \n';
}
comment += (`\n [+] ${item.request_name}\n`);
item.failed.forEach((test) => {
comment += ` - ${test} \n`;
});
});
return comment;
};
module.exports = {
buildMarkdownText,
buildPullRequestComment,
};
{
"name": "@decathlon/newman-reporter-pullrequest-decorator",
"license": "Apache-2.0",
"version": "0.0.21",
"version": "0.0.22",
"description": "Newman reporter allowing to decorate Github's PullRequest with postman collection results",

@@ -6,0 +6,0 @@ "main": "index.js",

@@ -82,2 +82,3 @@ # newman-reporter-pullrequest-decorator

`--showOnlyFails` | (Optional : Default `false`) Show only failing assertions.
`--reporter-pullrequest-decorator-enablecomment` | (Optional) Boolean. Allows you to get a comment in your pull request containing the summary of the test result.

@@ -84,0 +85,0 @@ ---

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc