@codacy/verity-cli 0.27.0 → 0.27.1
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/bin/verity.js +84 -3
- package/package.json +1 -1
package/bin/verity.js
CHANGED
|
@@ -10477,6 +10477,11 @@ var DEFAULT_SERVICE_URL = "".length > 0 ? "" : PROD_SERVICE_URL;
|
|
|
10477
10477
|
var GITHUB_CLIENT_ID = "Iv23li88HxAi3ZrbYzWh";
|
|
10478
10478
|
var GITHUB_DEVICE_CODE_URL = "https://github.com/login/device/code";
|
|
10479
10479
|
var GITHUB_ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token";
|
|
10480
|
+
var GITHUB_APP_SLUG = "verity-auth";
|
|
10481
|
+
var GITHUB_APP_INSTALL_URL = `https://github.com/apps/${GITHUB_APP_SLUG}/installations/new`;
|
|
10482
|
+
function githubAppInstallUrl(accountId) {
|
|
10483
|
+
return accountId != null ? `https://github.com/apps/${GITHUB_APP_SLUG}/installations/new/permissions?target_id=${accountId}` : GITHUB_APP_INSTALL_URL;
|
|
10484
|
+
}
|
|
10480
10485
|
|
|
10481
10486
|
// src/lib/auth.ts
|
|
10482
10487
|
async function resolveToken(flagToken) {
|
|
@@ -10748,10 +10753,48 @@ function analyzeRequest(options) {
|
|
|
10748
10753
|
// src/lib/register.ts
|
|
10749
10754
|
var import_promises3 = require("node:fs/promises");
|
|
10750
10755
|
var import_node_path3 = require("node:path");
|
|
10756
|
+
var readline = __toESM(require("node:readline/promises"));
|
|
10751
10757
|
|
|
10752
10758
|
// src/lib/provider-auth.ts
|
|
10753
10759
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10754
10760
|
var form = (fields) => new URLSearchParams(fields).toString();
|
|
10761
|
+
async function githubAccountId(owner) {
|
|
10762
|
+
try {
|
|
10763
|
+
const res = await fetch(`https://api.github.com/users/${encodeURIComponent(owner)}`, {
|
|
10764
|
+
headers: {
|
|
10765
|
+
Accept: "application/vnd.github+json",
|
|
10766
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
10767
|
+
"User-Agent": "verity-cli"
|
|
10768
|
+
}
|
|
10769
|
+
});
|
|
10770
|
+
if (!res.ok) return null;
|
|
10771
|
+
const body = await res.json();
|
|
10772
|
+
return typeof body.id === "number" ? body.id : null;
|
|
10773
|
+
} catch {
|
|
10774
|
+
return null;
|
|
10775
|
+
}
|
|
10776
|
+
}
|
|
10777
|
+
async function githubCanSeeRepo(owner, repo, token) {
|
|
10778
|
+
let res;
|
|
10779
|
+
try {
|
|
10780
|
+
res = await fetch(
|
|
10781
|
+
`https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`,
|
|
10782
|
+
{
|
|
10783
|
+
headers: {
|
|
10784
|
+
Authorization: `Bearer ${token}`,
|
|
10785
|
+
Accept: "application/vnd.github+json",
|
|
10786
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
10787
|
+
"User-Agent": "verity-cli"
|
|
10788
|
+
}
|
|
10789
|
+
}
|
|
10790
|
+
);
|
|
10791
|
+
} catch (err) {
|
|
10792
|
+
return { ok: false, error: `Network error contacting GitHub: ${err.message}` };
|
|
10793
|
+
}
|
|
10794
|
+
if (res.status === 404) return { ok: true, data: false };
|
|
10795
|
+
if (res.ok) return { ok: true, data: true };
|
|
10796
|
+
return { ok: false, error: `GitHub repo lookup failed (HTTP ${res.status})` };
|
|
10797
|
+
}
|
|
10755
10798
|
async function githubDeviceFlow() {
|
|
10756
10799
|
const override = process.env.VERITY_PROVIDER_TOKEN;
|
|
10757
10800
|
if (override) return { ok: true, data: override };
|
|
@@ -11068,6 +11111,37 @@ function listTrackedFiles() {
|
|
|
11068
11111
|
}
|
|
11069
11112
|
|
|
11070
11113
|
// src/lib/register.ts
|
|
11114
|
+
var isInteractive = () => Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
11115
|
+
async function waitForEnter(prompt) {
|
|
11116
|
+
if (!isInteractive()) return;
|
|
11117
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
11118
|
+
try {
|
|
11119
|
+
await rl.question(prompt);
|
|
11120
|
+
} finally {
|
|
11121
|
+
rl.close();
|
|
11122
|
+
}
|
|
11123
|
+
}
|
|
11124
|
+
async function ensureAppInstalled(owner, repo, token) {
|
|
11125
|
+
let installUrl = null;
|
|
11126
|
+
const maxAttempts = 3;
|
|
11127
|
+
for (let attempt = 1; ; attempt++) {
|
|
11128
|
+
const visible = await githubCanSeeRepo(owner, repo, token);
|
|
11129
|
+
if (!visible.ok) return { ok: true, data: void 0 };
|
|
11130
|
+
if (visible.data) return { ok: true, data: void 0 };
|
|
11131
|
+
if (installUrl === null) installUrl = githubAppInstallUrl(await githubAccountId(owner));
|
|
11132
|
+
if (!isInteractive() || attempt >= maxAttempts) {
|
|
11133
|
+
return {
|
|
11134
|
+
ok: false,
|
|
11135
|
+
error: `The Verity GitHub App can't see ${owner}/${repo}. Install it on "${owner}" and grant access to this repository, then re-run:
|
|
11136
|
+
${installUrl}`
|
|
11137
|
+
};
|
|
11138
|
+
}
|
|
11139
|
+
printWarn(`The Verity GitHub App can't see ${owner}/${repo} yet.`);
|
|
11140
|
+
printInfo(`Install it on "${owner}" (grant access to this repo):`);
|
|
11141
|
+
printInfo(` ${installUrl}`);
|
|
11142
|
+
await waitForEnter("Press Enter once installed to retry\u2026 ");
|
|
11143
|
+
}
|
|
11144
|
+
}
|
|
11071
11145
|
async function registerProject(opts) {
|
|
11072
11146
|
const parsed = parseRemote(opts.remote);
|
|
11073
11147
|
if (!parsed) {
|
|
@@ -11076,11 +11150,18 @@ async function registerProject(opts) {
|
|
|
11076
11150
|
if (parsed.provider !== "github") {
|
|
11077
11151
|
return { ok: false, error: `Provider '${parsed.provider}' is not supported yet \u2014 GitHub only for now.` };
|
|
11078
11152
|
}
|
|
11153
|
+
const usingTokenOverride = Boolean(process.env.VERITY_PROVIDER_TOKEN);
|
|
11079
11154
|
const providerAuth = await githubDeviceFlow();
|
|
11080
11155
|
if (!providerAuth.ok) {
|
|
11081
11156
|
return { ok: false, error: providerAuth.error };
|
|
11082
11157
|
}
|
|
11083
11158
|
const providerToken = providerAuth.data;
|
|
11159
|
+
if (!usingTokenOverride) {
|
|
11160
|
+
const installed = await ensureAppInstalled(parsed.owner, parsed.repo, providerToken);
|
|
11161
|
+
if (!installed.ok) {
|
|
11162
|
+
return { ok: false, error: installed.error };
|
|
11163
|
+
}
|
|
11164
|
+
}
|
|
11084
11165
|
const result = await apiRequest({
|
|
11085
11166
|
method: "POST",
|
|
11086
11167
|
path: "/auth/register",
|
|
@@ -15847,7 +15928,7 @@ var import_node_fs24 = require("node:fs");
|
|
|
15847
15928
|
var import_promises13 = require("node:fs/promises");
|
|
15848
15929
|
var import_node_path18 = require("node:path");
|
|
15849
15930
|
var import_node_child_process9 = require("node:child_process");
|
|
15850
|
-
var
|
|
15931
|
+
var readline2 = __toESM(require("node:readline/promises"));
|
|
15851
15932
|
|
|
15852
15933
|
// src/commands/migrate.ts
|
|
15853
15934
|
var import_node_fs23 = require("node:fs");
|
|
@@ -16129,7 +16210,7 @@ function registerMigrateCommand(program2) {
|
|
|
16129
16210
|
// src/commands/init.ts
|
|
16130
16211
|
async function promptYes(question) {
|
|
16131
16212
|
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
|
|
16132
|
-
const rl =
|
|
16213
|
+
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
16133
16214
|
try {
|
|
16134
16215
|
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
16135
16216
|
return answer === "" || answer === "y" || answer === "yes";
|
|
@@ -17080,7 +17161,7 @@ function registerTelemetryCommands(program2) {
|
|
|
17080
17161
|
}
|
|
17081
17162
|
|
|
17082
17163
|
// src/cli.ts
|
|
17083
|
-
program.name("verity").description("CLI for Verity quality gate service").version("0.27.
|
|
17164
|
+
program.name("verity").description("CLI for Verity quality gate service").version("0.27.1").option("--token <token>", "Override authentication token").option("--service-url <url>", "Override service URL").option("--verbose", "Log HTTP requests/responses to stderr");
|
|
17084
17165
|
registerAuthCommands(program);
|
|
17085
17166
|
registerHooksCommands(program);
|
|
17086
17167
|
registerIntentCommands(program);
|