@theholocron/codecov-client 1.58.0-alpha.35 → 1.58.0-alpha.36

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/README.md CHANGED
@@ -17,6 +17,8 @@ const codecov = createCodecovClient({ token: process.env.CODECOV_API_TOKEN! });
17
17
 
18
18
  const repo = await codecov.repos.get("github", "theholocron", "holocron");
19
19
  const owner = await codecov.owners.get("github", "theholocron");
20
+ const flags = await codecov.flags.list("github", "theholocron", "holocron"); // every page of GET .../flags/
21
+ const components = await codecov.components.list("github", "theholocron", "holocron"); // GET .../components/
20
22
  ```
21
23
 
22
24
  The token is a Codecov API (personal access) token, sent as `Authorization: Bearer`. A repository _upload_ token is a
package/dist/index.d.mts CHANGED
@@ -37,6 +37,22 @@ interface CodecovRepo {
37
37
  name?: string;
38
38
  };
39
39
  }
40
+ /** A component as Codecov reports it for a repository. Only the fields Holocron reads are typed. */
41
+ interface CodecovComponent {
42
+ /** The component's id, the `component_id` of `codecov.yml`. */
43
+ component_id: string;
44
+ /** The component's name. */
45
+ name: string;
46
+ /** The component's coverage percentage, when it has one. */
47
+ coverage?: number | null;
48
+ }
49
+ /** A flag as Codecov reports it for a repository. Only the fields Holocron reads are typed. */
50
+ interface CodecovFlag {
51
+ /** The flag's name, as an upload names it. */
52
+ flag_name: string;
53
+ /** The flag's coverage percentage, when it has one. */
54
+ coverage?: number | null;
55
+ }
40
56
  /** An owner (a user or organization) as Codecov reports it. Only the fields Holocron reads are typed. */
41
57
  interface CodecovOwner {
42
58
  /** The owner's login on the service. */
@@ -46,8 +62,14 @@ interface CodecovOwner {
46
62
  /** The owner's display name. */
47
63
  name?: string;
48
64
  }
49
- /** Creates a Codecov API client with `owners` and `repos` groups, both sharing one REST client. */
65
+ /** Creates a Codecov API client with `components`, `flags`, `owners` and `repos` groups, all sharing one REST client. */
50
66
  export declare function createCodecovClient(opts: CodecovClientOptions): {
67
+ components: {
68
+ list: (service: CodecovService, owner: string, repo: string) => Promise<CodecovComponent[]>;
69
+ };
70
+ flags: {
71
+ list: (service: CodecovService, owner: string, repo: string) => Promise<CodecovFlag[]>;
72
+ };
51
73
  owners: {
52
74
  get: (service: CodecovService, owner: string) => Promise<CodecovOwner>;
53
75
  };
@@ -57,4 +79,4 @@ export declare function createCodecovClient(opts: CodecovClientOptions): {
57
79
  };
58
80
  /** The client `createCodecovClient` returns. */
59
81
  export type CodecovClient = ReturnType<typeof createCodecovClient>;
60
- export type { CodecovClientOptions, CodecovOwner, CodecovRepo, CodecovService };
82
+ export type { CodecovClientOptions, CodecovComponent, CodecovFlag, CodecovOwner, CodecovRepo, CodecovService };
package/dist/index.mjs CHANGED
@@ -1,4 +1,39 @@
1
1
  import { createRestClient } from "@theholocron/http-client";
2
+ // src/components/components.ts
3
+ /** The `components` group of the Codecov client. */
4
+ function components(rest) {
5
+ return {
6
+ /**
7
+ * List the components of a repository (of the default branch's head commit): `GET
8
+ * /{service}/{owner}/repos/{repo}/components/`. Codecov documents a plain array here; a paginated `{ results }`
9
+ * body is read the same way.
10
+ */
11
+ list: async (service, owner, repo) => {
12
+ const body = await rest.request(`/${service}/${encodeURIComponent(owner)}/repos/${encodeURIComponent(repo)}/components/`);
13
+ return Array.isArray(body) ? body : body.results ?? [];
14
+ } };
15
+ }
16
+ // src/flags/flags.ts
17
+ /** The most pages `flags.list` reads, so a service that never ends its list cannot loop it forever. */
18
+ const MAX_PAGES = 50;
19
+ /** The `flags` group of the Codecov client. */
20
+ function flags(rest) {
21
+ return {
22
+ /**
23
+ * List every flag of a repository: `GET /{service}/{owner}/repos/{repo}/flags/?page=<n>&page_size=100`, following
24
+ * the pages until `next` is null.
25
+ */
26
+ list: async (service, owner, repo) => {
27
+ const base = `/${service}/${encodeURIComponent(owner)}/repos/${encodeURIComponent(repo)}/flags/`;
28
+ const found = [];
29
+ for (let page = 1; page <= MAX_PAGES; page++) {
30
+ const body = await rest.request(`${base}?page=${page}&page_size=100`);
31
+ found.push(...body.results ?? []);
32
+ if (!body.next) break;
33
+ }
34
+ return found;
35
+ } };
36
+ }
2
37
  // src/owners/owners.ts
3
38
  /** The `owners` group of the Codecov client. */
4
39
  function owners(rest) {
@@ -26,10 +61,12 @@ function createCodecovRestClient(opts) {
26
61
  });
27
62
  }
28
63
  // src/index.ts
29
- /** Creates a Codecov API client with `owners` and `repos` groups, both sharing one REST client. */
64
+ /** Creates a Codecov API client with `components`, `flags`, `owners` and `repos` groups, all sharing one REST client. */
30
65
  function createCodecovClient(opts) {
31
66
  const rest = createCodecovRestClient(opts);
32
67
  return {
68
+ components: components(rest),
69
+ flags: flags(rest),
33
70
  owners: owners(rest),
34
71
  repos: repos(rest)
35
72
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/codecov-client",
3
- "version": "1.58.0-alpha.35",
3
+ "version": "1.58.0-alpha.36",
4
4
  "description": "A TypeScript client for the Codecov REST API",
5
5
  "keywords": [
6
6
  "codecov",
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@theholocron/http-client": "^1.58.0-alpha.35",
35
+ "@theholocron/http-client": "^1.58.0-alpha.36",
36
36
  "@theholocron/observability": "^0.7.0-alpha.4"
37
37
  },
38
38
  "devDependencies": {
@@ -42,13 +42,13 @@
42
42
  "eslint": "^10.14.0",
43
43
  "eslint-plugin-n": "^18.5.0",
44
44
  "globals": "^17.14.0",
45
- "tsdown": "^0.23.5",
45
+ "tsdown": "^0.23.7",
46
46
  "typescript": "^5.9.3",
47
47
  "vitest": "^5.1.0",
48
- "@theholocron/tsconfig": "^8.9.0-alpha.17",
49
- "@theholocron/tsdown-config": "^8.9.0-alpha.17",
50
- "@theholocron/vitest-config": "^8.9.0-alpha.17",
51
- "@theholocron/eslint-config": "^8.9.0-alpha.17"
48
+ "@theholocron/eslint-config": "^8.9.0-alpha.18",
49
+ "@theholocron/tsconfig": "^8.9.0-alpha.18",
50
+ "@theholocron/vitest-config": "^8.9.0-alpha.18",
51
+ "@theholocron/tsdown-config": "^8.9.0-alpha.18"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22.0.0"