@smartbear/one-report-publisher
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -56,3 +56,3 @@ "use strict"; | ||
var projectId = core_1.default.getInput('project-id') || process.env.ONE_REPORT_PROJECT_ID; | ||
var token = core_1.default.getInput('token') || process.env.ONE_REPORT_TOKEN; | ||
var refreshToken = core_1.default.getInput('refresh-token') || process.env.ONE_REPORT_REFRESH_TOKEN; | ||
var baseUrl = core_1.default.getInput('url') || process.env.ONE_REPORT_URL; | ||
@@ -65,3 +65,3 @@ var globs = core_1.default.getMultilineInput('reports'); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestTimeout, responseBodies; | ||
var requestTimeout, accessToken, responseBodies; | ||
return __generator(this, function (_a) { | ||
@@ -72,9 +72,12 @@ switch (_a.label) { | ||
throw new Error("Please specify 'project-id' or define the ONE_REPORT_PROJECT_ID environment variable"); | ||
if (!token) | ||
throw new Error("Please specify 'token' or define the ONE_REPORT_TOKEN environment variable"); | ||
if (!refreshToken) | ||
throw new Error("Please specify 'refresh-token' or define the ONE_REPORT_REFRESH_TOKEN environment variable"); | ||
if (!baseUrl) | ||
throw new Error("Please specify 'url' or define the ONE_REPORT_URL environment variable"); | ||
requestTimeout = maxTime ? +maxTime * 1000 : undefined; | ||
return [4 /*yield*/, (0, index_js_1.publish)(globs, zip, projectId, baseUrl, process.env, (0, index_js_1.tokenAuthenticator)(token), requestTimeout)]; | ||
return [4 /*yield*/, (0, index_js_1.getAccessToken)(baseUrl, refreshToken)]; | ||
case 1: | ||
accessToken = _a.sent(); | ||
return [4 /*yield*/, (0, index_js_1.publish)(globs, zip, projectId, baseUrl, process.env, (0, index_js_1.tokenAuthenticator)(accessToken), requestTimeout)]; | ||
case 2: | ||
responseBodies = _a.sent(); | ||
@@ -81,0 +84,0 @@ return [2 /*return*/, responseBodies.map(function (body) { return body.testCycleId; })]; |
@@ -45,3 +45,3 @@ #!/usr/bin/env node | ||
program.requiredOption('-p, --project-id <id>', 'OneReport project id. Defaults to $ONE_REPORT_PROJECT_ID', process.env.ONE_REPORT_PROJECT_ID); | ||
program.requiredOption('-t, --token <token>', 'OneReport token. Defaults to $ONE_REPORT_TOKEN', process.env.ONE_REPORT_TOKEN); | ||
program.requiredOption('-t, --refresh-token <refresh-token>', 'OneReport refresh-token. Defaults to $ONE_REPORT_REFRESH_TOKEN', process.env.ONE_REPORT_REFRESH_TOKEN); | ||
program.requiredOption('-r, --reports <glob...>', 'Glob to the files to publish'); | ||
@@ -52,6 +52,6 @@ program.option('-m, --max-time <seconds>', 'Max time for each request'); | ||
program.parse(process.argv); | ||
var _a = program.opts(), projectId = _a.projectId, token = _a.token, globs = _a.reports, maxTime = _a.maxTime, ignoreError = _a.ignoreError, baseUrl = _a.url, noZip = _a.noZip; | ||
var _a = program.opts(), projectId = _a.projectId, refreshToken = _a.refreshToken, globs = _a.reports, maxTime = _a.maxTime, ignoreError = _a.ignoreError, baseUrl = _a.url, noZip = _a.noZip; | ||
function main() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestTimeout, responseBodies; | ||
var requestTimeout, accessToken, responseBodies; | ||
return __generator(this, function (_a) { | ||
@@ -61,4 +61,7 @@ switch (_a.label) { | ||
requestTimeout = maxTime ? +maxTime * 1000 : undefined; | ||
return [4 /*yield*/, (0, index_js_1.publish)(globs, !noZip, projectId, baseUrl, process.env, (0, index_js_1.tokenAuthenticator)(token), requestTimeout)]; | ||
return [4 /*yield*/, (0, index_js_1.getAccessToken)(baseUrl, refreshToken)]; | ||
case 1: | ||
accessToken = _a.sent(); | ||
return [4 /*yield*/, (0, index_js_1.publish)(globs, !noZip, projectId, baseUrl, process.env, (0, index_js_1.tokenAuthenticator)(accessToken), requestTimeout)]; | ||
case 2: | ||
responseBodies = _a.sent(); | ||
@@ -65,0 +68,0 @@ return [2 /*return*/, responseBodies.map(function (body) { return body.testCycleId; })]; |
@@ -0,1 +1,2 @@ | ||
export * from './getAccessToken.js'; | ||
export * from './publish.js'; | ||
@@ -2,0 +3,0 @@ export * from './tokenAuthenticator.js'; |
@@ -17,2 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./getAccessToken.js"), exports); | ||
__exportStar(require("./publish.js"), exports); | ||
@@ -19,0 +20,0 @@ __exportStar(require("./tokenAuthenticator.js"), exports); |
@@ -49,18 +49,2 @@ "use strict"; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -79,2 +63,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var util_1 = require("util"); | ||
var createResponseError_js_1 = require("./createResponseError.js"); | ||
var manyglob_js_1 = require("./manyglob.js"); | ||
@@ -142,7 +127,7 @@ var readStream_js_1 = require("./readStream.js"); | ||
exports.publish = publish; | ||
function publishFile(path, url, ciEnv, authHeaders, requestTimeout) { | ||
function publishFile(requestBodyPath, url, ciEnv, authHeaders, requestTimeout) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
lstat(path) | ||
lstat(requestBodyPath) | ||
.then(function (stat) { | ||
@@ -161,27 +146,17 @@ var _a, _b, _c, _d; | ||
} | ||
var headers = __assign(__assign(__assign(__assign(__assign({ 'Content-Type': contentTypes[(0, path_1.extname)(path)], 'Content-Length': stat.size }, (((_a = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _a === void 0 ? void 0 : _a.remote) ? { 'OneReport-SourceControl': ciEnv.git.remote } : {})), (((_b = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _b === void 0 ? void 0 : _b.revision) ? { 'OneReport-Revision': ciEnv.git.revision } : {})), (((_c = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _c === void 0 ? void 0 : _c.branch) ? { 'OneReport-Branch': ciEnv.git.branch } : {})), (((_d = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _d === void 0 ? void 0 : _d.tag) ? { 'OneReport-Tag': ciEnv.git.tag } : {})), authHeaders); | ||
var reqHeaders = __assign(__assign(__assign(__assign(__assign({ 'Content-Type': contentTypes[(0, path_1.extname)(requestBodyPath)], 'Content-Length': stat.size }, (((_a = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _a === void 0 ? void 0 : _a.remote) ? { 'OneReport-SourceControl': ciEnv.git.remote } : {})), (((_b = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _b === void 0 ? void 0 : _b.revision) ? { 'OneReport-Revision': ciEnv.git.revision } : {})), (((_c = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _c === void 0 ? void 0 : _c.branch) ? { 'OneReport-Branch': ciEnv.git.branch } : {})), (((_d = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _d === void 0 ? void 0 : _d.tag) ? { 'OneReport-Tag': ciEnv.git.tag } : {})), authHeaders); | ||
var req = h.request(url.toString(), { | ||
method: 'POST', | ||
headers: headers, | ||
headers: reqHeaders, | ||
}, function (res) { | ||
(0, readStream_js_1.readStream)(res) | ||
.then(function (buffer) { return buffer.toString('utf-8'); }) | ||
.then(function (body) { | ||
.then(function (responseBody) { | ||
if (res.statusCode !== 201) { | ||
return reject(new Error("Unexpected status code ".concat(res.statusCode, "\nPOST ").concat(url.toString(), " -d @").concat(path, "\n> ").concat(Object.entries(headers) | ||
.map(function (_a) { | ||
var _b = __read(_a, 2), h = _b[0], v = _b[1]; | ||
return "".concat(h, ": ").concat(v); | ||
}) | ||
.join('\n> '), "\n\n< ").concat(Object.entries(res.headers) | ||
.map(function (_a) { | ||
var _b = __read(_a, 2), h = _b[0], v = _b[1]; | ||
return "".concat(h, ": ").concat(v); | ||
}) | ||
.join('\n< '), "\n\n").concat(body, "\n"))); | ||
return reject((0, createResponseError_js_1.createResponseError)(res, url, reqHeaders, responseBody, requestBodyPath)); | ||
} | ||
else { | ||
try { | ||
var responseBody = JSON.parse(body); | ||
return resolve(responseBody); | ||
var jsonResponseBody = JSON.parse(responseBody); | ||
return resolve(jsonResponseBody); | ||
} | ||
@@ -202,3 +177,3 @@ catch (err) { | ||
}); | ||
var file = fs_1.default.createReadStream(path); | ||
var file = fs_1.default.createReadStream(requestBodyPath); | ||
(0, stream_1.pipeline)(file, req, function (err) { | ||
@@ -205,0 +180,0 @@ try { |
@@ -11,5 +11,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import core from '@actions/core'; | ||
import { publish, tokenAuthenticator } from '../../src/index.js'; | ||
import { getAccessToken, publish, tokenAuthenticator, } from '../../src/index.js'; | ||
const projectId = core.getInput('project-id') || process.env.ONE_REPORT_PROJECT_ID; | ||
const token = core.getInput('token') || process.env.ONE_REPORT_TOKEN; | ||
const refreshToken = core.getInput('refresh-token') || process.env.ONE_REPORT_REFRESH_TOKEN; | ||
const baseUrl = core.getInput('url') || process.env.ONE_REPORT_URL; | ||
@@ -24,8 +24,9 @@ const globs = core.getMultilineInput('reports'); | ||
throw new Error("Please specify 'project-id' or define the ONE_REPORT_PROJECT_ID environment variable"); | ||
if (!token) | ||
throw new Error("Please specify 'token' or define the ONE_REPORT_TOKEN environment variable"); | ||
if (!refreshToken) | ||
throw new Error("Please specify 'refresh-token' or define the ONE_REPORT_REFRESH_TOKEN environment variable"); | ||
if (!baseUrl) | ||
throw new Error("Please specify 'url' or define the ONE_REPORT_URL environment variable"); | ||
const requestTimeout = maxTime ? +maxTime * 1000 : undefined; | ||
const responseBodies = yield publish(globs, zip, projectId, baseUrl, process.env, tokenAuthenticator(token), requestTimeout); | ||
const accessToken = yield getAccessToken(baseUrl, refreshToken); | ||
const responseBodies = yield publish(globs, zip, projectId, baseUrl, process.env, tokenAuthenticator(accessToken), requestTimeout); | ||
return responseBodies.map((body) => body.testCycleId); | ||
@@ -32,0 +33,0 @@ }); |
@@ -12,7 +12,7 @@ #!/usr/bin/env node | ||
import { Command } from 'commander'; | ||
import { publish, tokenAuthenticator } from '../../src/index.js'; | ||
import { getAccessToken, publish, tokenAuthenticator, } from '../../src/index.js'; | ||
const program = new Command(); | ||
program.requiredOption('-u, --url <url>', 'OneReport URL. Defaults to $ONE_REPORT_URL', process.env.ONE_REPORT_URL); | ||
program.requiredOption('-p, --project-id <id>', 'OneReport project id. Defaults to $ONE_REPORT_PROJECT_ID', process.env.ONE_REPORT_PROJECT_ID); | ||
program.requiredOption('-t, --token <token>', 'OneReport token. Defaults to $ONE_REPORT_TOKEN', process.env.ONE_REPORT_TOKEN); | ||
program.requiredOption('-t, --refresh-token <refresh-token>', 'OneReport refresh-token. Defaults to $ONE_REPORT_REFRESH_TOKEN', process.env.ONE_REPORT_REFRESH_TOKEN); | ||
program.requiredOption('-r, --reports <glob...>', 'Glob to the files to publish'); | ||
@@ -23,7 +23,8 @@ program.option('-m, --max-time <seconds>', 'Max time for each request'); | ||
program.parse(process.argv); | ||
const { projectId, token, reports: globs, maxTime, ignoreError, url: baseUrl, noZip, } = program.opts(); | ||
const { projectId, refreshToken, reports: globs, maxTime, ignoreError, url: baseUrl, noZip, } = program.opts(); | ||
function main() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestTimeout = maxTime ? +maxTime * 1000 : undefined; | ||
const responseBodies = yield publish(globs, !noZip, projectId, baseUrl, process.env, tokenAuthenticator(token), requestTimeout); | ||
const accessToken = yield getAccessToken(baseUrl, refreshToken); | ||
const responseBodies = yield publish(globs, !noZip, projectId, baseUrl, process.env, tokenAuthenticator(accessToken), requestTimeout); | ||
return responseBodies.map((body) => body.testCycleId); | ||
@@ -30,0 +31,0 @@ }); |
@@ -0,1 +1,2 @@ | ||
export * from './getAccessToken.js'; | ||
export * from './publish.js'; | ||
@@ -2,0 +3,0 @@ export * from './tokenAuthenticator.js'; |
@@ -0,1 +1,2 @@ | ||
export * from './getAccessToken.js'; | ||
export * from './publish.js'; | ||
@@ -2,0 +3,0 @@ export * from './tokenAuthenticator.js'; |
@@ -18,2 +18,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { promisify } from 'util'; | ||
import { createResponseError } from './createResponseError.js'; | ||
import { manyglob } from './manyglob.js'; | ||
@@ -63,6 +64,6 @@ import { readStream } from './readStream.js'; | ||
} | ||
function publishFile(path, url, ciEnv, authHeaders, requestTimeout) { | ||
function publishFile(requestBodyPath, url, ciEnv, authHeaders, requestTimeout) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
lstat(path) | ||
lstat(requestBodyPath) | ||
.then((stat) => { | ||
@@ -81,28 +82,17 @@ var _a, _b, _c, _d; | ||
} | ||
const headers = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ 'Content-Type': contentTypes[extname(path)], 'Content-Length': stat.size }, (((_a = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _a === void 0 ? void 0 : _a.remote) ? { 'OneReport-SourceControl': ciEnv.git.remote } : {})), (((_b = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _b === void 0 ? void 0 : _b.revision) ? { 'OneReport-Revision': ciEnv.git.revision } : {})), (((_c = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _c === void 0 ? void 0 : _c.branch) ? { 'OneReport-Branch': ciEnv.git.branch } : {})), (((_d = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _d === void 0 ? void 0 : _d.tag) ? { 'OneReport-Tag': ciEnv.git.tag } : {})), authHeaders); | ||
const reqHeaders = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ 'Content-Type': contentTypes[extname(requestBodyPath)], 'Content-Length': stat.size }, (((_a = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _a === void 0 ? void 0 : _a.remote) ? { 'OneReport-SourceControl': ciEnv.git.remote } : {})), (((_b = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _b === void 0 ? void 0 : _b.revision) ? { 'OneReport-Revision': ciEnv.git.revision } : {})), (((_c = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _c === void 0 ? void 0 : _c.branch) ? { 'OneReport-Branch': ciEnv.git.branch } : {})), (((_d = ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.git) === null || _d === void 0 ? void 0 : _d.tag) ? { 'OneReport-Tag': ciEnv.git.tag } : {})), authHeaders); | ||
const req = h.request(url.toString(), { | ||
method: 'POST', | ||
headers, | ||
headers: reqHeaders, | ||
}, (res) => { | ||
readStream(res) | ||
.then((buffer) => buffer.toString('utf-8')) | ||
.then((body) => { | ||
.then((responseBody) => { | ||
if (res.statusCode !== 201) { | ||
return reject(new Error(`Unexpected status code ${res.statusCode} | ||
POST ${url.toString()} -d @${path} | ||
> ${Object.entries(headers) | ||
.map(([h, v]) => `${h}: ${v}`) | ||
.join('\n> ')} | ||
< ${Object.entries(res.headers) | ||
.map(([h, v]) => `${h}: ${v}`) | ||
.join('\n< ')} | ||
${body} | ||
`)); | ||
return reject(createResponseError(res, url, reqHeaders, responseBody, requestBodyPath)); | ||
} | ||
else { | ||
try { | ||
const responseBody = JSON.parse(body); | ||
return resolve(responseBody); | ||
const jsonResponseBody = JSON.parse(responseBody); | ||
return resolve(jsonResponseBody); | ||
} | ||
@@ -121,3 +111,3 @@ catch (err) { | ||
req.on('timeout', () => reject(new Error(`request to ${url.toString()} timed out after ${requestTimeout}ms`))); | ||
const file = fs.createReadStream(path); | ||
const file = fs.createReadStream(requestBodyPath); | ||
pipeline(file, req, (err) => { | ||
@@ -124,0 +114,0 @@ try { |
{ | ||
"name": "@smartbear/one-report-publisher", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Publish Test Results to SmartBear OneReport", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -30,8 +30,8 @@ [![Run Tests](https://github.com/SmartBear/one-report-publisher/actions/workflows/test.yaml/badge.svg)](https://github.com/SmartBear/one-report-publisher/actions/workflows/test.yaml) | ||
if: ${{ always() }} | ||
uses: smartbear/one-report-publisher@v0.6.0 | ||
uses: smartbear/one-report-publisher@v0.7.0 | ||
with: | ||
# Can be omitted if ONE_REPORT_PROJECT_ID is defined | ||
project-id: F5222E06-BA05-4C82-949A-2FE537B6F59F | ||
# Can be omitted if ONE_REPORT_TOKEN is defined | ||
token: ${{ secrets.ONE_REPORT_TOKEN }} | ||
# Can be omitted if ONE_REPORT_REFRESH_TOKEN is defined | ||
refresh-token: ${{ secrets.ONE_REPORT_REFRESH_TOKEN }} | ||
# Can be omitted if ONE_REPORT_URL is defined | ||
@@ -49,3 +49,3 @@ url: ${{ env.ONE_REPORT_URL }} | ||
``` | ||
npx @smartbear/one-report-publisher@v0.6.0 --help | ||
npx @smartbear/one-report-publisher@v0.7.0 --help | ||
@@ -55,10 +55,10 @@ Usage: one-report-publisher [options] | ||
Options: | ||
-u, --url <url> OneReport URL. Defaults to $ONE_REPORT_URL | ||
-p, --project-id <id> OneReport project id. Defaults to $ONE_REPORT_PROJECT_ID | ||
-t, --token <token> OneReport token. Defaults to $ONE_REPORT_TOKEN | ||
-r, --reports <glob...> Glob to the files to publish | ||
-m, --max-time <seconds> Max time for each request | ||
-i, --ignore-error Exit with 0 even if a timeout or error occurred | ||
--no-zip Do not zip non .zip files | ||
-h, --help display help for command | ||
-u, --url <url> OneReport URL. Defaults to $ONE_REPORT_URL | ||
-p, --project-id <id> OneReport project id. Defaults to $ONE_REPORT_PROJECT_ID | ||
-t, --refresh-token <refresh-token> OneReport refresh-token. Defaults to $ONE_REPORT_REFRESH_TOKEN | ||
-r, --reports <glob...> Glob to the files to publish | ||
-m, --max-time <seconds> Max time for each request | ||
-i, --ignore-error Exit with 0 even if a timeout or error occurred | ||
--no-zip Do not zip non .zip files | ||
-h, --help display help for command | ||
``` | ||
@@ -69,5 +69,5 @@ | ||
``` | ||
npx @smartbear/one-report-publisher@0.6.0 \ | ||
npx @smartbear/one-report-publisher@0.7.0 \ | ||
--project-id F5222E06-BA05-4C82-949A-2FE537B6F59F \ | ||
--token ${ONE_REPORT_TOKEN} \ | ||
--refresh-token ${ONE_REPORT_REFRESH_TOKEN} \ | ||
--reports ./reports/**/*.{xml,json,ndjson,zip} | ||
@@ -85,6 +85,6 @@ ``` | ||
command: | | ||
npx @smartbear/one-report-publisher@0.6.0 \ | ||
npx @smartbear/one-report-publisher@0.7.0 \ | ||
--project-id F5222E06-BA05-4C82-949A-2FE537B6F59F \ | ||
--token ${ONE_REPORT_TOKEN} \ | ||
--refresh-token ${ONE_REPORT_REFRESH_TOKEN} \ | ||
--reports ./reports/**/*.{xml,json,ndjson,zip} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
242595
127
2431
12