@codacy/verity-cli 0.26.0-experimental.fb8a404 → 0.27.0-experimental.1106a16
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 +90 -3
- package/package.json +1 -1
package/bin/verity.js
CHANGED
|
@@ -10477,6 +10477,11 @@ var DEFAULT_SERVICE_URL = "https://yyfaqvcgslcrzvrbvqik.supabase.co/functions/v1
|
|
|
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,34 @@ 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, installUrl) {
|
|
11125
|
+
const notInstalledError = {
|
|
11126
|
+
ok: false,
|
|
11127
|
+
error: `The Verity GitHub App can't see ${owner}/${repo}. Install it on "${owner}" and grant access to this repository, then re-run:
|
|
11128
|
+
${installUrl}`
|
|
11129
|
+
};
|
|
11130
|
+
const maxAttempts = 3;
|
|
11131
|
+
for (let attempt = 1; ; attempt++) {
|
|
11132
|
+
const visible = await githubCanSeeRepo(owner, repo, token);
|
|
11133
|
+
if (!visible.ok) return { ok: true, data: void 0 };
|
|
11134
|
+
if (visible.data) return { ok: true, data: void 0 };
|
|
11135
|
+
if (!isInteractive() || attempt >= maxAttempts) return notInstalledError;
|
|
11136
|
+
printWarn(`The Verity GitHub App can't see ${owner}/${repo} yet.`);
|
|
11137
|
+
printInfo(`Install it on "${owner}" (grant access to this repo):`);
|
|
11138
|
+
printInfo(` ${installUrl}`);
|
|
11139
|
+
await waitForEnter("Press Enter once installed to retry\u2026 ");
|
|
11140
|
+
}
|
|
11141
|
+
}
|
|
11071
11142
|
async function registerProject(opts) {
|
|
11072
11143
|
const parsed = parseRemote(opts.remote);
|
|
11073
11144
|
if (!parsed) {
|
|
@@ -11076,11 +11147,27 @@ async function registerProject(opts) {
|
|
|
11076
11147
|
if (parsed.provider !== "github") {
|
|
11077
11148
|
return { ok: false, error: `Provider '${parsed.provider}' is not supported yet \u2014 GitHub only for now.` };
|
|
11078
11149
|
}
|
|
11150
|
+
const usingTokenOverride = Boolean(process.env.VERITY_PROVIDER_TOKEN);
|
|
11151
|
+
const ownerId = usingTokenOverride ? null : await githubAccountId(parsed.owner);
|
|
11152
|
+
const installUrl = githubAppInstallUrl(ownerId);
|
|
11153
|
+
if (!usingTokenOverride && isInteractive()) {
|
|
11154
|
+
printInfo("");
|
|
11155
|
+
printInfo(`Verity uses a read-only GitHub App to verify write access to ${parsed.owner}/${parsed.repo}.`);
|
|
11156
|
+
printInfo(`Install it on "${parsed.owner}" (grant access to this repo) if you haven't already:`);
|
|
11157
|
+
printInfo(` ${installUrl}`);
|
|
11158
|
+
await waitForEnter("Press Enter to continue to GitHub authorization\u2026 ");
|
|
11159
|
+
}
|
|
11079
11160
|
const providerAuth = await githubDeviceFlow();
|
|
11080
11161
|
if (!providerAuth.ok) {
|
|
11081
11162
|
return { ok: false, error: providerAuth.error };
|
|
11082
11163
|
}
|
|
11083
11164
|
const providerToken = providerAuth.data;
|
|
11165
|
+
if (!usingTokenOverride) {
|
|
11166
|
+
const installed = await ensureAppInstalled(parsed.owner, parsed.repo, providerToken, installUrl);
|
|
11167
|
+
if (!installed.ok) {
|
|
11168
|
+
return { ok: false, error: installed.error };
|
|
11169
|
+
}
|
|
11170
|
+
}
|
|
11084
11171
|
const result = await apiRequest({
|
|
11085
11172
|
method: "POST",
|
|
11086
11173
|
path: "/auth/register",
|
|
@@ -15847,7 +15934,7 @@ var import_node_fs24 = require("node:fs");
|
|
|
15847
15934
|
var import_promises13 = require("node:fs/promises");
|
|
15848
15935
|
var import_node_path18 = require("node:path");
|
|
15849
15936
|
var import_node_child_process9 = require("node:child_process");
|
|
15850
|
-
var
|
|
15937
|
+
var readline2 = __toESM(require("node:readline/promises"));
|
|
15851
15938
|
|
|
15852
15939
|
// src/commands/migrate.ts
|
|
15853
15940
|
var import_node_fs23 = require("node:fs");
|
|
@@ -16129,7 +16216,7 @@ function registerMigrateCommand(program2) {
|
|
|
16129
16216
|
// src/commands/init.ts
|
|
16130
16217
|
async function promptYes(question) {
|
|
16131
16218
|
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
|
|
16132
|
-
const rl =
|
|
16219
|
+
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
16133
16220
|
try {
|
|
16134
16221
|
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
16135
16222
|
return answer === "" || answer === "y" || answer === "yes";
|
|
@@ -17080,7 +17167,7 @@ function registerTelemetryCommands(program2) {
|
|
|
17080
17167
|
}
|
|
17081
17168
|
|
|
17082
17169
|
// src/cli.ts
|
|
17083
|
-
program.name("verity").description("CLI for Verity quality gate service").version("0.
|
|
17170
|
+
program.name("verity").description("CLI for Verity quality gate service").version("0.27.0-experimental.1106a16").option("--token <token>", "Override authentication token").option("--service-url <url>", "Override service URL").option("--verbose", "Log HTTP requests/responses to stderr");
|
|
17084
17171
|
registerAuthCommands(program);
|
|
17085
17172
|
registerHooksCommands(program);
|
|
17086
17173
|
registerIntentCommands(program);
|