@theholocron/holocron-plugin-codecov 5.0.0-alpha.563 → 5.0.0-alpha.564

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/dist/index.d.mts CHANGED
@@ -169,6 +169,7 @@ export declare function createPlugin(options?: CodecovPluginOptions): {
169
169
  repo: import("@theholocron/cli").Probe;
170
170
  token: import("@theholocron/cli").Probe;
171
171
  };
172
+ whoami: import("@theholocron/cli").ProviderAction;
172
173
  capabilities: {
173
174
  coverage: () => Coverage;
174
175
  };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthError, AuthError as AuthError$1, ProviderApiError, connectionProbe, coverageExpectations, createFeatureResolver, createResolveToken, tokenExpectations } from "@theholocron/cli";
1
+ import { AuthError, AuthError as AuthError$1, ProviderApiError, connectionProbe, coverageExpectations, createFeatureResolver, createResolveToken, tokenExpectations, whoamiAction } from "@theholocron/cli";
2
2
  import { spawnSync } from "node:child_process";
3
3
  import { chmodSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
@@ -1124,6 +1124,84 @@ function tokenProbe(ctx) {
1124
1124
  }
1125
1125
  };
1126
1126
  }
1127
+ // src/whoami.ts
1128
+ /** The command that proves what the tokens reach. */
1129
+ const PROVE = "holocron probe codecov token --environment ci";
1130
+ /**
1131
+ * Codecov's `whoami` (`holocron provider codecov whoami`). Codecov has two tokens and only one can be asked anything:
1132
+ * the personal API token (`HOLOCRON_CODECOV_API_TOKEN`), which the REST API takes as a bearer token, so it is the one
1133
+ * described, through the repository read the plugin already uses. The repository upload token is not documented as
1134
+ * accepted by the REST API, so when it is the only one held the action says what it is and that Codecov cannot say who
1135
+ * it belongs to or when it expires (a skipped row, never a failure) and points at the `token` probe. With neither
1136
+ * held it is a failing `codecov:whoami:token` row saying how to set one. Codecov's API has no endpoint that describes
1137
+ * the current token or its expiry, so there is no lifetime reader and no token value is ever printed.
1138
+ */
1139
+ function codecovWhoami(options) {
1140
+ const target = resolveTarget(options);
1141
+ const apiInput = {
1142
+ env: options.env,
1143
+ keyring: options.keyring
1144
+ };
1145
+ const verify = async (token) => {
1146
+ if (!target) return {
1147
+ ok: false,
1148
+ message: "no repository to ask about: set the plugin options owner and repo"
1149
+ };
1150
+ const where = describeTarget(target);
1151
+ try {
1152
+ return {
1153
+ ok: true,
1154
+ subject: (await createCodecovClient({
1155
+ token,
1156
+ baseUrl: options.baseUrl,
1157
+ fetch: options.fetch
1158
+ }).repos.get(target.service, target.owner, target.repo)).private ? `Codecov API token: can read the private repository ${where}` : `Codecov API token: can read ${where}, which is public and answers without a token, so this does not prove the token`
1159
+ };
1160
+ } catch (err) {
1161
+ return {
1162
+ ok: false,
1163
+ message: `Codecov did not accept the API token for ${where}: ${String(err)}`
1164
+ };
1165
+ }
1166
+ };
1167
+ const api = whoamiAction({
1168
+ provider: "codecov",
1169
+ token: () => resolveApiToken(apiInput),
1170
+ verify,
1171
+ tokens: tokens.filter((t) => t.envName === resolveApiToken.token.envName),
1172
+ proveWith: PROVE
1173
+ });
1174
+ return async (ctx) => {
1175
+ try {
1176
+ resolveApiToken(apiInput);
1177
+ } catch (err) {
1178
+ if (!(err instanceof AuthError)) throw err;
1179
+ return uploadOnly(options);
1180
+ }
1181
+ return api(ctx);
1182
+ };
1183
+ }
1184
+ /** The rows when no API token is held: what the upload token is, or how to set a token at all. */
1185
+ function uploadOnly(options) {
1186
+ try {
1187
+ resolveToken(options);
1188
+ } catch (err) {
1189
+ return Promise.resolve([{
1190
+ id: "codecov:whoami:token",
1191
+ title: "codecov token",
1192
+ status: "fail",
1193
+ detail: `no Codecov token is set. Set HOLOCRON_CODECOV_API_TOKEN (a personal API token) to see who it is, or the upload token: ${err.message}`,
1194
+ problems: []
1195
+ }]);
1196
+ }
1197
+ return Promise.resolve([{
1198
+ id: "codecov:whoami:token",
1199
+ title: "codecov token",
1200
+ status: "skip",
1201
+ detail: `only the repository upload token (${resolveToken.token.envName}) is held. Codecov cannot say who an upload token belongs to or when it expires, and its REST API is not documented to accept it. Set HOLOCRON_CODECOV_API_TOKEN to describe an API token, or run \`${PROVE}\``,
1202
+ problems: []
1203
+ }]);
1204
+ }
1127
1205
  // src/index.ts
1128
1206
  /** Creates the shared context for the given options; no token is resolved until `client()` or `apiClient()` is first called. */
1129
1207
  function createContext(options = {}) {
@@ -1186,6 +1264,7 @@ function createPlugin(options = {}) {
1186
1264
  repo: target ? describeTarget(target) : void 0
1187
1265
  })
1188
1266
  },
1267
+ whoami: codecovWhoami(options),
1189
1268
  capabilities: { coverage: () => coverage(ctx) }
1190
1269
  };
1191
1270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-codecov",
3
- "version": "5.0.0-alpha.563",
3
+ "version": "5.0.0-alpha.564",
4
4
  "description": "Holocron plugin for Codecov. Implements the coverage capability against Codecov's REST API: checks that the service accepts a token for the repository.",
5
5
  "keywords": [
6
6
  "codecov",
@@ -42,17 +42,17 @@
42
42
  "tsdown": "^0.23.7",
43
43
  "typescript": "^6.0.3",
44
44
  "vitest": "^5.1.1",
45
- "@theholocron/cli": "5.0.0-alpha.563",
46
- "@theholocron/codecov-client": "^1.58.0-alpha.62",
45
+ "@theholocron/cli": "5.0.0-alpha.564",
46
+ "@theholocron/codecov-client": "^1.58.0-alpha.63",
47
47
  "@theholocron/eslint-config": "^8.9.0-alpha.24",
48
- "@theholocron/http-client": "^1.58.0-alpha.62",
48
+ "@theholocron/http-client": "^1.58.0-alpha.63",
49
49
  "@theholocron/tsconfig": "^8.9.0-alpha.24",
50
50
  "@theholocron/tsdown-config": "^8.9.0-alpha.24",
51
51
  "@theholocron/vitest-config": "^8.9.0-alpha.24"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@theholocron/codecov-client": "^1.58.0",
55
- "@theholocron/cli": "5.0.0-alpha.563"
55
+ "@theholocron/cli": "5.0.0-alpha.564"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=22"