debugbear
Advanced tools
Comparing version 2.0.1 to 2.0.2
import { analyzePage } from "./analyzePage"; | ||
import { callApi } from "./callApi"; | ||
import { inferBuildInfo } from "./inferBuildInfo"; | ||
import { getNgrokTunnelPublicUrl } from "./getNgrokTunnelPublicUrl"; | ||
@@ -82,3 +84,25 @@ export class ApiClient { | ||
async analyze(pageId: number, options = {}) { | ||
async analyze(pageId: number, options: any = {}) { | ||
if (options.inferBuildInfo) { | ||
let inferredBuildInfo = await inferBuildInfo({ | ||
baseBranch: options.baseBranch | ||
}); | ||
options.repoOwner = options.repoOwner || inferredBuildInfo.repoOwner; | ||
options.repoName = options.repoName || inferredBuildInfo.repoName; | ||
options.commitHash = options.commitHash || inferredBuildInfo.commitHash; | ||
options.commitBranch = | ||
options.commitBranch || inferredBuildInfo.commitBranch; | ||
options.buildTitle = options.buildTitle || inferredBuildInfo.buildTitle; | ||
} | ||
if (options.ngrokWebPort) { | ||
if (options.url) { | ||
console.log("Can't take URL parameter if getting baseUrl from ngrok"); | ||
process.exit(1); | ||
} | ||
options.baseUrl = await getNgrokTunnelPublicUrl(options.ngrokWebPort); | ||
} | ||
const { analysis, resultUrl } = await callApi({ | ||
@@ -85,0 +109,0 @@ method: "POST", |
@@ -39,2 +39,4 @@ "use strict"; | ||
var callApi_1 = require("./callApi"); | ||
var inferBuildInfo_1 = require("./inferBuildInfo"); | ||
var getNgrokTunnelPublicUrl_1 = require("./getNgrokTunnelPublicUrl"); | ||
var ApiClient = /** @class */ (function () { | ||
@@ -153,6 +155,31 @@ function ApiClient(apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, analysis, resultUrl; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, callApi_1.callApi({ | ||
var inferredBuildInfo, _a, _b, analysis, resultUrl; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!options.inferBuildInfo) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, inferBuildInfo_1.inferBuildInfo({ | ||
baseBranch: options.baseBranch | ||
})]; | ||
case 1: | ||
inferredBuildInfo = _c.sent(); | ||
options.repoOwner = options.repoOwner || inferredBuildInfo.repoOwner; | ||
options.repoName = options.repoName || inferredBuildInfo.repoName; | ||
options.commitHash = options.commitHash || inferredBuildInfo.commitHash; | ||
options.commitBranch = | ||
options.commitBranch || inferredBuildInfo.commitBranch; | ||
options.buildTitle = options.buildTitle || inferredBuildInfo.buildTitle; | ||
_c.label = 2; | ||
case 2: | ||
if (!options.ngrokWebPort) return [3 /*break*/, 4]; | ||
if (options.url) { | ||
console.log("Can't take URL parameter if getting baseUrl from ngrok"); | ||
process.exit(1); | ||
} | ||
_a = options; | ||
return [4 /*yield*/, getNgrokTunnelPublicUrl_1.getNgrokTunnelPublicUrl(options.ngrokWebPort)]; | ||
case 3: | ||
_a.baseUrl = _c.sent(); | ||
_c.label = 4; | ||
case 4: return [4 /*yield*/, callApi_1.callApi({ | ||
method: "POST", | ||
@@ -163,4 +190,4 @@ path: "/page/" + pageId + "/analyze", | ||
})]; | ||
case 1: | ||
_a = _b.sent(), analysis = _a.analysis, resultUrl = _a.resultUrl; | ||
case 5: | ||
_b = _c.sent(), analysis = _b.analysis, resultUrl = _b.resultUrl; | ||
return [2 /*return*/, { | ||
@@ -167,0 +194,0 @@ url: resultUrl, |
@@ -38,12 +38,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var envCi = require("env-ci"); | ||
var commander = require("commander"); | ||
var lodash_1 = require("lodash"); | ||
var analyzePage_1 = require("./analyzePage"); | ||
var getNgrokTunnelPublicUrl_1 = require("./getNgrokTunnelPublicUrl"); | ||
var child_process_1 = require("child_process"); | ||
var version = require("../package.json").version; | ||
function __runCli() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var urlValue, program, inferBuildInfo, ciEnv, slugParts, ciEnvCommitBranch, output, commitHashRegex, commitMessage, baseUrl, repo, commit, loginStep, err_1; | ||
var urlValue, program, baseUrl, repo, commit, loginStep, err_1; | ||
return __generator(this, function (_a) { | ||
@@ -77,38 +74,2 @@ switch (_a.label) { | ||
} | ||
inferBuildInfo = program.inferBuildInfo; | ||
if (inferBuildInfo) { | ||
ciEnv = envCi(); | ||
if (ciEnv.slug) { | ||
slugParts = ciEnv.slug.split("/"); | ||
if (slugParts.length === 2) { | ||
if (!program.repoOwner) { | ||
program.repoOwner = slugParts[0]; | ||
} | ||
if (!program.repoName) { | ||
program.repoName = slugParts[1]; | ||
} | ||
} | ||
} | ||
ciEnvCommitBranch = ciEnv.isPr ? ciEnv.prBranch : ciEnv.branch; | ||
if (!program.commitHash && ciEnv.commit) { | ||
program.commitHash = ciEnv.commit; | ||
} | ||
if (!program.commitBranch && ciEnvCommitBranch) { | ||
program.commitBranch = ciEnvCommitBranch; | ||
} | ||
if (!program.baseBranch && ciEnv.isPr && ciEnv.branch) { | ||
program.baseBranch = ciEnv.branch; | ||
} | ||
if (!program.buildTitle && ciEnv.isCi && program.commitHash) { | ||
try { | ||
output = child_process_1.execSync("git log --format=oneline -n 1 " + program.commitHash).toString(); | ||
commitHashRegex = /[0-9a-z]{20}[0-9a-z]+/; | ||
if (commitHashRegex.test(output)) { | ||
commitMessage = output.replace(commitHashRegex, "").trim(); | ||
program.buildTitle = commitMessage; | ||
} | ||
} | ||
catch (err) { } | ||
} | ||
} | ||
baseUrl = undefined; | ||
@@ -131,13 +92,5 @@ repo = "not specified"; | ||
} | ||
if (!program.ngrokWebPort) return [3 /*break*/, 2]; | ||
if (urlValue) { | ||
console.log("Can't take URL if getting baseUrl from ngrok"); | ||
process.exit(1); | ||
} | ||
return [4 /*yield*/, getNgrokTunnelPublicUrl_1.getNgrokTunnelPublicUrl(program.ngrokWebPort)]; | ||
_a.label = 1; | ||
case 1: | ||
baseUrl = _a.sent(); | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 5]); | ||
_a.trys.push([1, 3, , 4]); | ||
loginStep = { | ||
@@ -167,8 +120,10 @@ username: null, | ||
"path", | ||
"buildTitle" | ||
"buildTitle", | ||
"inferBuildInfo", | ||
"ngrokWebPort" | ||
]), { loginStep: loginStep }))]; | ||
case 2: | ||
_a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
err_1 = _a.sent(); | ||
@@ -178,4 +133,4 @@ console.log("\nCLI command failed"); | ||
process.exit(1); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -182,0 +137,0 @@ }); |
{ | ||
"name": "debugbear", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "API/CLI for DebugBearAnalyze pages with DebugBear. Analyze pages on demand on demand or as part of your Continuous Integration process.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,8 +0,4 @@ | ||
import * as envCi from "env-ci"; | ||
import * as commander from "commander"; | ||
import { pick } from "lodash"; | ||
import { analyzePage } from "./analyzePage"; | ||
import { getNgrokTunnelPublicUrl } from "./getNgrokTunnelPublicUrl"; | ||
import { execSync } from "child_process"; | ||
import { callApi } from "./callApi"; | ||
@@ -43,42 +39,2 @@ const version = require("../package.json").version; | ||
const inferBuildInfo = program.inferBuildInfo; | ||
if (inferBuildInfo) { | ||
const ciEnv = envCi(); | ||
if (ciEnv.slug) { | ||
const slugParts = ciEnv.slug.split("/"); | ||
if (slugParts.length === 2) { | ||
if (!program.repoOwner) { | ||
program.repoOwner = slugParts[0]; | ||
} | ||
if (!program.repoName) { | ||
program.repoName = slugParts[1]; | ||
} | ||
} | ||
} | ||
let ciEnvCommitBranch = ciEnv.isPr ? ciEnv.prBranch : ciEnv.branch; | ||
if (!program.commitHash && ciEnv.commit) { | ||
program.commitHash = ciEnv.commit; | ||
} | ||
if (!program.commitBranch && ciEnvCommitBranch) { | ||
program.commitBranch = ciEnvCommitBranch; | ||
} | ||
if (!program.baseBranch && ciEnv.isPr && ciEnv.branch) { | ||
program.baseBranch = ciEnv.branch; | ||
} | ||
if (!program.buildTitle && ciEnv.isCi && program.commitHash) { | ||
try { | ||
const output = execSync( | ||
`git log --format=oneline -n 1 ${program.commitHash}` | ||
).toString(); | ||
const commitHashRegex = /[0-9a-z]{20}[0-9a-z]+/; | ||
if (commitHashRegex.test(output)) { | ||
const commitMessage = output.replace(commitHashRegex, "").trim(); | ||
program.buildTitle = commitMessage; | ||
} | ||
} catch (err) {} | ||
} | ||
} | ||
let baseUrl = undefined; | ||
@@ -103,11 +59,2 @@ | ||
if (program.ngrokWebPort) { | ||
if (urlValue) { | ||
console.log("Can't take URL if getting baseUrl from ngrok"); | ||
process.exit(1); | ||
} | ||
baseUrl = await getNgrokTunnelPublicUrl(program.ngrokWebPort); | ||
} | ||
try { | ||
@@ -142,3 +89,5 @@ let loginStep = { | ||
"path", | ||
"buildTitle" | ||
"buildTitle", | ||
"inferBuildInfo", | ||
"ngrokWebPort" | ||
]), | ||
@@ -145,0 +94,0 @@ { loginStep } |
42939
21
1022